Gets a service definition.
public getDefinition ( string $id ) : |
||
$id | string | The service identifier |
Résultat | A Definition instance |
public function process(ContainerBuilder $container) { if (!$container->hasDefinition('form.extension')) { return; } $definition = $container->getDefinition('form.extension'); // Builds an array with service IDs as keys and tag aliases as values $types = array(); foreach ($container->findTaggedServiceIds('form.type') as $serviceId => $tag) { // The following if-else block is deprecated and will be removed // in Symfony 3.0 // Deprecation errors are triggered in the form registry if (isset($tag[0]['alias'])) { $types[$tag[0]['alias']] = $serviceId; } else { $types[$serviceId] = $serviceId; } // Support type access by FQCN $serviceDefinition = $container->getDefinition($serviceId); $types[$serviceDefinition->getClass()] = $serviceId; } $definition->replaceArgument(1, $types); $typeExtensions = array(); foreach ($container->findTaggedServiceIds('form.type_extension') as $serviceId => $tag) { $alias = isset($tag[0]['alias']) ? $tag[0]['alias'] : $serviceId; $typeExtensions[$alias][] = $serviceId; } $definition->replaceArgument(2, $typeExtensions); // Find all services annotated with "form.type_guesser" $guessers = array_keys($container->findTaggedServiceIds('form.type_guesser')); $definition->replaceArgument(3, $guessers); }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $universalExtensions = array(); foreach ($container->findTaggedServiceIds('sonata.admin.extension') as $id => $tags) { foreach ($tags as $attributes) { $target = false; if (isset($attributes['target'])) { $target = $attributes['target']; } if (isset($attributes['global']) && $attributes['global']) { $universalExtensions[] = $id; } if (!$target || !$container->hasDefinition($target)) { continue; } $container->getDefinition($target)->addMethodCall('addExtension', array(new Reference($id))); } } $extensionConfig = $container->getParameter('sonata.admin.extension.map'); $extensionMap = $this->flattenExtensionConfiguration($extensionConfig); foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) { $admin = $container->getDefinition($id); foreach ($universalExtensions as $extension) { $admin->addMethodCall('addExtension', array(new Reference($extension))); } $extensions = $this->getExtensionsForAdmin($id, $admin, $container, $extensionMap); foreach ($extensions as $extension) { if (!$container->has($extension)) { throw new \InvalidArgumentException(sprintf('Unable to find extension service for id %s', $extension)); } $admin->addMethodCall('addExtension', array(new Reference($extension))); } } }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $typeIdx = array(); foreach ($container->findTaggedServiceIds('form.type') as $id => $tags) { $typeIdx[] = $id; } $typeExtensionIdx = array(); foreach ($container->findTaggedServiceIds('form.type_extension') as $id => $tag) { $typeExtensionIdx[] = $id; } $container->setParameter('sonata.core.form.types', $typeIdx); $container->setParameter('sonata.core.form.type_extensions', $typeExtensionIdx); // nothing to do if (!$container->hasDefinition('sonata.core.form.extension.dependency')) { return; } // get factories $original = $container->getDefinition('form.extension'); $factory = $container->getDefinition('sonata.core.form.extension.dependency'); $factory->replaceArgument(1, $original->getArgument(1)); $factory->replaceArgument(2, $original->getArgument(2)); $factory->replaceArgument(3, $original->getArgument(3)); $container->removeDefinition('form.extension'); $container->removeDefinition('sonata.core.form.extension.dependency'); $container->setDefinition('form.extension', $factory); }
public function load(array $configs, ContainerBuilder $container) { $processor = new Processor(); $config = $processor->processConfiguration(new Configuration(), $configs); $loader = new XmlFileLoader($container, new FileLocator(array(__DIR__ . '/../Resources/config'))); $loader->load('services.xml'); $container->setParameter('jms_i18n_routing.default_locale', $config['default_locale']); $container->setParameter('jms_i18n_routing.locales', $config['locales']); $container->setParameter('jms_i18n_routing.catalogue', $config['catalogue']); $container->setParameter('jms_i18n_routing.strategy', $config['strategy']); $this->addClassesToCompile(array($container->getDefinition('jms_i18n_routing.router')->getClass())); if ('prefix' === $config['strategy']) { $container->getDefinition('jms_i18n_routing.locale_choosing_listener')->setPublic(true)->addTag('kernel.event_listener', array('event' => 'kernel.exception', 'priority' => 128)); } if ($config['hosts']) { $container->getDefinition('jms_i18n_routing.router')->addMethodCall('setHostMap', array($config['hosts'])); $container->getDefinition('jms_i18n_routing.locale_changing_listener')->setPublic(true)->addTag('kernel.event_listener', array('event' => 'kernel.request', 'priority' => 120))->addArgument(array_flip($config['hosts'])); $this->addClassesToCompile(array($container->getDefinition('jms_i18n_routing.locale_changing_listener')->getClass())); } // remove route extractor if JMSTranslationBundle is not enabled to avoid any problems $bundles = $container->getParameter('kernel.bundles'); if (!isset($bundles['JMSTranslationBundle'])) { $container->removeDefinition('jms_i18n_routing.route_translation_extractor'); } }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $container->getDefinition('sensio_framework_extra.routing.loader.annot_class')->addMethodCall('setSiteContext', array(new Reference('site_context'))); $container->getDefinition('router.default')->setClass('Alex\\MultisiteBundle\\Router\\MultisiteRouter'); $container->getDefinition('router.default')->addMethodCall('setSiteContext', array(new Reference('site_context'))); $container->getDefinition('router.default')->addMethodCall('setSortRoutes', array("%alex_multisite.sort_routes%")); }
/** * @inheritdoc */ public function process(ContainerBuilder $container) { $taggedServices = $container->findTaggedServiceIds('ojezu.add_call_to_remote_service'); foreach ($taggedServices as $serviceName => $tags) { foreach ($tags as $tag) { $remoteService = $tag['remote_service']; if ($remoteService[0] === '@') { $remoteService = $container->getDefinition(substr($remoteService, 1)); } $arguments = []; foreach ($tag as $attributeName => $attributeValue) { $match = []; if (preg_match('/^argument\\.(\\d+)$/', $attributeName, $match)) { if (is_string($attributeValue)) { if ($attributeValue === '@') { $attributeValue = $container->getDefinition($serviceName); } elseif ($attributeValue[0] === '@') { $attributeValue = $container->getDefinition(substr($attributeValue, 1)); } } $arguments[(int) $match[1]] = $attributeValue; } } $remoteService->addMethodCall($tag['method'], array_values($arguments)); } } }
/** * {@inheritdoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load(sprintf('services.%s.yml', $config['db_driver'])); $container->setParameter($this->getAlias() . '.db_driver', $config['db_driver']); $container->setParameter($this->getAlias() . '.model_manager_name', $config['model_manager_name']); $container->setParameter($this->getAlias() . '.cronjob_class', $config['cronjob_class']); $container->setParameter($this->getAlias() . '.cronjob_console', $config['cronjob_console']); $container->setParameter($this->getAlias() . '.logs_path', $config['logs_path']); if ('orm' === $config['db_driver']) { $managerService = $this->getAlias() . '.entity_manager'; $doctrineService = 'doctrine'; } else { $managerService = ''; $doctrineService = ''; } $definition = $container->getDefinition($managerService); if (method_exists($definition, 'setFactory')) { $definition->setFactory(array(new Reference($doctrineService), 'getManager')); } else { $definition->setFactoryService($doctrineService); $definition->setFactoryMethod('getManager'); } $container->setAlias($this->getAlias() . '.manager', $config['crontab_manager']); $definition = $container->getDefinition($config['crontab_manager']); $definition->addMethodCall('registryConfigCronjobs', array($config['jobs'])); $loader->load('services.yml'); }
public function process(ContainerBuilder $container) { if (!$container->hasDefinition('sonata.notification.dispatcher')) { return; } $definition = $container->getDefinition('sonata.notification.dispatcher'); $informations = array(); foreach ($container->findTaggedServiceIds('sonata.notification.consumer') as $id => $events) { foreach ($events as $event) { $priority = isset($event['priority']) ? $event['priority'] : 0; if (!isset($event['type'])) { throw new \InvalidArgumentException(sprintf('Service "%s" must define the "type" attribute on "sonata.notification" tags.', $id)); } if (!isset($informations[$event['type']])) { $informations[$event['type']] = array(); } $informations[$event['type']][] = $id; $definition->addMethodCall('addListenerService', array($event['type'], array($id, 'process'), $priority)); } } $container->getDefinition('sonata.notification.consumer.metadata')->replaceArgument(0, $informations); if ($container->getParameter('sonata.notification.event.iteration_listeners')) { $ids = $container->getParameter('sonata.notification.event.iteration_listeners'); foreach ($ids as $serviceId) { $definition = $container->getDefinition($serviceId); $class = new \ReflectionClass($definition->getClass()); if (!$class->implementsInterface('Sonata\\NotificationBundle\\Event\\IterationListener')) { throw new RuntimeException('Iteration listeners must implement Sonata\\NotificationBundle\\Event\\IterationListener'); } $definition->addTag('kernel.event_listener', array('event' => IterateEvent::EVENT_NAME, 'method' => 'iterate')); } } }
/** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $container->setParameter('rs_queue.queues', $config['queues']); $container->setParameter('rs_queue.serializer.class', $config['serializer']); $container->setParameter('rs_queue.server.redis', $config['server']['redis']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); // BC sf < 2.6 $definition = $container->getDefinition('rs_queue.serializer'); if (method_exists($definition, 'setFactory')) { $definition->setFactory(array(new Reference('rs_queue.serializer.factory'), 'get')); } else { $definition->setFactoryService('rs_queue.serializer.factory'); $definition->setFactoryMethod('get'); } // BC sf < 2.6 $definition = $container->getDefinition('rs_queue.redis'); if (method_exists($definition, 'setFactory')) { $definition->setFactory(array(new Reference('rs_queue.redis.factory'), 'get')); } else { $definition->setFactoryService('rs_queue.redis.factory'); $definition->setFactoryMethod('get'); } }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { // add inference types $inferenceTypeContainer = $container->getDefinition('rezzza.ruler.inference_type_container'); foreach ($container->findTaggedServiceIds('rezzza.ruler.inference_type') as $id => $tagAttributes) { $inferenceTypeContainer->addMethodCall('add', array(new Reference($id))); } // add events $eventDatas = $container->getParameter('rezzza.ruler.events'); $eventContainer = $container->getDefinition('rezzza.ruler.event.container'); $events = array(); foreach ($eventDatas as $key => $data) { $event = new Definition('Rezzza\\RulerBundle\\Ruler\\Event\\Event', array($key, $data['label'], $data['context_builder'])); $events[$key] = $event; $eventContainer->addMethodCall('add', array($event)); } // add inferences $inferenceDatas = $container->getParameter('rezzza.ruler.inferences'); $inferenceContainer = $container->getDefinition('rezzza.ruler.inference_container'); foreach ($inferenceDatas as $key => $data) { $inference = new Definition('Rezzza\\RulerBundle\\Ruler\\Inference\\Inference', array($key, $data['type'], $data['description'], $data['event'])); foreach ($data['event'] as $event) { if (!isset($events[$event])) { throw new \LogicException(sprintf('Event "%s" is not defined', $event)); } $events[$event]->addMethodCall('addInference', array($inference)); } $inferenceContainer->addMethodCall('add', array($inference)); } /* --- functions --- */ $rulerDefinition = $container->getDefinition('rezzza.ruler'); foreach ($container->findTaggedServiceIds('rezzza.ruler.functions') as $id => $tagAttributes) { $rulerDefinition->addMethodCall('addFunctionCollection', array(new Reference($id))); } }
/** * {@inheritDoc} */ public function process(ContainerBuilder $container) { if (!$this->integrationExtension->isVarTagValidatorEnabled()) { if (count($container->findTaggedServiceIds('validator.var_tag.constraint_factory')) > 0) { throw new \RuntimeException('Could not compile var tag validator constraint factory, because system is not enabled.'); } return; } $registryDefinition = $container->getDefinition('validator.var_tag.constraint_factory_registry'); foreach ($container->findTaggedServiceIds('validator.var_tag.constraint_factory') as $id => $tags) { $factoryDefinition = $container->getDefinition($id); $class = $factoryDefinition->getClass(); try { $class = $container->getParameterBag()->resolveValue($class); $refClass = new \ReflectionClass($class); $requiredInterface = 'FivePercent\\Component\\VarTagValidator\\Constraint\\ConstraintFactoryInterface'; if (!$refClass->implementsInterface($requiredInterface)) { throw new \RuntimeException(sprintf('The var tag constraint factory should implement "%s" interface.', $requiredInterface)); } foreach ($tags as $attributes) { if (empty($attributes['type'])) { throw new \RuntimeException('Missing attribute "type".'); } $registryDefinition->addMethodCall('addConstraintFactory', [$attributes['type'], new Reference($id)]); } } catch (\Exception $e) { throw new \RuntimeException(sprintf('Could not compile var tag validator constraint factory with service id "%s".', $id)); } } }
/** * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container */ public function process(ContainerBuilder $container) { if (!$container->hasDefinition('ezpublish.chain_router')) { return; } $chainRouter = $container->getDefinition('ezpublish.chain_router'); // Enforce default router to be part of the routing chain // The default router will be given the highest priority so that it will be used by default if ($container->hasDefinition('router.default')) { $defaultRouter = $container->getDefinition('router.default'); $defaultRouter->addMethodCall('setSiteAccess', array(new Reference('ezpublish.siteaccess'))); $defaultRouter->addMethodCall('setConfigResolver', array(new Reference('ezpublish.config.resolver'))); $defaultRouter->addMethodCall('setNonSiteAccessAwareRoutes', array('%ezpublish.default_router.non_siteaccess_aware_routes%')); $defaultRouter->addMethodCall('setLegacyAwareRoutes', array('%ezpublish.default_router.legacy_aware_routes%')); $defaultRouter->addMethodCall('setSiteAccessRouter', array(new Reference('ezpublish.siteaccess_router'))); if (!$defaultRouter->hasTag('router')) { $defaultRouter->addTag('router', array('priority' => 255)); } } foreach ($container->findTaggedServiceIds('router') as $id => $attributes) { $priority = isset($attributes[0]['priority']) ? (int) $attributes[0]['priority'] : 0; // Priority range is between -255 (the lowest) and 255 (the highest) if ($priority > 255) { $priority = 255; } if ($priority < -255) { $priority = -255; } $chainRouter->addMethodCall('add', array(new Reference($id), $priority)); } }
public function process(ContainerBuilder $container) { if (!$container->hasDefinition('templating.engine')) { return; } $renderers = array(); foreach ($container->findTaggedServiceIds('templating.renderer') as $id => $attributes) { if (isset($attributes[0]['alias'])) { $renderers[$attributes[0]['alias']] = new Reference($id); $container->getDefinition($id)->addMethodCall('setEngine', array(new Reference('templating.engine'))); } } $helpers = array(); foreach ($container->findTaggedServiceIds('templating.helper') as $id => $attributes) { if (isset($attributes[0]['alias'])) { $helpers[$attributes[0]['alias']] = $id; } } $definition = $container->getDefinition('templating.engine'); $arguments = $definition->getArguments(); $arguments[2] = $renderers; $definition->setArguments($arguments); if (count($helpers) > 0) { $definition->addMethodCall('setHelpers', array($helpers)); } }
/** * {@inheritDoc} */ public function process(ContainerBuilder $container) { // WebHome Auth url in user bar if ($container->hasParameter('webhome_auth_url')) { $container->getDefinition('webhome.menu.user_bar')->addArgument($container->getParameter('webhome_auth_url')); } // Listener for build menu if (!$container->hasDefinition('webhome.listener.menu')) { return; } $config = $container->getExtensionConfig('ndewez_web_home_common')[0]; $menuListener = $container->getDefinition('webhome.listener.menu'); if (isset($config['menu']['getter'])) { if (!$container->hasDefinition($config['menu']['getter'])) { throw new InvalidArgumentException(sprintf('Service %s doesn\'t exists', $config['menu']['getter'])); } $menuListener->addMethodCall('setGetter', [$container->getDefinition($config['menu']['getter'])]); } if (isset($config['menu']['builder'])) { if (!$container->hasDefinition($config['menu']['builder'])) { throw new InvalidArgumentException(sprintf('Service %s doesn\'t exists', $config['menu']['builder'])); } $menuListener->addMethodCall('setBuilderMenuItems', [$container->getDefinition($config['menu']['builder'])]); } if (isset($config['menu']['builder'])) { $menuListener->addMethodCall('setUseSession', [$config['menu']['session']]); } }
public function process(ContainerBuilder $container) { if (!$container->hasDefinition($this->dispatcherService)) { return; } $definition = $container->getDefinition($this->dispatcherService); foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) { foreach ($events as $event) { $priority = isset($event['priority']) ? $event['priority'] : 0; if (!isset($event['event'])) { throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id)); } if (!isset($event['method'])) { $event['method'] = 'on' . preg_replace_callback(array('/(?<=\\b)[a-z]/i', '/[^a-z0-9]/i'), function ($matches) { return strtoupper($matches[0]); }, $event['event']); $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']); } $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); } } foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) { // We must assume that the class value has been correctly filled, even if the service is created by a factory $class = $container->getDefinition($id)->getClass(); $refClass = new \ReflectionClass($class); $interface = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface'; if (!$refClass->implementsInterface($interface)) { throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface)); } $definition->addMethodCall('addSubscriberService', array($id, $class)); } }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $pool = $container->getDefinition('sonata.product.pool'); $calls = $pool->getMethodCalls(); $pool->setMethodCalls(array()); $map = array(); foreach ($calls as $method => $arguments) { if ($arguments[0] !== '__hack') { $pool->addMethodCall($arguments[0], $arguments[1]); continue; } foreach ($arguments[1] as $code => $options) { // define a new ProductDefinition $definition = new Definition('Sonata\\Component\\Product\\ProductDefinition', array(new Reference($options['provider']), new Reference($options['manager']))); $definition->setPublic(false); $container->setDefinition($code, $definition); $container->getDefinition($options['provider'])->addMethodCall('setCode', array($code)); $pool->addMethodCall('addProduct', array($code, new Reference($code))); $map[$code] = $container->getDefinition($options['manager'])->getArgument(0); $container->getDefinition($options['provider'])->addMethodCall('setBasketElementManager', array(new Reference('sonata.basket_element.manager'))); $container->getDefinition($options['provider'])->addMethodCall('setCurrencyPriceCalculator', array(new Reference('sonata.price.currency.calculator'))); $container->getDefinition($options['provider'])->addMethodCall('setProductCategoryManager', array(new Reference('sonata.product_category.product'))); $container->getDefinition($options['provider'])->addMethodCall('setProductCollectionManager', array(new Reference('sonata.product_collection.product'))); $container->getDefinition($options['provider'])->addMethodCall('setOrderElementClassName', array($container->getParameter('sonata.order.order_element.class'))); if (array_key_exists('variations', $options)) { $container->getDefinition($options['provider'])->addMethodCall('setVariationFields', array($options['variations']['fields'])); } } } $container->getDefinition('sonata.product.subscriber.orm')->replaceArgument(0, $map); }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $tags = $container->findTaggedServiceIds(self::TAG_NAME); foreach ($tags as $id => $tag) { /** @var Definition $serviceLinkDef */ $serviceLinkDef = $container->getDefinition($id); if (!isset($tag[0]['service'])) { throw new \RuntimeException(sprintf("Tag '%s' for service '%s' doesn't have required param 'service'", self::TAG_NAME, $id)); } $serviceId = $tag[0]['service']; $isOptional = false; if (strpos($serviceId, '?') === 0) { $serviceId = substr($serviceId, 1); $isOptional = true; } if ($container->hasDefinition($serviceId)) { // the service we are referred to must be public $serviceDef = $container->getDefinition($serviceId); if (!$serviceDef->isPublic()) { $serviceDef->setPublic(true); } } elseif (!$isOptional) { throw new \RuntimeException(sprintf('Target service "%s" is undefined. The service link "%s" with tag "%s" and tag-service "%s"', $serviceId, $id, self::TAG_NAME, $serviceId)); } $serviceLinkDef->setClass('Oro\\Bundle\\SecurityBundle\\DependencyInjection\\Utils\\ServiceLink'); $serviceLinkDef->setArguments([new Reference('service_container'), $serviceId, $isOptional]); } }
/** {@inheritdoc} */ public function load(array $config, ContainerBuilder $container) { // Load configuration (new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')))->load('webpack.yml'); // Retrieve all configuration entities $bundles = $container->getParameter('kernel.bundles'); $builder_definition = $container->getDefinition('hostnet_webpack.bridge.config_generator'); $config_extension_ids = array_keys($container->findTaggedServiceIds('hostnet_webpack.config_extension')); $config_definitions = []; $config_class_names = []; foreach ($config_extension_ids as $id) { $config_definitions[$id] = $container->getDefinition($id); $config_class_names[$id] = $container->getDefinition($id)->getClass(); } $configuration = new Configuration(array_keys($bundles), $config_class_names); $config = $this->processConfiguration($configuration, $config); $container->addResource(new FileResource((new \ReflectionClass(Configuration::class))->getFileName())); // Select the correct node binary for the platform we're currently running on. $config['node']['binary'] = $config['node']['binary'][$this->getPlatformKey()]; $config['node']['node_modules_path'] = !empty($config['node']['node_modules_path']) ? $config['node']['node_modules_path'] : getenv('NODE_PATH'); // Parse application config into the config generator foreach ($config_definitions as $id => $definition) { /* @var $definition Definition */ $builder_definition->addMethodCall('addExtension', [new Reference($id)]); $definition->addArgument($config); } // Pass the configuration to a container parameter for the CompilerPass and profiler to read. $container->setParameter('hostnet_webpack_config', $config); }
public function process(ContainerBuilder $container) { if (!$container->hasParameter('nelmio_browser_adaptive_parser')) { return; } $container->getDefinition('nelmio_security.ua_parser')->setArguments(array($container->getDefinition($container->getParameter('nelmio_browser_adaptive_parser')))); }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { foreach ($container->findTaggedServiceIds('snc_redis.connection_parameters') as $id => $attr) { $clientAlias = $attr[0]['clientAlias']; $parameterDefinition = $container->getDefinition($id); $parameters = $parameterDefinition->getArgument(0); if ($parameters['logging']) { $optionId = sprintf('snc_redis.client.%s_options', $clientAlias); $option = $container->getDefinition($optionId); if (1 < count($option->getArguments())) { throw new \RuntimeException('Please check the predis option arguments.'); } $arguments = $option->getArgument(0); $connectionFactoryId = sprintf('snc_redis.%s_connectionfactory', $clientAlias); $connectionFactoryDef = new Definition($container->getParameter('snc_redis.connection_factory.class')); $connectionFactoryDef->setPublic(false); $connectionFactoryDef->addArgument(new Reference(sprintf('snc_redis.client.%s_profile', $clientAlias))); $connectionFactoryDef->addMethodCall('setConnectionWrapperClass', array($container->getParameter('snc_redis.connection_wrapper.class'))); $connectionFactoryDef->addMethodCall('setLogger', array(new Reference('snc_redis.logger'))); $container->setDefinition($connectionFactoryId, $connectionFactoryDef); $arguments['connections'] = new Reference($connectionFactoryId); $option->replaceArgument(0, $arguments); } } }
/** * @param ContainerBuilder $container * @param array $config */ public function configureDelivery(ContainerBuilder $container, array $config) { $pool = $container->getDefinition('sonata.delivery.pool'); $internal = array('free_address_required' => 'sonata.delivery.method.free_address_required', 'free_address_not_required' => 'sonata.delivery.method.free_address_not_required'); $configured = array(); foreach ($config['services'] as $id => $settings) { if (array_key_exists($id, $internal)) { $id = $internal[$id]; $definition = $container->getDefinition($id); $definition->addMethodCall('setName', array($settings['name'])); $definition->addMethodCall('setCode', array($settings['code'])); $definition->addMethodCall('setPriority', array($settings['priority'])); $configured[$settings['code']] = $id; } } foreach ($config['methods'] as $code => $id) { if (array_key_exists($code, $configured)) { // Internal service $id = $configured[$code]; } if ($container->hasDefinition($id)) { $definition = $container->getDefinition($id); $definition->addMethodCall('setEnabled', array(true)); } // add the delivery method in the method pool $pool->addMethodCall('addMethod', array(new Reference($id))); } // Remove unconfigured services foreach ($internal as $code => $id) { if (false === array_search($id, $configured)) { $container->removeDefinition($id); } } }
/** * Configure the given ContainerBuilder * * This method allows a plugin to register additional services with the * service container. * * @param ContainerBuilder $container * * @return void */ public function configure(ContainerBuilder $container) { $container->register('packages.plugin.satis.subscriber', 'Terramar\\Packages\\Plugin\\Satis\\EventSubscriber')->addArgument(new Reference('packages.helper.resque'))->addArgument(new Reference('doctrine.orm.entity_manager'))->addTag('kernel.event_subscriber'); $container->register('packages.plugin.satis.config_helper', 'Terramar\\Packages\\Plugin\\Satis\\ConfigurationHelper')->addArgument(new Reference('doctrine.orm.entity_manager'))->addArgument('%app.root_dir%')->addArgument('%app.cache_dir%'); $container->getDefinition('packages.controller_manager')->addMethodCall('registerController', array(Actions::PACKAGE_EDIT, 'Terramar\\Packages\\Plugin\\Satis\\Controller::editAction'))->addMethodCall('registerController', array(Actions::PACKAGE_UPDATE, 'Terramar\\Packages\\Plugin\\Satis\\Controller::updateAction')); $container->getDefinition('packages.command_registry')->addMethodCall('addCommand', array('Terramar\\Packages\\Plugin\\Satis\\Command\\BuildCommand'))->addMethodCall('addCommand', array('Terramar\\Packages\\Plugin\\Satis\\Command\\UpdateCommand')); }
/** * You can modify the container here before it is dumped to PHP code. * * @param ContainerBuilder $container * * @api */ public function process(ContainerBuilder $container) { $config = $container->getParameter(ElastificationPhpClientExtension::PARAMETER_CONFIG_KEY); if (true === $config['profiler_enabled']) { $clientAlias = $container->getAlias(ElastificationPhpClientExtension::ALIAS_CLIENT); $profilerDef = $container->getDefinition(ElastificationPhpClientExtension::SERVICE_CLIENT_PROFILER_KEY); $profilerDef->replaceArgument(0, new Reference($clientAlias->__toString())); $dataCollectorDef = $container->getDefinition('elastification_php_client.datacollector'); $dataCollectorDef->addMethodCall('setConfig', array($config)); $container->setAlias(ElastificationPhpClientExtension::ALIAS_CLIENT, ElastificationPhpClientExtension::SERVICE_CLIENT_PROFILER_KEY); } else { if ($container->hasDefinition('profiler')) { $sfProfilerDef = $container->getDefinition('profiler'); $sfProfilerMethodCalls = $sfProfilerDef->getMethodCalls(); foreach ($sfProfilerMethodCalls as $sfProfilerMethodCallsIndex => $sfProfilerMethodCall) { if (isset($sfProfilerMethodCall[1][0]) && 'elastification_php_client.datacollector' == (string) $sfProfilerMethodCall[1][0]) { unset($sfProfilerMethodCalls[$sfProfilerMethodCallsIndex]); } } $sfProfilerDef->setMethodCalls($sfProfilerMethodCalls); } $container->removeDefinition(ElastificationPhpClientExtension::SERVICE_CLIENT_PROFILER_KEY); $container->removeDefinition('elastification_php_client.datacollector'); } }
/** * {@inheritdoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); /** * Load definitions */ $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); $servers = $config['servers']; $container->setParameter('laelaps_gearman.servers', $servers); /** * Build container, if array, add multiple servers, if string add one */ $gearmanClientDefinition = $container->getDefinition('laelaps.gearman.client'); $gearmanWorkerDefinition = $container->getDefinition('laelaps.gearman.worker'); if (is_array($servers)) { foreach ($servers as $server) { list($host, $port) = explode(':', $server); $gearmanClientDefinition->addMethodCall('addServer', array($host, $port)); $gearmanWorkerDefinition->addMethodCall('addServer', array($host, $port)); } } else { $gearmanClientDefinition->addMethodCall('addServers', array($servers)); $gearmanWorkerDefinition->addMethodCall('addServers', array($servers)); } }
/** * @param ContainerBuilder $container * @param string $serviceName * @param string $newServiceName */ private function changeService(ContainerBuilder $container, $serviceName, $newServiceName) { $service = $container->getDefinition($serviceName); $newService = $container->getDefinition($newServiceName); $container->removeDefinition($serviceName); $container->setDefinition($serviceName, $newService); }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $registry = $container->getDefinition('lug.resource.registry'); foreach (array_keys($container->findTaggedServiceIds('lug.resource')) as $resource) { $registry->addMethodCall('offsetSet', [$container->getDefinition($resource)->getArgument(0), new Reference($resource)]); } }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { foreach ($container->findTaggedServiceIds('vlr.model.violation.handler') as $id => $tags) { $priority = isset($tags[0]) && isset($tags[0]['priority']) ? $tags[0]['priority'] : null; $container->getDefinition('rezzza.violation.handler.manager')->addMethodCall('add', array($container->getDefinition($id), $priority)); } }
public function process(ContainerBuilder $container) { if (!$container->hasDefinition('security.expressions.compiler')) { return; } $compilerDef = $container->getDefinition('security.expressions.compiler'); foreach ($container->findTaggedServiceIds('security.expressions.function_compiler') as $id => $attr) { $compilerDef->addMethodCall('addFunctionCompiler', array(new Reference($id))); } foreach ($container->findTaggedServiceIds('security.expressions.type_compiler') as $id => $attr) { $compilerDef->addMethodCall('addTypeCompiler', array(new Reference($id))); } $serviceMap = $parameterMap = array(); foreach ($container->findTaggedServiceIds('security.expressions.variable') as $id => $attributes) { foreach ($attributes as $attr) { if (!isset($attr['variable']) || !isset($attr['service']) && !isset($attr['parameter'])) { throw new RuntimeException(sprintf('"variable", and either "service" or "parameter" must be given for tag "security.expressions.variable" for service id "%s".', $id)); } if (isset($attr['service'])) { $serviceMap[$attr['variable']] = $attr['service']; $container->findDefinition($attr['service'])->setPublic(true); } else { $parameterMap[$attr['variable']] = $attr['parameter']; } } } $container->getDefinition('security.expressions.variable_compiler')->addMethodCall('setMaps', array($serviceMap, $parameterMap)); }
/** * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container */ public function process(ContainerBuilder $container) { if (!$container->hasDefinition('innomatic.chain_router')) { return; } $chainRouter = $container->getDefinition('innomatic.chain_router'); // Enforce default router to be part of the routing chain // The default router will be given the highest priority so that it will be used by default if ($container->hasDefinition('router.default')) { $defaultRouter = $container->getDefinition('router.default'); if (!$defaultRouter->hasTag('router')) { $defaultRouter->addTag('router', array('priority' => 255)); } } foreach ($container->findTaggedServiceIds('router') as $id => $attributes) { $priority = isset($attributes[0]['priority']) ? (int) $attributes[0]['priority'] : 0; // Priority range is between -255 (the lowest) and 255 (the highest) if ($priority > 255) { $priority = 255; } if ($priority < -255) { $priority = -255; } $chainRouter->addMethodCall('add', array(new Reference($id), $priority)); } }
/** * {@inheritdoc} * * @throws InvalidConfigurationException */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); foreach ($config as $key => $value) { $container->setParameter($this->getAlias() . '.' . $key, $value); } $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); // Deprecated factory methods handling. // To be removed and set directly on config file when bumping Symfony requirements to >=2.6 $aliceFakerDefinition = $container->getDefinition('hautelook_alice.faker'); if (method_exists($aliceFakerDefinition, 'setFactory')) { $aliceFakerDefinition->setFactory(['Faker\\Factory', 'create']); } else { $aliceFakerDefinition->setFactoryClass('Faker\\Factory'); $aliceFakerDefinition->setFactoryMethod('create'); } foreach ($config['db_drivers'] as $driver => $isEnabled) { if (true === $isEnabled || null === $isEnabled && true === $this->isExtensionEnabled($driver)) { $loader->load(sprintf('%s.xml', $driver)); if ('orm' === $driver) { $this->setCommandFactory($container->getDefinition('hautelook_alice.doctrine.command.deprecated_load_command')); $this->setCommandFactory($container->getDefinition('hautelook_alice.doctrine.command.load_command')); } else { $this->setCommandFactory($container->getDefinition(sprintf('hautelook_alice.doctrine.%s.command.load_command', $driver))); } } } $container->getDefinition('hautelook_alice.alice.fixtures.loader')->replaceArgument(3, $container->getParameterBag()->all()); }