[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Loader/Configurator/ -> ServicesConfigurator.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\DependencyInjection\Loader\Configurator;
  13  
  14  use Symfony\Component\DependencyInjection\Alias;
  15  use Symfony\Component\DependencyInjection\ChildDefinition;
  16  use Symfony\Component\DependencyInjection\ContainerBuilder;
  17  use Symfony\Component\DependencyInjection\Definition;
  18  use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  19  use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  20  
  21  /**
  22   * @author Nicolas Grekas <p@tchwork.com>
  23   *
  24   * @method InstanceofConfigurator instanceof($fqcn)
  25   */
  26  class ServicesConfigurator extends AbstractConfigurator
  27  {
  28      const FACTORY = 'services';
  29  
  30      private $defaults;
  31      private $container;
  32      private $loader;
  33      private $instanceof;
  34  
  35      public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof)
  36      {
  37          $this->defaults = new Definition();
  38          $this->container = $container;
  39          $this->loader = $loader;
  40          $this->instanceof = &$instanceof;
  41          $instanceof = [];
  42      }
  43  
  44      /**
  45       * Defines a set of defaults for following service definitions.
  46       *
  47       * @return DefaultsConfigurator
  48       */
  49      final public function defaults()
  50      {
  51          return new DefaultsConfigurator($this, $this->defaults = new Definition());
  52      }
  53  
  54      /**
  55       * Defines an instanceof-conditional to be applied to following service definitions.
  56       *
  57       * @param string $fqcn
  58       *
  59       * @return InstanceofConfigurator
  60       */
  61      final protected function setInstanceof($fqcn)
  62      {
  63          $this->instanceof[$fqcn] = $definition = new ChildDefinition('');
  64  
  65          return new InstanceofConfigurator($this, $definition, $fqcn);
  66      }
  67  
  68      /**
  69       * Registers a service.
  70       *
  71       * @param string      $id
  72       * @param string|null $class
  73       *
  74       * @return ServiceConfigurator
  75       */
  76      final public function set($id, $class = null)
  77      {
  78          $defaults = $this->defaults;
  79          $allowParent = !$defaults->getChanges() && empty($this->instanceof);
  80  
  81          $definition = new Definition();
  82          if (!$defaults->isPublic() || !$defaults->isPrivate()) {
  83              $definition->setPublic($defaults->isPublic() && !$defaults->isPrivate());
  84          }
  85          $definition->setAutowired($defaults->isAutowired());
  86          $definition->setAutoconfigured($defaults->isAutoconfigured());
  87          // deep clone, to avoid multiple process of the same instance in the passes
  88          $definition->setBindings(unserialize(serialize($defaults->getBindings())));
  89          $definition->setChanges([]);
  90  
  91          $configurator = new ServiceConfigurator($this->container, $this->instanceof, $allowParent, $this, $definition, $id, $defaults->getTags());
  92  
  93          return null !== $class ? $configurator->class($class) : $configurator;
  94      }
  95  
  96      /**
  97       * Creates an alias.
  98       *
  99       * @param string $id
 100       * @param string $referencedId
 101       *
 102       * @return AliasConfigurator
 103       */
 104      final public function alias($id, $referencedId)
 105      {
 106          $ref = static::processValue($referencedId, true);
 107          $alias = new Alias((string) $ref);
 108          if (!$this->defaults->isPublic() || !$this->defaults->isPrivate()) {
 109              $alias->setPublic($this->defaults->isPublic());
 110          }
 111          $this->container->setAlias($id, $alias);
 112  
 113          return new AliasConfigurator($this, $alias);
 114      }
 115  
 116      /**
 117       * Registers a PSR-4 namespace using a glob pattern.
 118       *
 119       * @param string $namespace
 120       * @param string $resource
 121       *
 122       * @return PrototypeConfigurator
 123       */
 124      final public function load($namespace, $resource)
 125      {
 126          $allowParent = !$this->defaults->getChanges() && empty($this->instanceof);
 127  
 128          return new PrototypeConfigurator($this, $this->loader, $this->defaults, $namespace, $resource, $allowParent);
 129      }
 130  
 131      /**
 132       * Gets an already defined service definition.
 133       *
 134       * @param string $id
 135       *
 136       * @return ServiceConfigurator
 137       *
 138       * @throws ServiceNotFoundException if the service definition does not exist
 139       */
 140      final public function get($id)
 141      {
 142          $allowParent = !$this->defaults->getChanges() && empty($this->instanceof);
 143          $definition = $this->container->getDefinition($id);
 144  
 145          return new ServiceConfigurator($this->container, $definition->getInstanceofConditionals(), $allowParent, $this, $definition, $id, []);
 146      }
 147  
 148      /**
 149       * Registers a service.
 150       *
 151       * @param string      $id
 152       * @param string|null $class
 153       *
 154       * @return ServiceConfigurator
 155       */
 156      final public function __invoke($id, $class = null)
 157      {
 158          return $this->set($id, $class);
 159      }
 160  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1