1 | <?php |
||
2 | |||
3 | namespace PHPKitchen\DI\Mixins; |
||
4 | |||
5 | use PHPKitchen\DI\Contracts\Container; |
||
6 | |||
7 | /** |
||
8 | * Injects DI container to target class. |
||
9 | * |
||
10 | * @property Container $container public alias of {@link _diContainer} |
||
11 | * |
||
12 | * @package PHPKitchen\DI\mixins |
||
13 | * @author Dmitry Kolodko <[email protected]> |
||
14 | */ |
||
15 | trait ContainerAccess { |
||
16 | /** |
||
17 | * @var Container |
||
18 | */ |
||
19 | protected $_container; |
||
20 | |||
21 | public function getContainer() { |
||
22 | if (!isset($this->_container)) { |
||
23 | $this->initContainer(); |
||
24 | } |
||
25 | |||
26 | return $this->_container; |
||
27 | } |
||
28 | |||
29 | public function setContainer(Container $container) { |
||
30 | $this->_container = $container; |
||
31 | } |
||
32 | |||
33 | protected function initContainer() { |
||
34 | $this->setContainer(\Yii::$container); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
35 | } |
||
36 | } |