/**
  * 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 3.1.0
  */
 public function replaceArgument($index, $argument)
 {
     try {
         return parent::replaceArgument($index, $argument);
     } catch (ehough_iconic_exception_OutOfBoundsException $e) {
         throw new OutOfBoundsException($e);
     }
 }
 /**
  * Sets a specific argument
  *
  * @param integer $index
  * @param mixed   $argument
  *
  * @return ehough_iconic_Definition The current instance
  *
  * @throws ehough_iconic_exception_OutOfBoundsException When the replaced argument does not exist
  *
  * @api
  */
 public function replaceArgument($index, $argument)
 {
     try {
         $this->_delegate->replaceArgument($index, $argument);
     } catch (OutOfBoundsException $e) {
         throw new ehough_iconic_exception_OutOfBoundsException($e->getMessage());
     }
     return parent::replaceArgument($index, $argument);
 }
 /**
  * Resolves the definition
  *
  * @param string              $id         The definition identifier
  * @param ehough_iconic_DefinitionDecorator $definition
  *
  * @return ehough_iconic_Definition
  *
  * @throws RuntimeException When the definition is invalid
  */
 private function resolveDefinition($id, ehough_iconic_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 ehough_iconic_DefinitionDecorator) {
         $parentDef = $this->resolveDefinition($parent, $parentDef);
     }
     $this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $id, $parent));
     $def = new ehough_iconic_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());
     $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());
     }
     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());
     }
     if (isset($changes['lazy'])) {
         $def->setLazy($definition->isLazy());
     }
     // 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;
 }