1 | <?php |
||
10 | class Container |
||
11 | { |
||
12 | private static $instance; |
||
13 | |||
14 | /** |
||
15 | * Resolved types |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $definitions = []; |
||
19 | |||
20 | /** |
||
21 | * Globally available container |
||
22 | * |
||
23 | * @return static |
||
24 | */ |
||
25 | public static function getInstance() |
||
33 | |||
34 | /** |
||
35 | * Add item to the container |
||
36 | * @param string $alias |
||
37 | * @param mixed|null $concrete |
||
38 | */ |
||
39 | public function add($alias, $concrete = null) |
||
51 | |||
52 | /** |
||
53 | * Check if item is available in container |
||
54 | * @param string $alias |
||
55 | * @return boolean |
||
56 | */ |
||
57 | public function has($alias) |
||
65 | |||
66 | /** |
||
67 | * Get an item of the container |
||
68 | * @param string $alias |
||
69 | * @return mixed |
||
70 | */ |
||
71 | public function get($alias) |
||
75 | |||
76 | /** |
||
77 | * Call method with given parameters |
||
78 | * @param string|callable $action |
||
79 | * @param array $args |
||
80 | * @return mixed |
||
81 | */ |
||
82 | public function call ($action, array $args = []) |
||
93 | |||
94 | /** |
||
95 | * Get reflection from an action |
||
96 | * @param array|callable $action |
||
97 | * @return ReflectionFunctionAbstract |
||
98 | */ |
||
99 | public function getActionReflection($action) |
||
108 | |||
109 | /** |
||
110 | * Create a new container for asked class |
||
111 | * @param string $concrete |
||
112 | * @return Container |
||
113 | */ |
||
114 | public function build ($class) |
||
125 | |||
126 | /** |
||
127 | * Get reflection parameters |
||
128 | * @param ReflectionFunctionAbstract $reflection |
||
129 | * @param array $args |
||
130 | * @return array |
||
131 | */ |
||
132 | public function getParameters(ReflectionFunctionAbstract $reflection, $args = []) |
||
157 | } |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: