1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Metadata\Driver; |
||
6 | |||
7 | use Metadata\ClassMetadata; |
||
8 | use Psr\Container\ContainerInterface as PsrContainerInterface; |
||
9 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
10 | |||
11 | class LazyLoadingDriver implements DriverInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var ContainerInterface|PsrContainerInterface |
||
15 | */ |
||
16 | private $container; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $realDriverId; |
||
22 | |||
23 | /** |
||
24 | * @param ContainerInterface|PsrContainerInterface $container |
||
25 | */ |
||
26 | 3 | public function __construct($container, string $realDriverId) |
|
27 | { |
||
28 | 3 | if (!$container instanceof PsrContainerInterface && !$container instanceof ContainerInterface) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
29 | 1 | throw new \InvalidArgumentException(sprintf('The container must be an instance of %s or %s (%s given).', PsrContainerInterface::class, ContainerInterface::class, \is_object($container) ? \get_class($container) : \gettype($container))); |
|
30 | } |
||
31 | |||
32 | 2 | $this->container = $container; |
|
33 | 2 | $this->realDriverId = $realDriverId; |
|
34 | 2 | } |
|
35 | |||
36 | 2 | public function loadMetadataForClass(\ReflectionClass $class): ?ClassMetadata |
|
37 | { |
||
38 | 2 | return $this->container->get($this->realDriverId)->loadMetadataForClass($class); |
|
39 | } |
||
40 | } |
||
41 |