vendor/symfony/dependency-injection/Loader/Configurator/PrototypeConfigurator.php line 46

  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\Loader\PhpFileLoader;
  13. /**
  14.  * @author Nicolas Grekas <p@tchwork.com>
  15.  */
  16. class PrototypeConfigurator extends AbstractServiceConfigurator
  17. {
  18.     use Traits\AbstractTrait;
  19.     use Traits\ArgumentTrait;
  20.     use Traits\AutoconfigureTrait;
  21.     use Traits\AutowireTrait;
  22.     use Traits\BindTrait;
  23.     use Traits\CallTrait;
  24.     use Traits\ConfiguratorTrait;
  25.     use Traits\DeprecateTrait;
  26.     use Traits\FactoryTrait;
  27.     use Traits\LazyTrait;
  28.     use Traits\ParentTrait;
  29.     use Traits\PropertyTrait;
  30.     use Traits\PublicTrait;
  31.     use Traits\ShareTrait;
  32.     use Traits\TagTrait;
  33.     public const FACTORY 'load';
  34.     private PhpFileLoader $loader;
  35.     private string $resource;
  36.     private ?array $excludes null;
  37.     private bool $allowParent;
  38.     private ?string $path;
  39.     public function __construct(ServicesConfigurator $parentPhpFileLoader $loaderDefinition $defaultsstring $namespacestring $resourcebool $allowParentstring $path null)
  40.     {
  41.         $definition = new Definition();
  42.         if (!$defaults->isPublic() || !$defaults->isPrivate()) {
  43.             $definition->setPublic($defaults->isPublic());
  44.         }
  45.         $definition->setAutowired($defaults->isAutowired());
  46.         $definition->setAutoconfigured($defaults->isAutoconfigured());
  47.         // deep clone, to avoid multiple process of the same instance in the passes
  48.         $definition->setBindings(unserialize(serialize($defaults->getBindings())));
  49.         $definition->setChanges([]);
  50.         $this->loader $loader;
  51.         $this->resource $resource;
  52.         $this->allowParent $allowParent;
  53.         $this->path $path;
  54.         parent::__construct($parent$definition$namespace$defaults->getTags());
  55.     }
  56.     public function __destruct()
  57.     {
  58.         parent::__destruct();
  59.         if (isset($this->loader)) {
  60.             $this->loader->registerClasses($this->definition$this->id$this->resource$this->excludes$this->path);
  61.         }
  62.         unset($this->loader);
  63.     }
  64.     /**
  65.      * Excludes files from registration using glob patterns.
  66.      *
  67.      * @param string[]|string $excludes
  68.      *
  69.      * @return $this
  70.      */
  71.     final public function exclude(array|string $excludes): static
  72.     {
  73.         $this->excludes = (array) $excludes;
  74.         return $this;
  75.     }
  76. }