本文整理汇总了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);
}
}
}
示例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()));
}
示例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);
}
示例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);
}