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


PHP Definition::setArgument方法代码示例

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


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

示例1: 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);
     }
     $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->setArgument($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:nickaggarwal,项目名称:sample-symfony2,代码行数:80,代码来源:ResolveDefinitionTemplatesPass.php


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