/** * 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); }
/** * Parses an individual ehough_iconic_Definition * * @param string $id * @param DOMElement $service * @param string $file */ private function parseDefinition($id, DOMElement $service, $file) { if ($alias = $service->getAttribute('alias')) { $public = true; if ($publicAttr = $service->getAttribute('public')) { $public = self::_phpize($publicAttr); } $this->container->setAlias($id, new ehough_iconic_Alias($alias, $public)); return; } if ($parent = $service->getAttribute('parent')) { $definition = new ehough_iconic_DefinitionDecorator($parent); } else { $definition = new ehough_iconic_Definition(); } foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'synchronized', 'lazy', 'abstract') as $key) { if ($value = $service->getAttribute($key)) { $method = 'set' . str_replace('-', '', $key); $definition->{$method}(self::_phpize($value)); } } if ($files = $this->getChildren($service, 'file')) { $definition->setFile($files[0]->nodeValue); } $definition->setArguments($this->getArgumentsAsPhp($service, 'argument')); $definition->setProperties($this->getArgumentsAsPhp($service, 'property')); if ($configurators = $this->getChildren($service, 'configurator')) { $configurator = $configurators[0]; if ($function = $configurator->getAttribute('function')) { $definition->setConfigurator($function); } else { if ($childService = $configurator->getAttribute('service')) { $class = new ehough_iconic_Reference($childService, ehough_iconic_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] = self::_phpize($node->nodeValue); } // keep not normalized key for BC too $parameters[$name] = self::_phpize($node->nodeValue); } $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); } $this->container->setDefinition($id, $definition); }