/** * Sets the factory method able to create an instance of this class. * * @param string $factoryMethod The factory method name * * @return ehough_iconic_Definition The current instance * * @api */ public function setFactoryMethod($factoryMethod) { $this->_delegate->setFactoryMethod($factoryMethod); return parent::setFactoryMethod($factoryMethod); }
/** * {@inheritdoc} * * @api */ public function setFactoryMethod($method) { $this->changes['factory_method'] = true; return parent::setFactoryMethod($method); }
/** * 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; }
/** * Parses a definition. * * @param string $id * @param array $service * @param string $file * * @throws ehough_iconic_exception_InvalidArgumentException When tags are invalid */ private function parseDefinition($id, $service, $file) { if (is_string($service) && 0 === strpos($service, '@')) { $this->container->setAlias($id, substr($service, 1)); return; } elseif (isset($service['alias'])) { $public = !array_key_exists('public', $service) || (bool) $service['public']; $this->container->setAlias($id, new ehough_iconic_Alias($service['alias'], $public)); return; } if (isset($service['parent'])) { $definition = new ehough_iconic_DefinitionDecorator($service['parent']); } else { $definition = new ehough_iconic_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_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'])) { 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 ehough_iconic_exception_InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s.', $id, $file)); } foreach ($service['tags'] as $tag) { if (!isset($tag['name'])) { throw new ehough_iconic_exception_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 ehough_iconic_exception_InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s.', $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); }