Esempio n. 1
0
 /**
  * Checks if the definition is valid.
  *
  * @param ContainerBuilder $container  The container.
  * @param Definition       $definition The definition.
  * @param string           $id         The identifier.
  * @param array            $tag        The tag data.
  *
  * @throws DefinitionException If the definition is not valid.
  */
 protected function validate(ContainerBuilder $container, Definition $definition, $id, array $tag)
 {
     if ($definition->isAbstract()) {
         throw DefinitionException::taggedServiceAbstract($id, $this->tag);
         // @codeCoverageIgnore
     }
     if (!$definition->isPublic()) {
         throw DefinitionException::taggedServiceNotPublic($id, $this->tag);
         // @codeCoverageIgnore
     }
     if (null !== $this->parent) {
         $reflection = new ReflectionClass($container->getParameterBag()->resolveValue($definition->getClass()));
         // @codeCoverageIgnoreStart
         if (!$reflection->isSubclassOf($this->parent)) {
             throw DefinitionException::taggedServiceNotSubclass($id, $this->tag, $this->parent);
         }
         // @codeCoverageIgnoreEnd
     }
 }
Esempio n. 2
0
 /**
  * Adds a method call to a definition if one is not already made.
  *
  * The `$id` is prefixed with `SERVICE_ID`.
  *
  * @param ContainerBuilder $container  The container.
  * @param string           $id         The service identifier.
  * @param string           $method     The name of the method.
  * @param array            $arguments  The call arguments.
  *
  * @return Application For method chaining.
  *
  * @throws DefinitionException If the definition does not exist.
  */
 protected function addMethodCall(ContainerBuilder $container, $id, $method, array $arguments = array())
 {
     $id = self::getId($id);
     if (!$container->hasDefinition($id)) {
         throw DefinitionException::notExist($id);
         // @codeCoverageIgnore
     }
     $definition = $container->getDefinition($id);
     foreach ($definition->getMethodCalls() as $call) {
         if ($method === $call[0]) {
             return $this;
             // @codeCoverageIgnore
         }
     }
     $definition->addMethodCall($method, $arguments);
     return $this;
 }