[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Loader/Configurator/ -> ContainerConfigurator.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\Argument\IteratorArgument;
  15  use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
  16  use Symfony\Component\DependencyInjection\ContainerBuilder;
  17  use Symfony\Component\DependencyInjection\Definition;
  18  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  19  use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  20  use Symfony\Component\ExpressionLanguage\Expression;
  21  
  22  /**
  23   * @author Nicolas Grekas <p@tchwork.com>
  24   */
  25  class ContainerConfigurator extends AbstractConfigurator
  26  {
  27      const FACTORY = 'container';
  28  
  29      private $container;
  30      private $loader;
  31      private $instanceof;
  32      private $path;
  33      private $file;
  34  
  35      public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, $path, $file)
  36      {
  37          $this->container = $container;
  38          $this->loader = $loader;
  39          $this->instanceof = &$instanceof;
  40          $this->path = $path;
  41          $this->file = $file;
  42      }
  43  
  44      final public function extension($namespace, array $config)
  45      {
  46          if (!$this->container->hasExtension($namespace)) {
  47              $extensions = array_filter(array_map(function ($ext) { return $ext->getAlias(); }, $this->container->getExtensions()));
  48              throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in "%s"). Looked for namespace "%s", found "%s".', $namespace, $this->file, $namespace, $extensions ? implode('", "', $extensions) : 'none'));
  49          }
  50  
  51          $this->container->loadFromExtension($namespace, static::processValue($config));
  52      }
  53  
  54      final public function import($resource, $type = null, $ignoreErrors = false)
  55      {
  56          $this->loader->setCurrentDir(\dirname($this->path));
  57          $this->loader->import($resource, $type, $ignoreErrors, $this->file);
  58      }
  59  
  60      /**
  61       * @return ParametersConfigurator
  62       */
  63      final public function parameters()
  64      {
  65          return new ParametersConfigurator($this->container);
  66      }
  67  
  68      /**
  69       * @return ServicesConfigurator
  70       */
  71      final public function services()
  72      {
  73          return new ServicesConfigurator($this->container, $this->loader, $this->instanceof);
  74      }
  75  }
  76  
  77  /**
  78   * Creates a service reference.
  79   *
  80   * @param string $id
  81   *
  82   * @return ReferenceConfigurator
  83   */
  84  function ref($id)
  85  {
  86      return new ReferenceConfigurator($id);
  87  }
  88  
  89  /**
  90   * Creates an inline service.
  91   *
  92   * @param string|null $class
  93   *
  94   * @return InlineServiceConfigurator
  95   */
  96  function inline($class = null)
  97  {
  98      return new InlineServiceConfigurator(new Definition($class));
  99  }
 100  
 101  /**
 102   * Creates a lazy iterator.
 103   *
 104   * @param ReferenceConfigurator[] $values
 105   *
 106   * @return IteratorArgument
 107   */
 108  function iterator(array $values)
 109  {
 110      return new IteratorArgument(AbstractConfigurator::processValue($values, true));
 111  }
 112  
 113  /**
 114   * Creates a lazy iterator by tag name.
 115   *
 116   * @param string $tag
 117   *
 118   * @return TaggedIteratorArgument
 119   */
 120  function tagged($tag)
 121  {
 122      return new TaggedIteratorArgument($tag);
 123  }
 124  
 125  /**
 126   * Creates an expression.
 127   *
 128   * @param string $expression an expression
 129   *
 130   * @return Expression
 131   */
 132  function expr($expression)
 133  {
 134      return new Expression($expression);
 135  }


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1