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


PHP Definition::setDecoratedService方法代码示例

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


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

示例1: testSetGetDecoratedService

    public function testSetGetDecoratedService()
    {
        $def = new Definition('stdClass');
        $this->assertNull($def->getDecoratedService());
        $def->setDecoratedService('foo', 'foo.renamed', 5);
        $this->assertEquals(array('foo', 'foo.renamed', 5), $def->getDecoratedService());
        $def->setDecoratedService(null);
        $this->assertNull($def->getDecoratedService());

        $def = new Definition('stdClass');
        $this->assertNull($def->getDecoratedService());
        $def->setDecoratedService('foo', 'foo.renamed');
        $this->assertEquals(array('foo', 'foo.renamed', 0), $def->getDecoratedService());
        $def->setDecoratedService(null);
        $this->assertNull($def->getDecoratedService());

        $def = new Definition('stdClass');
        $def->setDecoratedService('foo');
        $this->assertEquals(array('foo', null, 0), $def->getDecoratedService());
        $def->setDecoratedService(null);
        $this->assertNull($def->getDecoratedService());

        $def = new Definition('stdClass');
        $this->setExpectedException('InvalidArgumentException', 'The decorated service inner name for "foo" must be different than the service name itself.');
        $def->setDecoratedService('foo', 'foo');
    }
开发者ID:symfony,项目名称:symfony,代码行数:26,代码来源:DefinitionTest.php

示例2: decoratesRabbitMqTracerConsumer

 /**
  * @param ContainerBuilder $container
  * @param string $id
  */
 private function decoratesRabbitMqTracerConsumer(ContainerBuilder $container, $id)
 {
     $decoratorId = $id . '.tolerance_decorator';
     $decoratorDefinition = new Definition(TracedConsumer::class, [new Reference($decoratorId . '.inner'), new Reference('tolerance.tracer'), new Reference('tolerance.tracer.stack_stack'), new Reference('tolerance.tracer.span_factory.amqp')]);
     $decoratorDefinition->setDecoratedService($id);
     $container->setDefinition($decoratorId, $decoratorDefinition);
 }
开发者ID:sroze,项目名称:tolerance,代码行数:11,代码来源:RabbitMqCompilerPass.php

示例3: parseDefinition

 /**
  * Parses an individual Definition.
  *
  * @param \DOMElement $service
  * @param string      $file
  *
  * @return Definition|null
  */
 private function parseDefinition(\DOMElement $service, $file)
 {
     if ($alias = $service->getAttribute('alias')) {
         $public = true;
         if ($publicAttr = $service->getAttribute('public')) {
             $public = XmlUtils::phpize($publicAttr);
         }
         $this->container->setAlias((string) $service->getAttribute('id'), new Alias($alias, $public));
         return;
     }
     if ($parent = $service->getAttribute('parent')) {
         $definition = new DefinitionDecorator($parent);
     } else {
         $definition = new Definition();
     }
     foreach (array('class', 'shared', 'public', 'synthetic', 'lazy', 'abstract') as $key) {
         if ($value = $service->getAttribute($key)) {
             $method = 'set' . str_replace('-', '', $key);
             $definition->{$method}(XmlUtils::phpize($value));
         }
     }
     if ($value = $service->getAttribute('autowire')) {
         $definition->setAutowired(XmlUtils::phpize($value));
     }
     if ($files = $this->getChildren($service, 'file')) {
         $definition->setFile($files[0]->nodeValue);
     }
     if ($deprecated = $this->getChildren($service, 'deprecated')) {
         $definition->setDeprecated(true, $deprecated[0]->nodeValue);
     }
     $definition->setArguments($this->getArgumentsAsPhp($service, 'argument'));
     $definition->setProperties($this->getArgumentsAsPhp($service, 'property'));
     if ($factories = $this->getChildren($service, 'factory')) {
         $factory = $factories[0];
         if ($function = $factory->getAttribute('function')) {
             $definition->setFactory($function);
         } else {
             $factoryService = $this->getChildren($factory, 'service');
             if (isset($factoryService[0])) {
                 $class = $this->parseDefinition($factoryService[0], $file);
             } elseif ($childService = $factory->getAttribute('service')) {
                 $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = $factory->getAttribute('class');
             }
             $definition->setFactory(array($class, $factory->getAttribute('method')));
         }
     }
     if ($configurators = $this->getChildren($service, 'configurator')) {
         $configurator = $configurators[0];
         if ($function = $configurator->getAttribute('function')) {
             $definition->setConfigurator($function);
         } else {
             $configuratorService = $this->getChildren($configurator, 'service');
             if (isset($configuratorService[0])) {
                 $class = $this->parseDefinition($configuratorService[0], $file);
             } elseif ($childService = $configurator->getAttribute('service')) {
                 $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = $configurator->getAttribute('class');
             }
             $definition->setConfigurator(array($class, $configurator->getAttribute('method')));
         }
     }
     foreach ($this->getChildren($service, 'call') as $call) {
         $definition->addMethodCall($call->getAttribute('method'), $this->getArgumentsAsPhp($call, 'argument'));
     }
     foreach ($this->getChildren($service, 'tag') as $tag) {
         $parameters = array();
         foreach ($tag->attributes as $name => $node) {
             if ('name' === $name) {
                 continue;
             }
             if (false !== strpos($name, '-') && false === strpos($name, '_') && !array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) {
                 $parameters[$normalizedName] = XmlUtils::phpize($node->nodeValue);
             }
             // keep not normalized key
             $parameters[$name] = XmlUtils::phpize($node->nodeValue);
         }
         $definition->addTag($tag->getAttribute('name'), $parameters);
     }
     foreach ($this->getChildren($service, 'autowiring-type') as $type) {
         $definition->addAutowiringType($type->textContent);
     }
     if ($value = $service->getAttribute('decorates')) {
         $renameId = $service->hasAttribute('decoration-inner-name') ? $service->getAttribute('decoration-inner-name') : null;
         $priority = $service->hasAttribute('decoration-priority') ? $service->getAttribute('decoration-priority') : 0;
         $definition->setDecoratedService($value, $renameId, $priority);
     }
     return $definition;
 }
开发者ID:ABaldwinHunter,项目名称:symfony-clone,代码行数:99,代码来源:XmlFileLoader.php

示例4: resolveDefinition

 /**
  * Resolves the definition.
  *
  * @param ContainerBuilder    $container  The ContainerBuilder
  * @param DefinitionDecorator $definition
  *
  * @return Definition
  *
  * @throws \RuntimeException When the definition is invalid
  */
 private function resolveDefinition(ContainerBuilder $container, DefinitionDecorator $definition)
 {
     if (!$container->hasDefinition($parent = $definition->getParent())) {
         throw new RuntimeException(sprintf('The parent definition "%s" defined for definition "%s" does not exist.', $parent, $this->currentId));
     }
     $parentDef = $container->getDefinition($parent);
     if ($parentDef instanceof DefinitionDecorator) {
         $id = $this->currentId;
         $this->currentId = $parent;
         $parentDef = $this->resolveDefinition($container, $parentDef);
         $container->setDefinition($parent, $parentDef);
         $this->currentId = $id;
     }
     $this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $this->currentId, $parent));
     $def = new Definition();
     // merge in parent definition
     // purposely ignored attributes: scope, abstract, tags
     $def->setClass($parentDef->getClass());
     $def->setArguments($parentDef->getArguments());
     $def->setMethodCalls($parentDef->getMethodCalls());
     $def->setProperties($parentDef->getProperties());
     $def->setAutowiringTypes($parentDef->getAutowiringTypes());
     if ($parentDef->getFactoryClass(false)) {
         $def->setFactoryClass($parentDef->getFactoryClass(false));
     }
     if ($parentDef->getFactoryMethod(false)) {
         $def->setFactoryMethod($parentDef->getFactoryMethod(false));
     }
     if ($parentDef->getFactoryService(false)) {
         $def->setFactoryService($parentDef->getFactoryService(false));
     }
     if ($parentDef->isDeprecated()) {
         $def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
     }
     $def->setFactory($parentDef->getFactory());
     $def->setConfigurator($parentDef->getConfigurator());
     $def->setFile($parentDef->getFile());
     $def->setPublic($parentDef->isPublic());
     $def->setLazy($parentDef->isLazy());
     // overwrite with values specified in the decorator
     $changes = $definition->getChanges();
     if (isset($changes['class'])) {
         $def->setClass($definition->getClass());
     }
     if (isset($changes['factory_class'])) {
         $def->setFactoryClass($definition->getFactoryClass(false));
     }
     if (isset($changes['factory_method'])) {
         $def->setFactoryMethod($definition->getFactoryMethod(false));
     }
     if (isset($changes['factory_service'])) {
         $def->setFactoryService($definition->getFactoryService(false));
     }
     if (isset($changes['factory'])) {
         $def->setFactory($definition->getFactory());
     }
     if (isset($changes['configurator'])) {
         $def->setConfigurator($definition->getConfigurator());
     }
     if (isset($changes['file'])) {
         $def->setFile($definition->getFile());
     }
     if (isset($changes['public'])) {
         $def->setPublic($definition->isPublic());
     }
     if (isset($changes['lazy'])) {
         $def->setLazy($definition->isLazy());
     }
     if (isset($changes['deprecated'])) {
         $def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
     }
     if (isset($changes['decorated_service'])) {
         $decoratedService = $definition->getDecoratedService();
         if (null === $decoratedService) {
             $def->setDecoratedService($decoratedService);
         } else {
             $def->setDecoratedService($decoratedService[0], $decoratedService[1], $decoratedService[2]);
         }
     }
     // merge arguments
     foreach ($definition->getArguments() as $k => $v) {
         if (is_numeric($k)) {
             $def->addArgument($v);
             continue;
         }
         if (0 !== strpos($k, 'index_')) {
             throw new RuntimeException(sprintf('Invalid argument key "%s" found.', $k));
         }
         $index = (int) substr($k, strlen('index_'));
         $def->replaceArgument($index, $v);
//.........这里部分代码省略.........
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:101,代码来源:ResolveDefinitionTemplatesPass.php

示例5: parseDefinition


//.........这里部分代码省略.........
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator($service['parent']);
     } else {
         $definition = new Definition();
     }
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['scope'])) {
         $definition->setScope($service['scope']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['synchronized'])) {
         $definition->setSynchronized($service['synchronized']);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (isset($service['factory'])) {
         if (is_string($service['factory'])) {
             if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
                 $parts = explode(':', $service['factory']);
                 $definition->setFactory(array($this->resolveServices('@' . $parts[0]), $parts[1]));
             } else {
                 $definition->setFactory($service['factory']);
             }
         } else {
             $definition->setFactory(array($this->resolveServices($service['factory'][0]), $service['factory'][1]));
         }
     }
     if (isset($service['factory_class'])) {
         $definition->setFactoryClass($service['factory_class']);
     }
     if (isset($service['factory_method'])) {
         $definition->setFactoryMethod($service['factory_method']);
     }
     if (isset($service['factory_service'])) {
         $definition->setFactoryService($service['factory_service']);
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     if (isset($service['configurator'])) {
         if (is_string($service['configurator'])) {
             $definition->setConfigurator($service['configurator']);
         } else {
             $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
         }
     }
     if (isset($service['calls'])) {
         if (!is_array($service['calls'])) {
             throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['calls'] as $call) {
             $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             $definition->addMethodCall($call[0], $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['tags'] as $tag) {
             if (!is_array($tag)) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
             }
             if (!isset($tag['name'])) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file));
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     if (isset($service['decorates'])) {
         $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
         $definition->setDecoratedService($service['decorates'], $renameId);
     }
     $this->container->setDefinition($id, $definition);
 }
开发者ID:tahermarkos,项目名称:Transport,代码行数:101,代码来源:YamlFileLoader.php

示例6: parseDefinition

 /**
  * Parses an individual Definition.
  *
  * @param \DOMElement $service
  * @param string      $file
  *
  * @return Definition|null
  */
 private function parseDefinition(\DOMElement $service, $file)
 {
     if ($alias = $service->getAttribute('alias')) {
         $public = true;
         if ($publicAttr = $service->getAttribute('public')) {
             $public = XmlUtils::phpize($publicAttr);
         }
         $this->container->setAlias((string) $service->getAttribute('id'), new Alias($alias, $public));
         return;
     }
     if ($parent = $service->getAttribute('parent')) {
         $definition = new DefinitionDecorator($parent);
     } else {
         $definition = new Definition();
     }
     foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'lazy', 'abstract') as $key) {
         if ($value = $service->getAttribute($key)) {
             if (in_array($key, array('factory-class', 'factory-method', 'factory-service'))) {
                 @trigger_error(sprintf('The "%s" attribute of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use the "factory" element instead.', $key, (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED);
             }
             $method = 'set' . str_replace('-', '', $key);
             $definition->{$method}(XmlUtils::phpize($value));
         }
     }
     if ($value = $service->getAttribute('synchronized')) {
         $triggerDeprecation = 'request' !== (string) $service->getAttribute('id');
         if ($triggerDeprecation) {
             @trigger_error(sprintf('The "synchronized" attribute of service "%s" in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED);
         }
         $definition->setSynchronized(XmlUtils::phpize($value), $triggerDeprecation);
     }
     if ($files = $this->getChildren($service, 'file')) {
         $definition->setFile($files[0]->nodeValue);
     }
     $definition->setArguments($this->getArgumentsAsPhp($service, 'argument'));
     $definition->setProperties($this->getArgumentsAsPhp($service, 'property'));
     if ($factories = $this->getChildren($service, 'factory')) {
         $factory = $factories[0];
         if ($function = $factory->getAttribute('function')) {
             $definition->setFactory($function);
         } else {
             $factoryService = $this->getChildren($factory, 'service');
             if (isset($factoryService[0])) {
                 $class = $this->parseDefinition($factoryService[0], $file);
             } elseif ($childService = $factory->getAttribute('service')) {
                 $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = $factory->getAttribute('class');
             }
             $definition->setFactory(array($class, $factory->getAttribute('method')));
         }
     }
     if ($configurators = $this->getChildren($service, 'configurator')) {
         $configurator = $configurators[0];
         if ($function = $configurator->getAttribute('function')) {
             $definition->setConfigurator($function);
         } else {
             $configuratorService = $this->getChildren($configurator, 'service');
             if (isset($configuratorService[0])) {
                 $class = $this->parseDefinition($configuratorService[0], $file);
             } elseif ($childService = $configurator->getAttribute('service')) {
                 $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = $configurator->getAttribute('class');
             }
             $definition->setConfigurator(array($class, $configurator->getAttribute('method')));
         }
     }
     foreach ($this->getChildren($service, 'call') as $call) {
         $definition->addMethodCall($call->getAttribute('method'), $this->getArgumentsAsPhp($call, 'argument'));
     }
     foreach ($this->getChildren($service, 'tag') as $tag) {
         $parameters = array();
         foreach ($tag->attributes as $name => $node) {
             if ('name' === $name) {
                 continue;
             }
             if (false !== strpos($name, '-') && false === strpos($name, '_') && !array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) {
                 $parameters[$normalizedName] = XmlUtils::phpize($node->nodeValue);
             }
             // keep not normalized key for BC too
             $parameters[$name] = XmlUtils::phpize($node->nodeValue);
         }
         if ('' === $tag->getAttribute('name')) {
             throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', (string) $service->getAttribute('id'), $file));
         }
         $definition->addTag($tag->getAttribute('name'), $parameters);
     }
     if ($value = $service->getAttribute('decorates')) {
         $renameId = $service->hasAttribute('decoration-inner-name') ? $service->getAttribute('decoration-inner-name') : null;
         $definition->setDecoratedService($value, $renameId);
     }
//.........这里部分代码省略.........
开发者ID:raphydev,项目名称:onep,代码行数:101,代码来源:XmlFileLoader.php

示例7: setDecoratedService

 /**
  * {@inheritdoc}
  */
 public function setDecoratedService($id, $renamedId = null, $priority = 0)
 {
     $this->changes['decorated_service'] = true;
     return parent::setDecoratedService($id, $renamedId, $priority);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:8,代码来源:DefinitionDecorator.php

示例8: registerSerializerConfiguration

 /**
  * Loads the serializer configuration.
  *
  * @param array            $config    A serializer configuration array
  * @param ContainerBuilder $container A ContainerBuilder instance
  * @param XmlFileLoader    $loader    An XmlFileLoader instance
  */
 private function registerSerializerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
 {
     if (class_exists('Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer')) {
         // Run after serializer.normalizer.object
         $definition = $container->register('serializer.normalizer.data_uri', DataUriNormalizer::class);
         $definition->setPublic(false);
         $definition->addTag('serializer.normalizer', array('priority' => -920));
     }
     if (class_exists('Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer')) {
         // Run before serializer.normalizer.object
         $definition = $container->register('serializer.normalizer.datetime', DateTimeNormalizer::class);
         $definition->setPublic(false);
         $definition->addTag('serializer.normalizer', array('priority' => -910));
     }
     if (class_exists('Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer')) {
         // Run before serializer.normalizer.object
         $definition = $container->register('serializer.normalizer.json_serializable', JsonSerializableNormalizer::class);
         $definition->setPublic(false);
         $definition->addTag('serializer.normalizer', array('priority' => -900));
     }
     $loader->load('serializer.xml');
     $chainLoader = $container->getDefinition('serializer.mapping.chain_loader');
     $serializerLoaders = array();
     if (isset($config['enable_annotations']) && $config['enable_annotations']) {
         $annotationLoader = new Definition('Symfony\\Component\\Serializer\\Mapping\\Loader\\AnnotationLoader', array(new Reference('annotation_reader')));
         $annotationLoader->setPublic(false);
         $serializerLoaders[] = $annotationLoader;
     }
     $bundles = $container->getParameter('kernel.bundles');
     foreach ($bundles as $bundle) {
         $reflection = new \ReflectionClass($bundle);
         $dirname = dirname($reflection->getFileName());
         if (is_file($file = $dirname . '/Resources/config/serialization.xml')) {
             $definition = new Definition('Symfony\\Component\\Serializer\\Mapping\\Loader\\XmlFileLoader', array(realpath($file)));
             $definition->setPublic(false);
             $serializerLoaders[] = $definition;
             $container->addResource(new FileResource($file));
         }
         if (is_file($file = $dirname . '/Resources/config/serialization.yml')) {
             $definition = new Definition('Symfony\\Component\\Serializer\\Mapping\\Loader\\YamlFileLoader', array(realpath($file)));
             $definition->setPublic(false);
             $serializerLoaders[] = $definition;
             $container->addResource(new FileResource($file));
         }
         if (is_dir($dir = $dirname . '/Resources/config/serialization')) {
             foreach (Finder::create()->files()->in($dir)->name('*.xml') as $file) {
                 $definition = new Definition('Symfony\\Component\\Serializer\\Mapping\\Loader\\XmlFileLoader', array($file->getRealPath()));
                 $definition->setPublic(false);
                 $serializerLoaders[] = $definition;
             }
             foreach (Finder::create()->files()->in($dir)->name('*.yml') as $file) {
                 $definition = new Definition('Symfony\\Component\\Serializer\\Mapping\\Loader\\YamlFileLoader', array($file->getRealPath()));
                 $definition->setPublic(false);
                 $serializerLoaders[] = $definition;
             }
             $container->addResource(new DirectoryResource($dir));
         }
     }
     $chainLoader->replaceArgument(0, $serializerLoaders);
     if (isset($config['cache']) && $config['cache']) {
         @trigger_error('The "framework.serializer.cache" option is deprecated since Symfony 3.1 and will be removed in 4.0. Configure the "cache.serializer" service under "framework.cache.pools" instead.', E_USER_DEPRECATED);
         $container->setParameter('serializer.mapping.cache.prefix', 'serializer_' . $this->getKernelRootHash($container));
         $container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument(1, new Reference($config['cache']));
     } elseif (!$container->getParameter('kernel.debug')) {
         $cacheMetadataFactory = new Definition(CacheClassMetadataFactory::class, array(new Reference('serializer.mapping.cache_class_metadata_factory.inner'), new Reference('cache.serializer')));
         $cacheMetadataFactory->setPublic(false);
         $cacheMetadataFactory->setDecoratedService('serializer.mapping.class_metadata_factory');
         $container->setDefinition('serializer.mapping.cache_class_metadata_factory', $cacheMetadataFactory);
     }
     if (isset($config['name_converter']) && $config['name_converter']) {
         $container->getDefinition('serializer.normalizer.object')->replaceArgument(1, new Reference($config['name_converter']));
     }
 }
开发者ID:joelwurtz,项目名称:symfony,代码行数:80,代码来源:FrameworkExtension.php

示例9: parseDefinition


//.........这里部分代码省略.........
     if (isset($service['shared'])) {
         $definition->setShared($service['shared']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (array_key_exists('deprecated', $service)) {
         $definition->setDeprecated(true, $service['deprecated']);
     }
     if (isset($service['factory'])) {
         $definition->setFactory($this->parseCallable($service['factory'], 'factory', $id, $file));
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     if (isset($service['configurator'])) {
         $definition->setConfigurator($this->parseCallable($service['configurator'], 'configurator', $id, $file));
     }
     if (isset($service['calls'])) {
         if (!is_array($service['calls'])) {
             throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['calls'] as $call) {
             if (isset($call['method'])) {
                 $method = $call['method'];
                 $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
             } else {
                 $method = $call[0];
                 $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             }
             $definition->addMethodCall($method, $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['tags'] as $tag) {
             if (!is_array($tag)) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
             }
             if (!isset($tag['name'])) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
             }
             if (!is_string($tag['name']) || '' === $tag['name']) {
                 throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file));
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     if (isset($service['decorates'])) {
         if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
             throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['decorates'], substr($service['decorates'], 1)));
         }
         $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
         $priority = isset($service['decoration_priority']) ? $service['decoration_priority'] : 0;
         $definition->setDecoratedService($service['decorates'], $renameId, $priority);
     }
     if (isset($service['autowire'])) {
         $definition->setAutowired($service['autowire']);
     }
     if (isset($service['autowiring_types'])) {
         if (is_string($service['autowiring_types'])) {
             $definition->addAutowiringType($service['autowiring_types']);
         } else {
             if (!is_array($service['autowiring_types'])) {
                 throw new InvalidArgumentException(sprintf('Parameter "autowiring_types" must be a string or an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
             }
             foreach ($service['autowiring_types'] as $autowiringType) {
                 if (!is_string($autowiringType)) {
                     throw new InvalidArgumentException(sprintf('A "autowiring_types" attribute must be of type string for service "%s" in %s. Check your YAML syntax.', $id, $file));
                 }
                 $definition->addAutowiringType($autowiringType);
             }
         }
     }
     $this->container->setDefinition($id, $definition);
 }
开发者ID:ayoah,项目名称:symfony,代码行数:101,代码来源:YamlFileLoader.php

示例10: parseDefinition


//.........这里部分代码省略.........
         @trigger_error(sprintf('The "synchronized" key of service "%s" in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $id, $file), E_USER_DEPRECATED);
         $definition->setSynchronized($service['synchronized'], 'request' !== $id);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (isset($service['factory'])) {
         if (is_string($service['factory'])) {
             if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
                 $parts = explode(':', $service['factory']);
                 $definition->setFactory(array($this->resolveServices('@' . $parts[0]), $parts[1]));
             } else {
                 $definition->setFactory($service['factory']);
             }
         } else {
             $definition->setFactory(array($this->resolveServices($service['factory'][0]), $service['factory'][1]));
         }
     }
     if (isset($service['factory_class'])) {
         @trigger_error(sprintf('The "factory_class" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
         $definition->setFactoryClass($service['factory_class']);
     }
     if (isset($service['factory_method'])) {
         @trigger_error(sprintf('The "factory_method" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
         $definition->setFactoryMethod($service['factory_method']);
     }
     if (isset($service['factory_service'])) {
         @trigger_error(sprintf('The "factory_service" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
         $definition->setFactoryService($service['factory_service']);
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     if (isset($service['configurator'])) {
         if (is_string($service['configurator'])) {
             $definition->setConfigurator($service['configurator']);
         } else {
             $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
         }
     }
     if (isset($service['calls'])) {
         if (!is_array($service['calls'])) {
             throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['calls'] as $call) {
             if (isset($call['method'])) {
                 $method = $call['method'];
                 $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
             } else {
                 $method = $call[0];
                 $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             }
             $definition->addMethodCall($method, $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['tags'] as $tag) {
             if (!is_array($tag)) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
             }
             if (!isset($tag['name'])) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
             }
             if (!is_string($tag['name']) || '' === $tag['name']) {
                 throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file));
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     if (isset($service['decorates'])) {
         if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
             throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['decorates'], substr($service['decorates'], 1)));
         }
         $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
         $definition->setDecoratedService($service['decorates'], $renameId);
     }
     $this->container->setDefinition($id, $definition);
 }
开发者ID:raphydev,项目名称:onep,代码行数:101,代码来源:YamlFileLoader.php

示例11: testGetServiceDefinitionForDecoratedService

 /**
  * Tests that getDecoratedService() is unsupported.
  *
  * Tests that the correct InvalidArgumentException is thrown for
  * getDecoratedService().
  *
  * @covers ::getServiceDefinition
  *
  * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
  */
 public function testGetServiceDefinitionForDecoratedService()
 {
     $bar_definition = new Definition('\\stdClass');
     $bar_definition->setDecoratedService(new Reference('foo'));
     $services['bar'] = $bar_definition;
     $this->containerBuilder->getDefinitions()->willReturn($services);
     $this->dumper->getArray();
 }
开发者ID:318io,项目名称:318-io,代码行数:18,代码来源:OptimizedPhpArrayDumperTest.php

示例12: setDecoratedService

 /**
  * Sets the service that this service is decorating.
  *
  * @param null|string $id The decorated service id, use null to remove decoration
  * @param null|string $renamedId The new decorated service id
  *
  * @return tubepress_api_ioc_DefinitionInterface The current instance
  *
  * @throws InvalidArgumentException In case the decorated service id and the new decorated service id are equals.
  *
  * @api
  * @since 4.0.0
  */
 public function setDecoratedService($id, $renamedId = null)
 {
     $this->_underlyingSymfonyDefinition->setDecoratedService($id, $renamedId);
     return $this;
 }
开发者ID:tubepress,项目名称:tubepress,代码行数:18,代码来源:Definition.php

示例13: parseDefinition


//.........这里部分代码省略.........
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (array_key_exists('deprecated', $service)) {
         $definition->setDeprecated(true, $service['deprecated']);
     }
     if (isset($service['factory'])) {
         $definition->setFactory($this->parseCallable($service['factory'], 'factory', $id, $file));
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     if (isset($service['configurator'])) {
         $definition->setConfigurator($this->parseCallable($service['configurator'], 'configurator', $id, $file));
     }
     if (isset($service['calls'])) {
         if (!is_array($service['calls'])) {
             $message = sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your JSON syntax', $id, $file);
             throw new InvalidArgumentException($message);
         }
         foreach ($service['calls'] as $call) {
             if (isset($call['method'])) {
                 $method = $call['method'];
                 $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
             } else {
                 $method = $call[0];
                 $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             }
             $definition->addMethodCall($method, $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             $message = sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your JSON syntax', $id, $file);
             throw new InvalidArgumentException($message);
         }
         foreach ($service['tags'] as $tag) {
             if (!is_array($tag)) {
                 $message = sprintf('A "tags" entry must be an array for service "%s" in %s. Check your JSON syntax', $id, $file);
                 throw new InvalidArgumentException($message);
             }
             if (!isset($tag['name'])) {
                 $message = sprintf('A "tags" entry is missing a "name" key for service "%s" in %s', $id, $file);
                 throw new InvalidArgumentException($message);
             }
             if (!is_string($tag['name']) || '' === $tag['name']) {
                 $message = sprintf('The tag name for service "%s" in %s must be a non-empty string', $id, $file);
                 throw new InvalidArgumentException($message);
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     $message = sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", ' . 'attribute "%s" in %s. Check your JSON syntax', $id, $name, $attribute, $file);
                     throw new InvalidArgumentException($message);
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     if (isset($service['decorates'])) {
         if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
             $message = sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without ' . 'the "@" prefix (replace "%s" with "%s")', $id, $service['decorates'], substr($service['decorates'], 1));
             throw new InvalidArgumentException($message);
         }
         $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
         $priority = isset($service['decoration_priority']) ? $service['decoration_priority'] : 0;
         $definition->setDecoratedService($service['decorates'], $renameId, $priority);
     }
     if (isset($service['autowire'])) {
         $definition->setAutowired($service['autowire']);
     }
     if (isset($service['autowiring_types'])) {
         if (is_string($service['autowiring_types'])) {
             $definition->addAutowiringType($service['autowiring_types']);
         } else {
             if (!is_array($service['autowiring_types'])) {
                 $message = sprintf('Parameter "autowiring_types" must be a string or an array for service "%s" in %s. ' . 'Check your JSON syntax', $id, $file);
                 throw new InvalidArgumentException($message);
             }
             foreach ($service['autowiring_types'] as $autowiringType) {
                 if (!is_string($autowiringType)) {
                     $message = sprintf('A "autowiring_types" attribute must be of type string for service "%s" in %s. ' . 'Check your JSON syntax', $id, $file);
                     throw new InvalidArgumentException($message);
                 }
                 $definition->addAutowiringType($autowiringType);
             }
         }
     }
     $this->container->setDefinition($id, $definition);
 }
开发者ID:novuso,项目名称:common-bundle,代码行数:101,代码来源:JsonFileLoader.php


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