1 | <?php |
||
10 | class Binder |
||
11 | { |
||
12 | /** |
||
13 | * A reference to the service container. |
||
14 | * |
||
15 | * @var \Illuminate\Contracts\Container\Container |
||
16 | */ |
||
17 | protected $container; |
||
18 | |||
19 | /** |
||
20 | * A collection of bindings. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $bindings = []; |
||
25 | |||
26 | /** |
||
27 | * A collection of aliases. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $aliases = []; |
||
32 | |||
33 | /** |
||
34 | * A collection of classes and their dependencies. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $needs = []; |
||
39 | |||
40 | /** |
||
41 | * Holds a record of the last binding that occured. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $lastBinding = []; |
||
46 | |||
47 | /** |
||
48 | * Create a new Binder from the given service container instance. |
||
49 | * |
||
50 | * @param \Illuminate\Contracts\Container\Container $container |
||
51 | */ |
||
52 | public function __construct(Container $container) |
||
56 | |||
57 | /** |
||
58 | * Create an alias for the given class or interface. |
||
59 | * |
||
60 | * @param string $alias The alias. |
||
61 | * @param string $fqn The full namespaced path to the class or interface. |
||
62 | */ |
||
63 | public function setAlias($alias, $fqn) |
||
67 | |||
68 | /** |
||
69 | * Create a binding from an interface to a concrete class. |
||
70 | * |
||
71 | * @param string $alias The alias for this binding. |
||
72 | * @param string $interface The interface. |
||
73 | * @param string $concrete The concrete implementation. |
||
74 | */ |
||
75 | public function setBinding($alias, $interface, $concrete) |
||
86 | |||
87 | /** |
||
88 | * Binds the previous virtual binding into the Laravel service container. |
||
89 | * This will map the interface to the concrete class, then create an alias |
||
90 | * for the interface so it can later be referenced by its short name. |
||
91 | */ |
||
92 | public function solidify() |
||
114 | |||
115 | /** |
||
116 | * Set the dependencies of a class. |
||
117 | * |
||
118 | * @param string $alias The alias of the class. |
||
119 | * @param array $needs An array of dependencies. |
||
120 | */ |
||
121 | public function setNeeds($alias, array $needs) |
||
125 | |||
126 | /** |
||
127 | * Register all the dependencies with the underlying service container. |
||
128 | */ |
||
129 | public function register() |
||
135 | |||
136 | /** |
||
137 | * Registers the given dependencies with the parent class. |
||
138 | * |
||
139 | * @param string $parent_fqn The full namespaced class path. |
||
140 | * @param array $dependencies The collection of dependencies. |
||
141 | */ |
||
142 | protected function registerDependencies($parent_fqn, array $dependencies) |
||
154 | |||
155 | /** |
||
156 | * Get the fully qualified name for the given string if it's an alias |
||
157 | * otherwise ensure the class/interface exists and return it. Will throw a |
||
158 | * BindingException if the class/interface does not exist. |
||
159 | * |
||
160 | * @param string $string |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | protected function getFqn($string) |
||
178 | |||
179 | /** |
||
180 | * Check if the given array has the key specified. |
||
181 | * |
||
182 | * @param array $array The array to check. |
||
183 | * @param mixed $key The key. |
||
184 | * |
||
185 | * @return boolean |
||
186 | */ |
||
187 | protected function arrayHas(array $array, $key) |
||
192 | |||
193 | /** |
||
194 | * Return a clean alias and ensure it is a string and not of length zero. |
||
195 | * Will throw a BindingException if the value given is not a string or a |
||
196 | * string of length zero. |
||
197 | * |
||
198 | * @param string $alias |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | protected function cleanAlias($alias) |
||
211 | } |
||
212 |