1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Ray\Di; |
||
6 | |||
7 | use Koriym\NullObject\NullObject; |
||
8 | use ReflectionClass; |
||
9 | |||
10 | use function assert; |
||
11 | use function is_dir; |
||
12 | |||
13 | /** |
||
14 | * @codeCoverageIgnore |
||
15 | */ |
||
16 | final class NullObjectDependency implements DependencyInterface |
||
17 | { |
||
18 | /** @var class-string */ |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
19 | private $interface; |
||
20 | |||
21 | /** |
||
22 | * @param class-string $interface |
||
0 ignored issues
–
show
|
|||
23 | */ |
||
24 | public function __construct(string $interface) |
||
25 | { |
||
26 | $this->interface = $interface; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function __toString(): string |
||
33 | { |
||
34 | return ''; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function inject(Container $container) |
||
41 | { |
||
42 | return null; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | * |
||
48 | * @return void |
||
49 | */ |
||
50 | public function register(array &$container, Bind $bind) |
||
51 | { |
||
52 | $container[(string) $bind] = $bind->getBound(); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function setScope($scope) |
||
59 | { |
||
60 | } |
||
61 | |||
62 | public function toNull(string $scriptDir): Dependency |
||
63 | { |
||
64 | assert(is_dir($scriptDir)); |
||
65 | $nullObject = new NullObject(); |
||
66 | $class = $nullObject->save($this->interface, $scriptDir); |
||
67 | |||
68 | return new Dependency(new NewInstance(new ReflectionClass($class), new SetterMethods([]))); |
||
69 | } |
||
70 | } |
||
71 |