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


PHP ContainerBuilder::addClassResource方法代码示例

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


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

示例1: process

 public function process(ContainerBuilder $container)
 {
     $this->parameterBag = $parameterBag = $container->getParameterBag();
     try {
         $preferredServices = (array) $parameterBag->resolveValue("%autowiring.preferred_services%");
     } catch (ParameterNotFoundException $exception) {
         $preferredServices = [];
     }
     try {
         $fastAnnotationChecksRegex = "/" . implode("|", array_map(function ($s) {
             return preg_quote($s);
         }, (array) $parameterBag->resolveValue("%autowiring.fast_annotation_checks%"))) . "/";
     } catch (ParameterNotFoundException $exception) {
         $fastAnnotationChecksRegex = null;
     }
     foreach ($container->getDefinitions() as $serviceId => $definition) {
         if ($this->canDefinitionBeAutowired($serviceId, $definition) === false) {
             continue;
         }
         try {
             $className = $parameterBag->resolveValue($definition->getClass());
             $reflectionClass = new ReflectionClass($className);
             $this->autowireClass($className, $reflectionClass, $definition, $fastAnnotationChecksRegex, $preferredServices, $parameterBag);
             // add files to cache
             $container->addClassResource($reflectionClass);
         } catch (AutowiringException $exception) {
             throw new AutowiringException(sprintf("%s (service: %s)", $exception->getMessage(), $serviceId), $exception->getCode(), $exception);
         }
     }
 }
开发者ID:mzstic,项目名称:autowiring-bundle,代码行数:30,代码来源:AutowiringCompilerPass.php

示例2: testAddClassResource

 /**
  * @covers Symfony\Component\DependencyInjection\ContainerBuilder::addClassResource
  */
 public function testAddClassResource()
 {
     if (!class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
         $this->markTestSkipped('The "Config" component is not available');
     }
     $container = new ContainerBuilder();
     $container->setResourceTracking(false);
     $container->addClassResource(new \ReflectionClass('BarClass'));
     $this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');
     $container->setResourceTracking(true);
     $container->addClassResource(new \ReflectionClass('BarClass'));
     $resources = $container->getResources();
     $this->assertCount(1, $resources, '1 resource was registered');
     /* @var $resource \Symfony\Component\Config\Resource\FileResource */
     $resource = end($resources);
     $this->assertInstanceOf('Symfony\\Component\\Config\\Resource\\FileResource', $resource);
     $this->assertSame(realpath(__DIR__ . '/Fixtures/includes/classes.php'), realpath($resource->getResource()));
 }
开发者ID:tejdeeps,项目名称:tejcs.com,代码行数:21,代码来源:ContainerBuilderTest.php

示例3: loadPlugin

 /**
  * @param ContainerBuilder $container
  * @param BundlePlugin $plugin
  * @param array $processedConfiguration The fully processed configuration values for this bundle
  */
 private function loadPlugin(ContainerBuilder $container, BundlePlugin $plugin, array $processedConfiguration)
 {
     $container->addClassResource(new \ReflectionClass(get_class($plugin)));
     $pluginConfiguration = $this->pluginConfiguration($plugin, $processedConfiguration);
     $plugin->load($pluginConfiguration, $container);
 }
开发者ID:ad3n,项目名称:BundlePlugin,代码行数:11,代码来源:ExtensionWithPlugins.php

示例4: generate

 /**
  * @throws \LogicException
  */
 public function generate()
 {
     $pageflowAnnotation = $this->reader->getClassAnnotation($this->controllerClass, 'PHPMentors\\PageflowerBundle\\Annotation\\Pageflow');
     if ($pageflowAnnotation === null) {
         throw new \LogicException(sprintf('Annotation "%s" is not found in class "%s".', 'PHPMentors\\PageflowerBundle\\Annotation\\Pageflow', $this->controllerClass->getName()));
     }
     $pageflowBuilderDefinition = new DefinitionDecorator('phpmentors_pageflower.pageflow_builder');
     $pageflowBuilderDefinition->setArguments(array($this->controllerServiceId));
     $statesFound = false;
     $transitionsFound = false;
     foreach ($pageflowAnnotation->value as $annotation) {
         if ($annotation instanceof States) {
             if ($statesFound) {
                 throw new \LogicException(sprintf('Annotation "%s" must be specified only once.', get_class($annotation)));
             }
             $statesFound = true;
             foreach ($annotation->value as $state) {
                 if ($state instanceof AnnotationInterface) {
                     if ($state->value === null || strlen($state->value) == 0) {
                         throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($state)));
                     }
                     if ($state instanceof Start) {
                         $pageflowBuilderDefinition->addMethodCall('addState', array($state->value));
                         $pageflowBuilderDefinition->addMethodCall('setStartState', array($state->value));
                         $this->states[] = $state->value;
                     } elseif ($state instanceof End) {
                         $pageflowBuilderDefinition->addMethodCall('addState', array($state->value));
                         $pageflowBuilderDefinition->addMethodCall('setEndState', array($state->value, StateInterface::STATE_FINAL));
                         $this->states[] = $state->value;
                     } else {
                         throw new \LogicException(sprintf('State "%s" must be encapsulated with one of [ %s ], "%s" is specified.', $state->value, implode(', ', array('PHPMentors\\PageflowerBundle\\Annotation\\Start', 'PHPMentors\\PageflowerBundle\\Annotation\\End')), get_class($state)));
                     }
                 } else {
                     if ($state === null || strlen($state) == 0) {
                         throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
                     }
                     $pageflowBuilderDefinition->addMethodCall('addState', array($state));
                     $this->states[] = $state;
                 }
             }
         } elseif ($annotation instanceof Transitions) {
             if ($transitionsFound) {
                 throw new \LogicException(sprintf('Annotation "%s" must be specified only once.', get_class($annotation)));
             }
             $transitionsFound = true;
             foreach ($annotation->value as $transition) {
                 if (is_array($transition) && count($transition) == 2 && is_string($transition[0]) && is_string($transition[1])) {
                     foreach (array($transition[0], $transition[1]) as $state) {
                         if ($state === null || strlen($state) == 0) {
                             throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
                         }
                         if (!in_array($state, $this->states)) {
                             throw new \LogicException(sprintf('The value for annotation "%s" must be one of [ %s ], "%s" is specified.', get_class($annotation), implode(', ', $this->states), $state));
                         }
                     }
                     $pageflowBuilderDefinition->addMethodCall('addTransition', array($transition[0], $transition[1], $transition[1]));
                 } else {
                     throw new \LogicException(sprintf('The value for annotation "%s" must be string array, "%s" is specified.', get_class($annotation), var_export($transition, true)));
                 }
             }
         } else {
             throw new \LogicException(sprintf('The value for annotation "%s" must be one of [ %s ], "%s" is specified.', get_class($pageflowAnnotation), implode(', ', array('"PHPMentors\\PageflowerBundle\\Annotation\\States"', '"PHPMentors\\PageflowerBundle\\Annotation\\Transitions"')), is_object($annotation) ? get_class($annotation) : $annotation));
         }
     }
     $pageflowBuilderServiceId = 'phpmentors_pageflower.pageflow_builder.' . $this->controllerServiceId;
     $this->container->setDefinition($pageflowBuilderServiceId, $pageflowBuilderDefinition);
     $pageflowDefinition = new DefinitionDecorator('phpmentors_pageflower.pageflow');
     $pageflowDefinition->setFactoryService($pageflowBuilderServiceId);
     $pageflowServiceId = 'phpmentors_pageflower.pageflow.' . $this->controllerServiceId;
     $this->container->setDefinition($pageflowServiceId, $pageflowDefinition);
     $this->container->getDefinition('phpmentors_pageflower.pageflow_repository')->addMethodCall('add', array(new Reference($pageflowServiceId)));
     $this->container->addClassResource($this->controllerClass);
 }
开发者ID:iteman,项目名称:pageflower-bundle,代码行数:76,代码来源:PageflowDefinitionGenerator.php


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