/**
  * Sets a file to require before creating the service.
  *
  * @param string $file A full pathname to include
  *
  * @return ehough_iconic_Definition The current instance
  *
  * @api
  */
 public function setFile($file)
 {
     $this->_delegate->setFile($file);
     return parent::setFile($file);
 }
 /**
  * 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;
 }
예제 #3
0
 /**
  * Parses an individual ehough_iconic_Definition
  *
  * @param string           $id
  * @param SimpleXMLElement $service
  * @param string           $file
  */
 private function parseDefinition($id, $service, $file)
 {
     if ((string) $service['alias']) {
         $public = true;
         if (isset($service['public'])) {
             $public = $service->getAttributeAsPhp('public');
         }
         $this->container->setAlias($id, new ehough_iconic_Alias((string) $service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new ehough_iconic_DefinitionDecorator((string) $service['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 (isset($service[$key])) {
             $method = 'set' . str_replace('-', '', $key);
             $definition->{$method}((string) $service->getAttributeAsPhp($key));
         }
     }
     if ($service->file) {
         $definition->setFile((string) $service->file);
     }
     $definition->setArguments($service->getArgumentsAsPhp('argument'));
     $definition->setProperties($service->getArgumentsAsPhp('property'));
     if (isset($service->configurator)) {
         if (isset($service->configurator['function'])) {
             $definition->setConfigurator((string) $service->configurator['function']);
         } else {
             if (isset($service->configurator['service'])) {
                 $class = new ehough_iconic_Reference((string) $service->configurator['service'], ehough_iconic_ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = (string) $service->configurator['class'];
             }
             $definition->setConfigurator(array($class, (string) $service->configurator['method']));
         }
     }
     foreach ($service->call as $call) {
         $definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp('argument'));
     }
     foreach ($service->tag as $tag) {
         $parameters = array();
         foreach ($tag->attributes() as $name => $value) {
             if ('name' === $name) {
                 continue;
             }
             $parameters[$name] = ehough_iconic_SimpleXMLElement::phpize($value);
         }
         $definition->addTag((string) $tag['name'], $parameters);
     }
     $this->container->setDefinition($id, $definition);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function setFile($file)
 {
     $this->changes['file'] = true;
     return parent::setFile($file);
 }
예제 #5
0
 /**
  * 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);
 }
예제 #6
0
 /**
  * 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);
 }