作者:senthil-r-wiredelt
项目:meilleure-visit
/**
* @expectedException \OutOfBoundsException
*/
public function testGetArgumentShouldCheckBounds()
{
$def = new DefinitionDecorator('foo');
$def->setArguments(array(0 => 'foo'));
$def->replaceArgument(0, 'foo');
$def->getArgument(1);
}
作者:upenn-da
项目:dag-framewor
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if ($container->hasDefinition('doctrine')) {
$definition = new DefinitionDecorator('dag.form.type.object_to_identifier');
$definition->addArgument(new Reference('doctrine'));
$definition->addArgument('dag_entity_to_identifier');
$definition->addTag('form.type', array('alias' => 'dag_entity_to_identifier'));
$container->setDefinition('dag_entity_to_identifier', $definition);
}
if ($container->hasDefinition('doctrine_mongodb')) {
$definition = new DefinitionDecorator('dag.form.type.object_to_identifier');
$definition->addArgument(new Reference('doctrine_mongodb'));
$definition->addArgument('dag_document_to_identifier');
$definition->addTag('form.type', array('alias' => 'dag_document_to_identifier'));
$container->setDefinition('dag_document_to_identifier', $definition);
if (!$container->hasDefinition('dag_entity_to_identifier')) {
$container->setAlias('dag_entity_to_identifier', 'dag_document_to_identifier');
}
}
if ($container->hasDefinition('doctrine_phpcr')) {
$definition = new DefinitionDecorator('dag.form.type.object_to_identifier');
$definition->addArgument(new Reference('doctrine_phpcr'));
$definition->addArgument('dag_phpcr_document_to_identifier');
$definition->addTag('form.type', array('alias' => 'dag_phpcr_document_to_identifier'));
$container->setDefinition('dag_phpcr_document_to_identifier', $definition);
if (!$container->hasDefinition('dag_entity_to_identifier')) {
$container->setAlias('dag_entity_to_identifier', 'dag_phpcr_document_to_identifier');
}
}
}
作者:sanchoja
项目:oldmytriptocub
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
foreach ($container->findTaggedServiceIds('payum.storage_extension') as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
$paymentIds = array();
if (isset($attributes['all']) && $attributes['all']) {
$paymentIds = array_merge($paymentIds, $this->findAllPaymentIds($container));
}
if (isset($attributes['factory']) && $attributes['factory']) {
$paymentIds = array_merge($paymentIds, $this->findPaymentIdsByFactory($container, $attributes['factory']));
}
if (isset($attributes['context']) && $attributes['context']) {
$paymentIds = array_merge($paymentIds, $this->findPaymentIdsByContext($container, $attributes['context']));
}
$paymentIds = array_filter(array_unique($paymentIds));
foreach ($paymentIds as $paymentId) {
$storageExtension = new DefinitionDecorator('payum.extension.storage.prototype');
$storageExtension->replaceArgument(0, new Reference($id));
$storageExtension->setPublic(false);
if (false !== strpos($id, '.storage.')) {
$storageExtensionId = str_replace('.storage.', '.extension.storage.', $id);
} else {
throw new LogicException(sprintf('In order to add storage to extension the storage %id has to contains ".storage." inside.', $id));
}
$container->setDefinition($storageExtensionId, $storageExtension);
$payment = $container->getDefinition($paymentId);
$payment->addMethodCall('addExtension', array(new Reference($storageExtensionId), isset($attributes['prepend']) && $attributes['prepend']));
}
}
}
}
作者:nickaggarwa
项目:sample-symfony
public function testSetArgument()
{
$def = new DefinitionDecorator('foo');
$this->assertEquals(array(), $def->getArguments());
$this->assertSame($def, $def->setArgument(0, 'foo'));
$this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
}
作者:Tobio
项目:CsaGuzzleBundl
/**
* Sets up handlers and registers middleware for each tagged client.
*
* @param ContainerBuilder $container
* @param array $middlewareBag
*/
private function registerMiddleware(ContainerBuilder $container, array $middlewareBag)
{
$clients = $container->findTaggedServiceIds(self::CLIENT_TAG);
foreach ($clients as $clientId => $tags) {
if (count($tags) > 1) {
throw new \LogicException('Clients should use a single \'csa_guzzle.client\' tag');
}
$clientMiddleware = $middlewareBag;
if (isset($tags[0]['middleware'])) {
$whitelist = explode(' ', $tags[0]['middleware']);
$clientMiddleware = array_filter($clientMiddleware, function ($value) use($whitelist) {
return in_array($value['alias'], $whitelist, true);
});
}
$handlerStack = new DefinitionDecorator('csa_guzzle.handler_stack');
$handlerStack->setPublic(false);
foreach ($clientMiddleware as $middleware) {
$handlerStack->addMethodCall('push', [new Reference($middleware['id']), $middleware['alias']]);
}
$clientHandlerStackId = sprintf('csa_guzzle.handler_stack.%s', $clientId);
$container->setDefinition($clientHandlerStackId, $handlerStack);
$clientDefinition = $container->findDefinition($clientId);
$arguments = $clientDefinition->getArguments();
$options = [];
if (!empty($arguments)) {
$options = array_shift($arguments);
}
$options['handler'] = new Reference($clientHandlerStackId);
array_unshift($arguments, $options);
$clientDefinition->setArguments($arguments);
}
}
作者:agentsi
项目:jsonrpc-bundl
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
if (array_key_exists('servers', $config)) {
foreach ($config['servers'] as $id => $server) {
$container->setParameter('json_rpc.serializer.class', $server['serializer']);
$container->setParameter('json_rpc.reflection.class', $server['reflection']);
$definition = new DefinitionDecorator('json_rpc.server');
$definition->addTag('json_rpc.servers', array('resource' => $id));
foreach ($server['services'] as $service) {
$definition->addMethodCall('addService', array($service['namespace'], $service['class']));
}
$container->setDefinition(sprintf('json_rpc.server.%s', $id), $definition);
$definition = new DefinitionDecorator('json_rpc.transport.internal');
$definition->addTag('json_rpc.transports');
$definition->replaceArgument(0, new Reference(sprintf('json_rpc.server.%s', $id)));
$container->setDefinition(sprintf('json_rpc.transport.internal.%s', $id), $definition);
$definition = new DefinitionDecorator('json_rpc.client.internal');
$definition->addTag('json_rpc.clients.internal');
$definition->replaceArgument(0, new Reference(sprintf('json_rpc.transport.internal.%s', $id)));
$container->setDefinition(sprintf('json_rpc.client.internal.%s', $id), $definition);
}
}
}
作者:piotrminkin
项目:pm
/**
* @inheritdoc
*/
public function process(ContainerBuilder $container)
{
$definitions = array();
$servicesIds = $container->findTaggedServiceIds('pmd_state_machine.token_configurable');
foreach ($servicesIds as $serviceId => $tag) {
$group = isset($tag[0]['group']) ? $tag[0]['group'] : null;
$type = isset($tag[0]['type']) ? $tag[0]['type'] : null;
if (!isset($group) || !isset($type)) {
throw new \InvalidArgumentException(sprintf('Services tagged %s must have group and type defined', 'pmd_state_machine.token_configurable'));
}
$serviceDefinition = $container->getDefinition($serviceId);
$optionsId = sprintf('pmd_state_machine.behavior.%s_%s_options', $group, $type);
$optionsReference = new Reference($optionsId, ContainerInterface::NULL_ON_INVALID_REFERENCE);
// Configure options resolver
$resolverId = sprintf('pmd_state_machine.behavior.%s_%s_resolver', $group, $type);
$resolverReference = new Reference($resolverId);
$resolverDefinition = new DefinitionDecorator('pmd_state_machine.behavior_resolver.token_options_resolver');
$resolverDefinition->replaceArgument(0, $optionsReference);
// Configure configurable decorator
$configId = sprintf('pmd_state_machine.behavior.%s_%s_configurator', $group, $type);
$configDefinition = new DefinitionDecorator('pmd_state_machine.behavior.token_configurable_configurator');
$configDefinition->replaceArgument(0, $resolverReference);
$serviceDefinition->setConfigurator(array(new Reference($configId, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false), 'configure'));
$definitions[$resolverId] = $resolverDefinition;
$definitions[$configId] = $configDefinition;
}
$container->addDefinitions($definitions);
}
作者:necatikarta
项目:generator-grunt-symfon
/**
* Returns a definition for an asset package.
*
* @param ContainerBuilder $container Container
* @param array $httpUrls SSL assets_base_urls
* @param array $sslUrls assets_base_urls
* @param string $rootDir Directory where to look for reved assets
* @param string $summaryFile Grunt filerev summary file
* @param string $cacheDir Kernel cache dir
* @param bool $debug Debug mode?
* @param string $name Package name
*
* @return DefinitionDecorator
*/
private function createPackageDefinition(ContainerBuilder $container, array $httpUrls, array $sslUrls, $rootDir, $summaryFile, $cacheDir, $debug, $name = null)
{
if (!$httpUrls) {
$package = new DefinitionDecorator('grunt.filerev.templating.asset.path_package');
$package->setPublic(false)->setScope('request')->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
return $package;
}
if ($httpUrls == $sslUrls) {
$package = new DefinitionDecorator('grunt.filerev.templating.asset.url_package');
$package->setPublic(false)->replaceArgument(0, $sslUrls)->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
return $package;
}
$prefix = $name ? 'templating.asset.package.' . $name : 'templating.asset.default_package';
$httpPackage = new DefinitionDecorator('grunt.filerev.templating.asset.url_package');
$httpPackage->replaceArgument(0, $httpUrls)->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
$container->setDefinition($prefix . '.http', $httpPackage);
if ($sslUrls) {
$sslPackage = new DefinitionDecorator('grunt.filerev.templating.asset.url_package');
$sslPackage->replaceArgument(0, $sslUrls)->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
} else {
$sslPackage = new DefinitionDecorator('grunt.filerev.templating.asset.path_package');
$sslPackage->setScope('request')->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
}
$container->setDefinition($prefix . '.ssl', $sslPackage);
$package = new DefinitionDecorator('templating.asset.request_aware_package');
$package->setPublic(false)->setScope('request')->replaceArgument(1, $prefix . '.http')->replaceArgument(2, $prefix . '.ssl');
return $package;
}
作者:aboutcoder
项目:file-distribution-bundl
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/services'));
if ('custom' !== $config['db_driver']) {
$loader->load(sprintf('%s.xml', $config['db_driver']));
}
$this->remapParametersNamespaces($config, $container, array('' => array('db_driver' => 'abc.file_distribution.storage', 'model_manager_name' => 'abc.file_distribution.model_manager_name')));
if (!empty($config['definition'])) {
$this->loadFilesystem($config['definition'], $container, $loader, $config['db_driver']);
}
$loader->load('service.xml');
if (isset($config['filesystems'])) {
foreach ($config['filesystems'] as $name => $filesystem) {
$definitionId = 'abc.file_distribution.definition.' . $name;
$definition = new DefinitionDecorator('abc.file_distribution.definition.prototype');
$definition->addMethodCall('setType', array($filesystem['type']));
$definition->addMethodCall('setPath', array($filesystem['path']));
$definition->addMethodCall('setProperties', array($filesystem['options']));
$container->setDefinition($definitionId, $definition);
$definition = new Definition('Abc\\Filesystem\\Filesystem', array(new Reference('abc.file_distribution.adapter_factory'), new Reference($definitionId)));
$container->setDefinition('abc.file_distribution.filesystem.' . $name, $definition);
}
}
}
作者:conject
项目:nemro
/**
* @param ContainerBuilder $container
*
* @throws \InvalidArgumentException
*/
public function process(ContainerBuilder $container)
{
$config = $container->getExtensionConfig('elastica')[0];
$jsonLdFrameLoader = $container->get('nemrod.elastica.jsonld.frame.loader.filesystem');
$confManager = $container->getDefinition('nemrod.elastica.config_manager');
$filiationBuilder = $container->get('nemrod.filiation.builder');
$jsonLdFrameLoader->setFiliationBuilder($filiationBuilder);
foreach ($config['indexes'] as $name => $index) {
$indexName = isset($index['index_name']) ? $index['index_name'] : $name;
foreach ($index['types'] as $typeName => $settings) {
$jsonLdFrameLoader->setEsIndex($name);
$frame = $jsonLdFrameLoader->load($settings['frame'], null, true, true, true);
$type = !empty($frame['@type']) ? $frame['@type'] : $settings['type'];
if (empty($type)) {
throw \Exception("You must provide a RDF Type.");
}
//type
$typeId = 'nemrod.elastica.type.' . $name . '.' . $typeName;
$indexId = 'nemrod.elastica.index.' . $name;
$typeDef = new DefinitionDecorator('nemrod.elastica.type.abstract');
$typeDef->replaceArgument(0, $type);
$typeDef->setFactory(array(new Reference($indexId), 'getType'));
$typeDef->addTag('nemrod.elastica.type', array('index' => $name, 'name' => $typeName, 'type' => $type));
$container->setDefinition($typeId, $typeDef);
//registering config to configManager
$confManager->addMethodCall('setTypeConfigurationArray', array($name, $typeName, $type, $frame));
}
}
}
作者:schmeiser
项目:qandidate-toggle-bundl
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/'));
$loader->load('services.xml');
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), $configs);
$collection = 'in_memory';
switch (true) {
case 'redis' === $config['persistence']:
$loader->load('redis.xml');
$collection = 'predis';
$container->setParameter('qandidate.toggle.redis.namespace', $config['redis_namespace']);
$container->setAlias('qandidate.toggle.redis.client', $config['redis_client']);
break;
case 'factory' === $config['persistence']:
$collection = 'factory';
$definition = new DefinitionDecorator('qandidate.toggle.collection.in_memory');
$definition->setFactory(array(new Reference($config['collection_factory']['service_id']), $config['collection_factory']['method']));
$container->setDefinition('qandidate.toggle.collection.factory', $definition);
break;
}
$container->setAlias('qandidate.toggle.collection', 'qandidate.toggle.collection.' . $collection);
$contextFactoryService = 'qandidate.toggle.user_context_factory';
if (null !== $config['context_factory']) {
$contextFactoryService = $config['context_factory'];
}
$container->setAlias('qandidate.toggle.context_factory', $contextFactoryService);
}
作者:appsc
项目:appsco-php-clien
/**
* Subclasses must return the id of a service which implements the
* AuthenticationProviderInterface.
*
* @param ContainerBuilder $container
* @param string $id The unique id of the firewall
* @param array $config The options array for this listener
* @param string $userProviderId The id of the user provider
*
* @return string never null, the id of the authentication provider
*/
protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId)
{
$providerId = 'security.authentication.provider.appsco.' . $id;
$provider = new DefinitionDecorator('security.authentication.provider.appsco');
$provider->replaceArgument(0, new Reference($userProviderId));
$container->setDefinition($providerId, $provider);
return $providerId;
}
作者:regularjac
项目:frontend-bundl
private function createAssetVersionStrategy($packageName, $versionStrategy)
{
$version = new DefinitionDecorator($this->namespaceService('asset.version_strategy'));
$version->addArgument($versionStrategy);
$versionId = $this->namespaceService("_package.{$packageName}.version_strategy_asset");
$this->container->setDefinition($versionId, $version);
return new Reference($versionId);
}
作者:blazareck
项目:lu
public function testMenu()
{
$definition = new DefinitionDecorator('lug.ui.menu.builder');
$definition->setClass($class = $this->createMenuBuilderClassMock());
$this->container->setDefinition($menuName = 'lug.ui.menu.test', $definition);
$this->compileContainer();
$this->assertInstanceOf($class, $this->container->get($menuName));
}
作者:feso
项目:request-object
private function registerPayloadResolver(ContainerBuilder $container)
{
$definition = new Definition(PayloadResolver::class);
$definition->setAbstract(true);
$container->setDefinition('request_object.payload_resolver', $definition);
$implDefinition = new DefinitionDecorator('request_object.payload_resolver');
$implDefinition->setClass(HttpPayloadResolver::class);
$container->setDefinition('request_object.payload_resolver.http', $implDefinition);
}
作者:Raxer97
项目:challeng
/**
* {@inheritDoc}
*/
protected function createStorage(ContainerBuilder $container, $modelClass, array $config)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config/storage'));
$loader->load('doctrine.' . $config['driver'] . '.xml');
$storage = new DefinitionDecorator(sprintf('payum.storage.doctrine.%s', $config['driver']));
$storage->setPublic(true);
$storage->replaceArgument(1, $modelClass);
return $storage;
}
作者:DocHonch
项目:PayumBundl
/**
* {@inheritDoc}
*/
protected function createStorage(ContainerBuilder $container, $modelClass, array $config)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config/storage'));
$loader->load('propel1.xml');
$storage = new DefinitionDecorator('payum.storage.propel1');
$storage->setPublic(true);
$storage->replaceArgument(0, $modelClass);
return $storage;
}
作者:winzo
项目:payum-limoneti
/**
* {@inheritDoc}
*/
protected function addApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config)
{
$apiDefinition = new DefinitionDecorator('payum.limonetik.api.prototype');
$apiDefinition->replaceArgument(0, array('merchantId' => $config['merchant_id'], 'key' => $config['key'], 'sandbox' => $config['sandbox']));
$apiDefinition->setPublic(true);
$apiId = 'payum.context.' . $contextName . '.api';
$container->setDefinition($apiId, $apiDefinition);
$paymentDefinition->addMethodCall('addApi', array(new Reference($apiId)));
}
作者:networksof
项目:seekerplus.co
/**
* {@inheritDoc}
*/
public function create(ContainerBuilder $container, $resolverName, array $config)
{
$awsS3ClientId = 'liip_imagine.cache.resolver.'.$resolverName.'.client';
$awsS3ClientDefinition = new Definition('Aws\S3\S3Client');
if (method_exists($awsS3ClientDefinition, 'setFactory')) {
$awsS3ClientDefinition->setFactory(array('Aws\S3\S3Client', 'factory'));
} else {
// to be removed when dependency on Symfony DependencyInjection is bumped to 2.6
$awsS3ClientDefinition->setFactoryClass('Aws\S3\S3Client');
$awsS3ClientDefinition->setFactoryMethod('factory');
}
$awsS3ClientDefinition->addArgument($config['client_config']);
$container->setDefinition($awsS3ClientId, $awsS3ClientDefinition);
$resolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.aws_s3');
$resolverDefinition->replaceArgument(0, new Reference($awsS3ClientId));
$resolverDefinition->replaceArgument(1, $config['bucket']);
$resolverDefinition->replaceArgument(2, $config['acl']);
$resolverDefinition->replaceArgument(3, array_replace($config['url_options'], $config['get_options']));
$resolverDefinition->replaceArgument(4, $config['put_options']);
$resolverId = 'liip_imagine.cache.resolver.'.$resolverName;
$container->setDefinition($resolverId, $resolverDefinition);
if (isset($config['cache_prefix'])) {
$resolverDefinition->addMethodCall('setCachePrefix', array($config['cache_prefix']));
}
if ($config['proxies']) {
$proxiedResolverId = 'liip_imagine.cache.resolver.'.$resolverName.'.proxied';
$container->setDefinition($proxiedResolverId, $resolverDefinition);
$proxyResolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.proxy');
$proxyResolverDefinition->replaceArgument(0, new Reference($proxiedResolverId));
$proxyResolverDefinition->replaceArgument(1, $config['proxies']);
$container->setDefinition($resolverId, $proxyResolverDefinition);
}
if ($config['cache']) {
$cachedResolverId = 'liip_imagine.cache.resolver.'.$resolverName.'.cached';
$container->setDefinition($cachedResolverId, $container->getDefinition($resolverId));
$cacheResolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.cache');
$cacheResolverDefinition->replaceArgument(0, new Reference($config['cache']));
$cacheResolverDefinition->replaceArgument(1, new Reference($cachedResolverId));
$container->setDefinition($resolverId, $cacheResolverDefinition);
}
$container->getDefinition($resolverId)->addTag('liip_imagine.cache.resolver', array(
'resolver' => $resolverName,
));
return $resolverId;
}
作者:fattouchsqual
项目:AMFWebServicesSecurityBundl
/**
* Creates the listener.
*
* @return string
*/
protected function createListener($container, $id, $config, $userProvider)
{
$listenerId = $this->getListenerId();
$listener = new DefinitionDecorator($listenerId);
$listener->replaceArgument(2, $id);
$listenerId .= '.' . $id;
$container->setDefinition($listenerId, $listener);
return $listenerId;
}