![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/laminas/laminas-di/src/CodeGenerator/ |
<?php declare(strict_types=1); namespace Laminas\Di\CodeGenerator; use Laminas\Di\DefaultContainer; use Laminas\Di\InjectorInterface; use Psr\Container\ContainerInterface; /** * Abstract class for code generated dependency injectors */ abstract class AbstractInjector implements InjectorInterface { /** @var array<string, class-string<FactoryInterface>|FactoryInterface> */ protected $factories = []; /** @var array<string, FactoryInterface> */ private array $factoryInstances = []; private ContainerInterface $container; public function __construct(private InjectorInterface $injector, ?ContainerInterface $container = null) { $this->container = $container ?: new DefaultContainer($this); $this->loadFactoryList(); } /** * Init factory list */ abstract protected function loadFactoryList(): void; private function setFactory(string $type, FactoryInterface $factory): void { $this->factoryInstances[$type] = $factory; } /** * @template T * @param string|class-string<T> $type * @return FactoryInterface<T> */ private function getFactory(string $type): FactoryInterface { if (isset($this->factoryInstances[$type])) { return $this->factoryInstances[$type]; } $factoryClass = $this->factories[$type]; $factory = $factoryClass instanceof FactoryInterface ? $factoryClass : new $factoryClass(); $this->setFactory($type, $factory); return $factory; } public function canCreate(string $name): bool { return $this->hasFactory($name) || $this->injector->canCreate($name); } private function hasFactory(string $name): bool { return isset($this->factories[$name]); } /** * @template T of object * @param string|class-string<T> $name * @param array<mixed> $options * @return T */ public function create(string $name, array $options = []) { if ($this->hasFactory($name)) { return $this->getFactory($name)->create($this->container, $options); } return $this->injector->create($name, $options); } }