1 | <?php |
||
32 | trait InstanceFactoryTrait |
||
33 | { |
||
34 | use ScopeTrait; |
||
35 | |||
36 | /** |
||
37 | * instances pool |
||
38 | * |
||
39 | * @var object[] |
||
40 | * @access protected |
||
41 | */ |
||
42 | protected $pool = []; |
||
43 | |||
44 | /** |
||
45 | * for loop detection |
||
46 | * |
||
47 | * @var array |
||
48 | * @access protected |
||
49 | */ |
||
50 | protected $loop = []; |
||
51 | |||
52 | /** |
||
53 | * @var int |
||
54 | * @access protected |
||
55 | */ |
||
56 | protected $counter = 0; |
||
57 | |||
58 | /** |
||
59 | * Get the instance either from the pool or create it |
||
60 | * |
||
61 | * @param string $id service id with or without the scope |
||
62 | * @param array $args arguments for the constructor |
||
63 | * @return object |
||
64 | * @throws LogicException if instantiation goes wrong |
||
65 | * @throws RuntimeException if method execution goes wrong |
||
66 | * @access protected |
||
67 | */ |
||
68 | protected function getInstance(/*# string */ $id, array $args) |
||
88 | |||
89 | /** |
||
90 | * Full scope info with consideration of ancestor instances |
||
91 | * |
||
92 | * @param string $id |
||
93 | * @return array |
||
94 | * @access protected |
||
95 | */ |
||
96 | protected function realScopeInfo(/*# string */ $id)/*# : array */ |
||
107 | |||
108 | /** |
||
109 | * Create the instance with loop detection |
||
110 | * |
||
111 | * Loop: an instance depends on itself in the creation chain. |
||
112 | * |
||
113 | * @param string $rawId |
||
114 | * @param array $args arguments for the constructor if any |
||
115 | * @return object |
||
116 | * @throws LogicException if instantiation goes wrong or loop detected |
||
117 | * @access protected |
||
118 | */ |
||
119 | protected function createInstance(/*# string */ $rawId, array $args) |
||
136 | |||
137 | /** |
||
138 | * execute init methods defined in 'di.init' node |
||
139 | * |
||
140 | * @return $this |
||
141 | * @throws RuntimeException if anything goes wrong |
||
142 | * @access protected |
||
143 | */ |
||
144 | protected function initContainer() |
||
155 | } |
||
156 |