Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
39 / 39 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
TreeDefinitions | |
100.00% |
39 / 39 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
makeDefinitions | |
100.00% |
39 / 39 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace pvc\struct\tree\di; |
6 | |
7 | use League\Container\Definition\Definition; |
8 | use League\Container\Definition\DefinitionInterface; |
9 | use pvc\interfaces\struct\collection\CollectionInterface; |
10 | use pvc\interfaces\struct\collection\CollectionOrderedByIndexFactoryInterface; |
11 | use pvc\interfaces\struct\collection\CollectionOrderedByIndexInterface; |
12 | use pvc\interfaces\struct\collection\CollectionOrderedFactoryInterface; |
13 | use pvc\interfaces\struct\collection\CollectionOrderedInterface; |
14 | use pvc\interfaces\struct\tree\node\TreenodeChildCollectionFactoryInterface; |
15 | use pvc\interfaces\struct\tree\node\TreenodeChildCollectionInterface; |
16 | use pvc\interfaces\struct\tree\node\TreenodeFactoryInterface; |
17 | use pvc\interfaces\struct\tree\node\TreenodeInterface; |
18 | use pvc\interfaces\struct\tree\tree\TreeInterface; |
19 | use pvc\interfaces\struct\tree\tree\TreenodeCollectionInterface; |
20 | use pvc\struct\collection\Collection; |
21 | use pvc\struct\collection\CollectionOrderedByIndex; |
22 | use pvc\struct\collection\CollectionOrderedByIndexFactory; |
23 | use pvc\struct\tree\node\Treenode; |
24 | use pvc\struct\tree\node\TreenodeChildCollection; |
25 | use pvc\struct\tree\node\TreenodeChildCollectionFactory; |
26 | use pvc\struct\tree\node\TreenodeFactory; |
27 | use pvc\struct\tree\tree\Tree; |
28 | use pvc\struct\tree\tree\TreenodeCollection; |
29 | |
30 | class TreeDefinitions |
31 | { |
32 | /** |
33 | * @return array<int, DefinitionInterface> |
34 | */ |
35 | public static function makeDefinitions(): array |
36 | { |
37 | return [ |
38 | /** |
39 | * map interfaces to implementations |
40 | */ |
41 | |
42 | new Definition(CollectionInterface::class, Collection::class), |
43 | |
44 | new Definition(CollectionOrderedByIndexInterface::class, CollectionOrderedByIndex::class), |
45 | new Definition(CollectionOrderedByIndexFactoryInterface::class, CollectionOrderedByIndexFactory::class), |
46 | |
47 | new Definition(TreenodeChildCollectionInterface::class, TreenodeChildCollection::class), |
48 | new Definition(TreenodeChildCollectionFactoryInterface::class, TreenodeChildCollectionFactory::class), |
49 | |
50 | new Definition(TreenodeInterface::class, Treenode::class), |
51 | new Definition(TreenodeFactoryInterface::class, TreenodeFactory::class), |
52 | new Definition(TreenodeCollectionInterface::class, TreenodeCollection::class), |
53 | |
54 | new Definition(TreeInterface::class, Tree::class), |
55 | |
56 | /** |
57 | * definitions for the implementations |
58 | */ |
59 | new Definition(Collection::class), |
60 | new Definition(CollectionOrderedByIndex::class), |
61 | new Definition(CollectionOrderedByIndexFactory::class) |
62 | ->setShared(), |
63 | |
64 | new Definition(TreenodeChildCollection::class), |
65 | new Definition(TreenodeChildCollectionFactory::class) |
66 | ->setShared(), |
67 | |
68 | new Definition(Treenode::class, Treenode::class) |
69 | ->addArgument(TreenodeChildCollectionFactoryInterface::class), |
70 | |
71 | new Definition(TreenodeFactory::class) |
72 | ->addArgument(TreenodeChildCollectionFactoryInterface::class) |
73 | /** |
74 | * why is the argument to setShared required here and not elsewhere |
75 | * (phpstan picks it up) |
76 | */ |
77 | ->setShared(true), |
78 | |
79 | new Definition(TreenodeCollection::class), |
80 | |
81 | new Definition(Tree::class) |
82 | /** |
83 | * should be able to type hint these as interfaces, but I think there's |
84 | * a bug in the League's resolver code. Type hinting the interface |
85 | * resolves down to the concrete classes, but *without* any arguments |
86 | * that are part of the definitions. in other words, there is a call to |
87 | * $container->get(TreenodeFactory::class) but it dies because it can't find |
88 | * the argument for the constructor which is defined above. |
89 | */ |
90 | ->addArgument(TreenodeFactory::class) |
91 | ->addArgument(TreenodeCollection::class), |
92 | ]; |
93 | } |
94 | } |