1 | <?php |
||
42 | trait DicAwareTrait |
||
43 | { |
||
44 | /** |
||
45 | * Smart getter that tries to get instance from parent first before failing. |
||
46 | * |
||
47 | * @return ContainerInterface |
||
48 | * @throws \LogicException |
||
49 | */ |
||
50 | 2 | public function getDic(): ContainerInterface |
|
51 | { |
||
52 | 2 | if (null === $this->dic) { |
|
53 | 1 | $parent = get_parent_class($this); |
|
54 | 1 | if ($parent instanceof DicAwareInterface) { |
|
55 | $this->dic = $parent->getDic(); |
||
56 | } else { |
||
57 | 1 | $mess = 'Trying to access $dic before it was set'; |
|
58 | 1 | throw new \LogicException($mess, 1); |
|
59 | } |
||
60 | } |
||
61 | 1 | return $this->dic; |
|
62 | } |
||
63 | /** |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function hasDic(): bool |
||
70 | /** |
||
71 | * @param ContainerInterface $value |
||
72 | * |
||
73 | * @return DicAwareInterface|self Fluent Interface. |
||
74 | */ |
||
75 | 1 | public function setDic(ContainerInterface $value) |
|
80 | /** |
||
81 | * @var ContainerInterface $dic |
||
82 | */ |
||
83 | private $dic; |
||
84 | } |
||
85 |