当前位置: 首页>>代码示例>>PHP>>正文


PHP ContainerBuilder::getDefinition方法代码示例

本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::getDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::getDefinition方法的具体用法?PHP ContainerBuilder::getDefinition怎么用?PHP ContainerBuilder::getDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DependencyInjection\ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder::getDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 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);
 }
开发者ID:nakashu,项目名称:symfony,代码行数:32,代码来源:FormPass.php

示例2: process

 /**
  * {@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)));
         }
     }
 }
开发者ID:robhunt3r,项目名称:SonataAdminBundle,代码行数:37,代码来源:ExtensionCompilerPass.php

示例3: process

 /**
  * {@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);
 }
开发者ID:LamaDelRay,项目名称:test_symf,代码行数:29,代码来源:FormFactoryCompilerPass.php

示例4: load

 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');
     }
 }
开发者ID:natxet,项目名称:JMSI18nRoutingBundle,代码行数:25,代码来源:JMSI18nRoutingExtension.php

示例5: process

 /**
  * {@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%"));
 }
开发者ID:Alltricks,项目名称:multisite-bundle,代码行数:10,代码来源:InjectSiteContextPass.php

示例6: process

 /**
  * @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));
         }
     }
 }
开发者ID:ojezu,项目名称:add-call-to-remote-service-bundle,代码行数:30,代码来源:AddCallToRemoteServiceCompilerPass.php

示例7: load

 /**
  * {@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');
 }
开发者ID:agentsib,项目名称:crontab-bundle,代码行数:33,代码来源:AgentSIBCrontabExtension.php

示例8: process

 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'));
         }
     }
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:33,代码来源:NotificationCompilerPass.php

示例9: load

 /**
  * {@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');
     }
 }
开发者ID:mmoreram,项目名称:rsqueue-bundle,代码行数:29,代码来源:RSQueueExtension.php

示例10: process

 /**
  * {@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)));
     }
 }
开发者ID:kmoussouni,项目名称:RulerBundle,代码行数:38,代码来源:BuilderCompilerPass.php

示例11: process

 /**
  * {@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));
         }
     }
 }
开发者ID:Gtvar,项目名称:FivePercent-IntegrationBundle,代码行数:33,代码来源:AddVarTagConstraintFactoryPass.php

示例12: process

 /**
  * @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));
     }
 }
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:34,代码来源:ChainRoutingPass.php

示例13: process

 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));
     }
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:26,代码来源:AddTemplatingRenderersPass.php

示例14: process

 /**
  * {@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']]);
     }
 }
开发者ID:nicolasdewez,项目名称:webhome-common,代码行数:31,代码来源:MenuCompilerPass.php

示例15: process

 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));
     }
 }
开发者ID:acappel01,项目名称:opencall,代码行数:32,代码来源:RegisterListenersPass.php


注:本文中的Symfony\Component\DependencyInjection\ContainerBuilder::getDefinition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。