vendor/symfony/dependency-injection/Loader/Configurator/AbstractServiceConfigurator.php line 109

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\DependencyInjection\Loader\Configurator;
  11. use Symfony\Component\DependencyInjection\Definition;
  12. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  13. abstract class AbstractServiceConfigurator extends AbstractConfigurator
  14. {
  15.     protected $parent;
  16.     protected $id;
  17.     private $defaultTags = [];
  18.     public function __construct(ServicesConfigurator $parentDefinition $definitionstring $id null, array $defaultTags = [])
  19.     {
  20.         $this->parent $parent;
  21.         $this->definition $definition;
  22.         $this->id $id;
  23.         $this->defaultTags $defaultTags;
  24.     }
  25.     public function __destruct()
  26.     {
  27.         // default tags should be added last
  28.         foreach ($this->defaultTags as $name => $attributes) {
  29.             foreach ($attributes as $attribute) {
  30.                 $this->definition->addTag($name$attribute);
  31.             }
  32.         }
  33.         $this->defaultTags = [];
  34.     }
  35.     /**
  36.      * Registers a service.
  37.      */
  38.     final public function set(?string $idstring $class null): ServiceConfigurator
  39.     {
  40.         $this->__destruct();
  41.         return $this->parent->set($id$class);
  42.     }
  43.     /**
  44.      * Creates an alias.
  45.      */
  46.     final public function alias(string $idstring $referencedId): AliasConfigurator
  47.     {
  48.         $this->__destruct();
  49.         return $this->parent->alias($id$referencedId);
  50.     }
  51.     /**
  52.      * Registers a PSR-4 namespace using a glob pattern.
  53.      */
  54.     final public function load(string $namespacestring $resource): PrototypeConfigurator
  55.     {
  56.         $this->__destruct();
  57.         return $this->parent->load($namespace$resource);
  58.     }
  59.     /**
  60.      * Gets an already defined service definition.
  61.      *
  62.      * @throws ServiceNotFoundException if the service definition does not exist
  63.      */
  64.     final public function get(string $id): ServiceConfigurator
  65.     {
  66.         $this->__destruct();
  67.         return $this->parent->get($id);
  68.     }
  69.     /**
  70.      * Removes an already defined service definition or alias.
  71.      */
  72.     final public function remove(string $id): ServicesConfigurator
  73.     {
  74.         $this->__destruct();
  75.         return $this->parent->remove($id);
  76.     }
  77.     /**
  78.      * Registers a stack of decorator services.
  79.      *
  80.      * @param InlineServiceConfigurator[]|ReferenceConfigurator[] $services
  81.      */
  82.     final public function stack(string $id, array $services): AliasConfigurator
  83.     {
  84.         $this->__destruct();
  85.         return $this->parent->stack($id$services);
  86.     }
  87.     /**
  88.      * Registers a service.
  89.      */
  90.     final public function __invoke(string $idstring $class null): ServiceConfigurator
  91.     {
  92.         $this->__destruct();
  93.         return $this->parent->set($id$class);
  94.     }
  95. }