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


PHP Definition::replaceArgument方法代码示例

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


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

示例1: replaceArgument

 /**
  * Sets a specific argument
  *
  * @param integer $index
  * @param mixed   $argument
  *
  * @return tubepress_api_ioc_DefinitionInterface The current instance
  *
  * @throws OutOfBoundsException When the replaced argument does not exist
  *
  * @api
  * @since 4.0.0
  */
 public function replaceArgument($index, $argument)
 {
     $cleaned = $this->convertToSymfonyReferenceIfNecessary($argument);
     try {
         $this->_underlyingSymfonyDefinition->replaceArgument($index, $cleaned);
     } catch (\Symfony\Component\DependencyInjection\Exception\OutOfBoundsException $e) {
         throw new OutOfBoundsException($e);
     }
     return $this;
 }
开发者ID:tubepress,项目名称:tubepress,代码行数:23,代码来源:Definition.php

示例2: replaceArgument

 /**
  * @param ContainerBuilder $container
  * @param Definition       $definition
  * @param string           $tag
  * @param int              $argumentIndex
  */
 public function replaceArgument(ContainerBuilder $container, Definition $definition, $tag, $argumentIndex)
 {
     $transports = $definition->getArgument($argumentIndex);
     $taggedServices = $container->findTaggedServiceIds($tag);
     foreach ($taggedServices as $id => $attributes) {
         $transports[] = new Reference($id);
     }
     $definition->replaceArgument($argumentIndex, $transports);
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:15,代码来源:SynchronizerCompilerPass.php

示例3: processTypeExtensions

 private function processTypeExtensions(Definition $definition, ContainerBuilder $container)
 {
     $typeExtensions = [];
     foreach ($container->findTaggedServiceIds('rollerworks_search.type_extension') as $serviceId => $tag) {
         $alias = isset($tag[0]['alias']) ? $tag[0]['alias'] : $serviceId;
         $typeExtensions[$alias][] = $serviceId;
     }
     $definition->replaceArgument(2, $typeExtensions);
 }
开发者ID:rollerworks,项目名称:search-symfony-di,代码行数:9,代码来源:ExtensionPass.php

示例4: it_add_builders_in_priority_order

 /**
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  * @param \Symfony\Component\DependencyInjection\Definition $def
  * @param \Symfony\Component\DependencyInjection\Definition $fooDef
  * @param \Symfony\Component\DependencyInjection\Definition $barDef
  * @param \Symfony\Component\DependencyInjection\Definition $bazDef
  */
 public function it_add_builders_in_priority_order($container, $def, $fooDef, $barDef, $bazDef)
 {
     $container->findTaggedServiceIds('admin.context')->willReturn(array('builder_foo' => array(array('priority' => 5)), 'builder_bar' => array(array()), 'builder_baz' => array(array('priority' => -10))));
     $container->findDefinition('builder_foo')->willReturn($fooDef);
     $container->findDefinition('builder_bar')->willReturn($barDef);
     $container->findDefinition('builder_baz')->willReturn($bazDef);
     $def->replaceArgument(0, array($fooDef, $barDef, $bazDef))->shouldBeCalled();
     $this->process($container);
 }
开发者ID:kbedn,项目名称:admin-bundle,代码行数:16,代码来源:ContextPassSpec.php

示例5: processTypeExtensions

 private function processTypeExtensions(ContainerBuilder $container, Definition $definition)
 {
     $typeExtensions = [];
     foreach ($container->findTaggedServiceIds('rollerworks_datagrid.type_extension') as $id => list($tag)) {
         $def = $container->getDefinition($id);
         if (!$def->isPublic()) {
             throw new InvalidArgumentException(sprintf('The service "%s" must be public as it can be lazy-loaded.', $id));
         }
         if ($def->isAbstract()) {
             throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as it can be lazy-loaded.', $id));
         }
         if (!isset($tag['extended_type'])) {
             throw new InvalidArgumentException(sprintf('Tagged datagrid type extension must have the extended type configured using the ' . 'extended_type/extended-type attribute, none was configured for the "%s" service.', $id));
         }
         $extendedType = $tag['extended_type'];
         $typeExtensions[$extendedType][] = $id;
     }
     $definition->replaceArgument(2, $typeExtensions);
 }
开发者ID:rollerworks,项目名称:datagrid-bundle,代码行数:19,代码来源:ExtensionPass.php

示例6: injectClassResolverInPlaceHolder

 private function injectClassResolverInPlaceHolder(array $attributes, Definition $serviceInWhichInjectDef, $serviceIdInWhichInjectDef)
 {
     list(, $group) = $this->computeClassResolverId($attributes);
     $classResolverId = $this->getClassResolverIdWithGroup('kassko_class_resolver.chain', $group);
     $index = isset($attributes['index']) ? $attributes['index'] : 0;
     if (!isset($attributes['method'])) {
         $serviceInWhichInjectDef->replaceArgument($index, new Reference($classResolverId));
     } else {
         $method = $attributes['method'];
         $calls = $serviceInWhichInjectDef->getMethodCalls();
         foreach ($calls as &$call) {
             if ($method === $call[0]) {
                 if (!isset($call[1][$index])) {
                     throw new OutOfBoundsException(sprintf('The index attribute "%s" for tag "%s"' . ' and service "%s" is not in the range [0, %d].', $index, $classesToRegisterTag, $serviceIdInWhichInjectDef, count($calls) - 1));
                 }
                 $call[1][$index] = new Reference($classResolverId);
             }
         }
         unset($call);
         //Precaution.
         $serviceInWhichInjectDef->setMethodCalls($calls);
     }
 }
开发者ID:kassko,项目名称:with-symfony,代码行数:23,代码来源:InjectClassResolversPass.php

示例7: 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

示例8: resolveDefinition

 /**
  * Resolves the definition
  *
  * @param string              $id         The definition identifier
  * @param DefinitionDecorator $definition
  *
  * @return Definition
  */
 private function resolveDefinition($id, DefinitionDecorator $definition)
 {
     if (!$this->container->hasDefinition($parent = $definition->getParent())) {
         throw new RuntimeException(sprintf('The parent definition "%s" defined for definition "%s" does not exist.', $parent, $id));
     }
     $parentDef = $this->container->getDefinition($parent);
     if ($parentDef instanceof DefinitionDecorator) {
         $parentDef = $this->resolveDefinition($parent, $parentDef);
     }
     $this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $id, $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->setFactoryClass($parentDef->getFactoryClass());
     $def->setFactoryMethod($parentDef->getFactoryMethod());
     $def->setFactoryService($parentDef->getFactoryService());
     $def->setConfigurator($parentDef->getConfigurator());
     $def->setFile($parentDef->getFile());
     $def->setPublic($parentDef->isPublic());
     // 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());
     }
     if (isset($changes['factory_method'])) {
         $def->setFactoryMethod($definition->getFactoryMethod());
     }
     if (isset($changes['factory_service'])) {
         $def->setFactoryService($definition->getFactoryService());
     }
     if (isset($changes['configurator'])) {
         $def->setConfigurator($definition->getConfigurator());
     }
     if (isset($changes['file'])) {
         $def->setFile($definition->getFile());
     }
     if (isset($changes['public'])) {
         $def->setPublic($definition->isPublic());
     }
     // 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);
     }
     // merge properties
     foreach ($definition->getProperties() as $k => $v) {
         $def->setProperty($k, $v);
     }
     // append method calls
     if (count($calls = $definition->getMethodCalls()) > 0) {
         $def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
     }
     // these attributes are always taken from the child
     $def->setAbstract($definition->isAbstract());
     $def->setScope($definition->getScope());
     $def->setTags($definition->getTags());
     // set new definition on container
     $this->container->setDefinition($id, $def);
     return $def;
 }
开发者ID:laubosslink,项目名称:lab,代码行数:82,代码来源:ResolveDefinitionTemplatesPass.php

示例9: configurePluginByName

 /**
  * @param string           $name
  * @param Definition       $definition
  * @param array            $config
  * @param ContainerBuilder $container  In case we need to add additional services for this plugin
  * @param string           $serviceId  Service id of the plugin, in case we need to add additional services for this plugin.
  */
 private function configurePluginByName($name, Definition $definition, array $config, ContainerInterface $container, $serviceId)
 {
     switch ($name) {
         case 'cache':
             $definition->replaceArgument(0, new Reference($config['cache_pool']))->replaceArgument(1, new Reference($config['stream_factory']))->replaceArgument(2, $config['config']);
             break;
         case 'cookie':
             $definition->replaceArgument(0, new Reference($config['cookie_jar']));
             break;
         case 'decoder':
             $definition->addArgument(['use_content_encoding' => $config['use_content_encoding']]);
             break;
         case 'history':
             $definition->replaceArgument(0, new Reference($config['journal']));
             break;
         case 'logger':
             $definition->replaceArgument(0, new Reference($config['logger']));
             if (!empty($config['formatter'])) {
                 $definition->replaceArgument(1, new Reference($config['formatter']));
             }
             break;
         case 'redirect':
             $definition->addArgument(['preserve_header' => $config['preserve_header'], 'use_default_for_multiple' => $config['use_default_for_multiple']]);
             break;
         case 'retry':
             $definition->addArgument(['retries' => $config['retry']]);
             break;
         case 'stopwatch':
             $definition->replaceArgument(0, new Reference($config['stopwatch']));
             break;
             /* client specific plugins */
         /* client specific plugins */
         case 'add_host':
             $uriService = $serviceId . '.host_uri';
             $this->createUri($container, $uriService, $config['host']);
             $definition->replaceArgument(0, new Reference($uriService));
             $definition->replaceArgument(1, ['replace' => $config['replace']]);
             break;
         case 'header_append':
         case 'header_defaults':
         case 'header_set':
         case 'header_remove':
             $definition->replaceArgument(0, $config['headers']);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Internal exception: Plugin %s is not handled', $name));
     }
 }
开发者ID:php-http,项目名称:HttplugBundle,代码行数:55,代码来源:HttplugExtension.php

示例10: testReplaceArgumentShouldCheckBounds

 /**
  * @expectedException \OutOfBoundsException
  */
 public function testReplaceArgumentShouldCheckBounds()
 {
     $def = new Definition('stdClass');
     $def->addArgument('foo');
     $def->replaceArgument(1, 'bar');
 }
开发者ID:nuwe1,项目名称:symfony,代码行数:9,代码来源:DefinitionTest.php

示例11: configureHandler

 public function configureHandler(ServiceDefinition $definition, array $config)
 {
     $filesystemId = $this->createFilesystem($this->container, $config['name'], $config['adapter']);
     $definition->replaceArgument(0, new Reference($filesystemId));
 }
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:5,代码来源:Flysystem.php

示例12: configureHandler

 public function configureHandler(ServiceDefinition $definition, array $config)
 {
     $definition->replaceArgument(0, new Reference($config['connection']));
 }
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:4,代码来源:LegacyDFSCluster.php

示例13: configureListener

 /**
  * @param Definition $definition
  * @param array $config
  */
 protected function configureListener(Definition $definition, array $config)
 {
     $definition->replaceArgument(0, $config);
 }
开发者ID:emarref,项目名称:EmarrefXdebugBundle,代码行数:8,代码来源:EmarrefXdebugExtension.php

示例14: addFilter

 /**
  * Adds filter to manager definition by id and name.
  *
  * @param Definition $manager
  * @param string     $filterName
  * @param string     $filterId
  */
 private function addFilter($manager, $filterName, $filterId)
 {
     $filtersContainer = $manager->getArgument(0);
     $filtersContainer->addMethodCall('set', [$filterName, new Reference($filterId)]);
     $manager->replaceArgument(0, $filtersContainer);
 }
开发者ID:vinhdrt,项目名称:FilterManagerBundle,代码行数:13,代码来源:FilterPass.php

示例15: autowireConstructor

 /**
  * @param string $class
  * @param Definition $definition
  * @param string[] $classes
  * @param string $id
  * @param ContainerBuilder $container
  */
 private function autowireConstructor($class, Definition $definition, array $classes, $id, ContainerBuilder $container)
 {
     $reflection = new ReflectionClass($class);
     $constructor = $reflection->getConstructor();
     // service not created by factory with public constructor with not fully configured arguments
     if ($constructor !== NULL && $constructor->isPublic() && $definition->getFactoryMethod() === NULL) {
         $autowiredArgs = $this->autowireMethod($constructor, $definition->getArguments(), $classes, $id, $container);
         if ($definition instanceof DefinitionDecorator && $definition->getParent() !== NULL) {
             $parentDef = $container->getDefinition($definition->getParent());
             $parentDefArgsCount = count($parentDef->getArguments());
             $argsToReplace = array();
             foreach ($autowiredArgs as $i => $arg) {
                 if ($i < $parentDefArgsCount) {
                     $argsToReplace[$i] = $arg;
                     unset($autowiredArgs[$i]);
                 }
             }
             $definition->setArguments($autowiredArgs);
             foreach ($argsToReplace as $i => $arg) {
                 $definition->replaceArgument($i, $arg);
             }
         } else {
             $definition->setArguments($autowiredArgs);
         }
     }
 }
开发者ID:janmarek,项目名称:autowiring-bundle,代码行数:33,代码来源:AutowiringPass.php


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