@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use Resta\Console\ConsoleBindings; |
8 | 8 | use Resta\Contracts\ContainerContracts; |
9 | 9 | |
10 | -class Container implements ContainerContracts,\ArrayAccess |
|
10 | +class Container implements ContainerContracts, \ArrayAccess |
|
11 | 11 | { |
12 | 12 | /** |
13 | 13 | * @var bool |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | * @param array $bind |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - public function applicationProviderBinding($make,$bind=array()) |
|
52 | + public function applicationProviderBinding($make, $bind = array()) |
|
53 | 53 | { |
54 | 54 | //service container is an automatic application provider |
55 | 55 | //that we can bind to the special class di in the dependency condition. |
56 | 56 | //This method is automatically added to the classes resolved by the entire make bind method. |
57 | - return array_merge($bind,['app'=>$make]); |
|
57 | + return array_merge($bind, ['app'=>$make]); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | * @throws DependencyException |
66 | 66 | * @throws NotFoundException |
67 | 67 | */ |
68 | - public function bind($object=null,$callback=null) |
|
68 | + public function bind($object = null, $callback = null) |
|
69 | 69 | { |
70 | 70 | //If the bind method does not have parameters object and callback, the value is directly assigned to the kernel object. |
71 | 71 | //Otherwise, when the bind object and callback are sent, the closure class inherits |
72 | 72 | //the applicationProvider object and the resolve method is called |
73 | - return $this->make($object,$callback,'container'); |
|
73 | + return $this->make($object, $callback, 'container'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | * @throws DependencyException |
83 | 83 | * @throws NotFoundException |
84 | 84 | */ |
85 | - private function build($object,$callback,$sync=false) |
|
85 | + private function build($object, $callback, $sync = false) |
|
86 | 86 | { |
87 | 87 | //If the console object returns true, |
88 | 88 | //we do not cancel binding operations |
89 | 89 | //We are getting what applies to console with consoleKernelObject. |
90 | - if($sync===false) return $this->consoleKernelObjectChecker($object,$callback); |
|
90 | + if ($sync===false) return $this->consoleKernelObjectChecker($object, $callback); |
|
91 | 91 | |
92 | 92 | //the value corresponding to the bind value for the global object is assigned and |
93 | 93 | //the resolve method is called for the dependency injection. |
94 | - $this->kernelAssigner()->setKernelObject($object,$callback); |
|
94 | + $this->kernelAssigner()->setKernelObject($object, $callback); |
|
95 | 95 | |
96 | 96 | //return kernel object |
97 | 97 | return $this->kernel(); |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | * @throws DependencyException |
107 | 107 | * @throws NotFoundException |
108 | 108 | */ |
109 | - private function consoleKernelObject($object,$callback,$container=false) |
|
109 | + private function consoleKernelObject($object, $callback, $container = false) |
|
110 | 110 | { |
111 | 111 | //we use the console bindings class to specify the classes to be preloaded in the console application. |
112 | 112 | //Thus, classes that can not be bound with http are called without closure in global loaders directory. |
113 | - $this->resolve(ConsoleBindings::class)->console($object,$callback,$container); |
|
113 | + $this->resolve(ConsoleBindings::class)->console($object, $callback, $container); |
|
114 | 114 | |
115 | 115 | //The console application must always return the kernel method. |
116 | 116 | return $this->kernel(); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @throws DependencyException |
126 | 126 | * @throws NotFoundException |
127 | 127 | */ |
128 | - private function consoleKernelObjectChecker($object,$callback,$container=false) |
|
128 | + private function consoleKernelObjectChecker($object, $callback, $container = false) |
|
129 | 129 | { |
130 | 130 | //we check whether the callback value is a callable function. |
131 | 131 | $isCallableForCallback = is_callable($callback); |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | //If the console object returns true, |
134 | 134 | //we do not cancel binding operations |
135 | 135 | //We are getting what applies to console with consoleKernelObject. |
136 | - if($this->console() AND $isCallableForCallback) return $this->consoleKernelObject($object,$callback,$container); |
|
136 | + if ($this->console() AND $isCallableForCallback) return $this->consoleKernelObject($object, $callback, $container); |
|
137 | 137 | |
138 | 138 | //If the application is not a console operation, we re-bind to existing methods synchronously. |
139 | - return ($container) ? $this->containerBuild($object,$callback,true) : $this->build($object,$callback,true); |
|
139 | + return ($container) ? $this->containerBuild($object, $callback, true) : $this->build($object, $callback, true); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | * @throws DependencyException |
147 | 147 | * @throws NotFoundException |
148 | 148 | */ |
149 | - private function consoleShared($object,$callback) |
|
149 | + private function consoleShared($object, $callback) |
|
150 | 150 | { |
151 | 151 | //The console share is evaluated as a true variable to be assigned as the 3rd parameter in the classes to be bound. |
152 | 152 | //The work to be done here is to bind the classes to be included in the console share privately. |
153 | - $this->kernelAssigner()->consoleShared($object,$callback); |
|
153 | + $this->kernelAssigner()->consoleShared($object, $callback); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | * @throws DependencyException |
163 | 163 | * @throws NotFoundException |
164 | 164 | */ |
165 | - public function containerBuild($object,$callback,$sync=false) |
|
165 | + public function containerBuild($object, $callback, $sync = false) |
|
166 | 166 | { |
167 | 167 | //If the console object returns true, |
168 | 168 | //we do not cancel binding operations |
169 | 169 | //We are getting what applies to console with consoleKernelObject. |
170 | - if($sync===false) return $this->consoleKernelObjectChecker($object,$callback,true); |
|
170 | + if ($sync===false) return $this->consoleKernelObjectChecker($object, $callback, true); |
|
171 | 171 | |
172 | 172 | //Since the objects that come to the build method are objects from the container method, |
173 | 173 | //we need to automatically create a kernel object named serviceContainer in this method. |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | //the value corresponding to the bind value for the global object is assigned and |
177 | 177 | //the resolve method is called for the dependency method. |
178 | - $this->kernelAssigner()->setKernelObject($object,$callback,'serviceContainer'); |
|
178 | + $this->kernelAssigner()->setKernelObject($object, $callback, 'serviceContainer'); |
|
179 | 179 | |
180 | 180 | //return kernel object |
181 | 181 | return $this->kernel(); |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * @param $class |
186 | 186 | * @param $bind |
187 | 187 | */ |
188 | - private function contextualBindCleaner($class,$bind) |
|
188 | + private function contextualBindCleaner($class, $bind) |
|
189 | 189 | { |
190 | 190 | //the context bind objects are checked again and the bind sequence submitted by |
191 | 191 | //the user is checked and forced to re-instantiate the object. |
192 | - if(isset(self::$instance[$class]) && self::$bindParams[$class]!==$bind){ |
|
192 | + if (isset(self::$instance[$class]) && self::$bindParams[$class]!==$bind) { |
|
193 | 193 | unset(self::$instance[$class]); |
194 | 194 | unset(self::$bindParams[$class]); |
195 | 195 | } |
@@ -208,15 +208,15 @@ discard block |
||
208 | 208 | |
209 | 209 | // the has method can have a dotted string value so |
210 | 210 | // we need to be able to control the string or array within the container. |
211 | - foreach (explode(".",$abstract) as $item){ |
|
212 | - if(isset($container[$item])){ |
|
211 | + foreach (explode(".", $abstract) as $item) { |
|
212 | + if (isset($container[$item])) { |
|
213 | 213 | $container = $container[$item]; |
214 | 214 | } |
215 | - else{ |
|
216 | - if(!is_array($container[$item]) && empty($container[$item])){ |
|
215 | + else { |
|
216 | + if (!is_array($container[$item]) && empty($container[$item])) { |
|
217 | 217 | $container = $container[$item]; |
218 | 218 | } |
219 | - else{ |
|
219 | + else { |
|
220 | 220 | return null; |
221 | 221 | } |
222 | 222 | } |
@@ -240,11 +240,11 @@ discard block |
||
240 | 240 | |
241 | 241 | // the has method can have a dotted string value so |
242 | 242 | // we need to be able to control the string or array within the container. |
243 | - foreach (explode(".",$abstract) as $item){ |
|
243 | + foreach (explode(".", $abstract) as $item) { |
|
244 | 244 | |
245 | 245 | // this blog will work |
246 | 246 | // if the data in the container loop points to an array. |
247 | - if(!is_array($container)){ |
|
247 | + if (!is_array($container)) { |
|
248 | 248 | |
249 | 249 | // we are querying the value of |
250 | 250 | // the items corresponding to the dotted value in the container. |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $container = $container[$item]; |
253 | 253 | $bools[] = is_null($container) ? false : true; |
254 | 254 | } |
255 | - else{ |
|
255 | + else { |
|
256 | 256 | |
257 | 257 | // if the container array corresponds to a string, |
258 | 258 | // the bools array is filled with the isset control directly. |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | // the method returns false if the bools sequence is false, |
264 | 264 | // otherwise it will return true. |
265 | - return in_array(false,$bools) ? false : true; |
|
265 | + return in_array(false, $bools) ? false : true; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @throws DependencyException |
313 | 313 | * @throws NotFoundException |
314 | 314 | */ |
315 | - public function make($object=null,$callback=null,$container=false) |
|
315 | + public function make($object = null, $callback = null, $container = false) |
|
316 | 316 | { |
317 | 317 | //we check whether the boolean value of the singleton variable used |
318 | 318 | //for booting does not reset every time the object variable to be assigned to the kernel variable is true |
@@ -320,8 +320,8 @@ discard block |
||
320 | 320 | |
321 | 321 | //The console share is evaluated as a true variable to be assigned as the 3rd parameter in the classes to be bound. |
322 | 322 | //The work to be done here is to bind the classes to be included in the console share privately. |
323 | - if($container){ |
|
324 | - $this->consoleShared($object,$callback); |
|
323 | + if ($container) { |
|
324 | + $this->consoleShared($object, $callback); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | //If the third parameter passed to the bind method carries a container value, |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | //If the bind method does not have parameters object and callback, the value is directly assigned to the kernel object. |
332 | 332 | //Otherwise, when the bind object and callback are sent, the closure class inherits |
333 | 333 | //the applicationProvider object and the resolve method is called |
334 | - return ($object===null) ? $this->kernel() : $this->{$makeBuild}($object,$callback); |
|
334 | + return ($object===null) ? $this->kernel() : $this->{$makeBuild}($object, $callback); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | */ |
352 | 352 | public function offsetGet($offset) { |
353 | 353 | |
354 | - return $this->resolve($this->instances['containerInstanceResolve'],[ |
|
354 | + return $this->resolve($this->instances['containerInstanceResolve'], [ |
|
355 | 355 | 'instances' => $this->instances |
356 | 356 | ])->{$offset}(); |
357 | 357 | } |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * @param null $concrete |
376 | 376 | * @return bool|mixed |
377 | 377 | */ |
378 | - public function register($key,$object,$concrete=null) |
|
378 | + public function register($key, $object, $concrete = null) |
|
379 | 379 | { |
380 | 380 | // we assign the values required |
381 | 381 | // for register to the global value variable. |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | |
386 | 386 | // If there is an instance of the application class, |
387 | 387 | // the register method is saved both in this example and in the global. |
388 | - if(defined('appInstance')){ |
|
388 | + if (defined('appInstance')) { |
|
389 | 389 | |
390 | 390 | // where we will assign both the global instance |
391 | 391 | // and the registered application object. |
@@ -404,19 +404,19 @@ discard block |
||
404 | 404 | * @param bool $withConcrete |
405 | 405 | * @return bool |
406 | 406 | */ |
407 | - private function registerProcess($instance,$withConcrete=false) |
|
407 | + private function registerProcess($instance, $withConcrete = false) |
|
408 | 408 | { |
409 | 409 | // values recorded without concrete. |
410 | 410 | // or values deleted |
411 | - if(false===$withConcrete){ |
|
411 | + if (false===$withConcrete) { |
|
412 | 412 | |
413 | 413 | //values registered without concrete |
414 | - $instance->{$this->values['key']}=$this->values['object']; |
|
414 | + $instance->{$this->values['key']} = $this->values['object']; |
|
415 | 415 | return false; |
416 | 416 | } |
417 | 417 | |
418 | 418 | //values registered with concrete |
419 | - $instance->{$this->values['key']}[$this->values['object']]=$this->values['concrete']; |
|
419 | + $instance->{$this->values['key']}[$this->values['object']] = $this->values['concrete']; |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -427,22 +427,22 @@ discard block |
||
427 | 427 | * @throws DependencyException |
428 | 428 | * @throws NotFoundException |
429 | 429 | */ |
430 | - public function resolve($class,$bind=array()) |
|
430 | + public function resolve($class, $bind = array()) |
|
431 | 431 | { |
432 | 432 | //the context bind objects are checked again and the bind sequence submitted by |
433 | 433 | //the user is checked and forced to re-instantiate the object. |
434 | - $this->contextualBindCleaner($class,$bind); |
|
434 | + $this->contextualBindCleaner($class, $bind); |
|
435 | 435 | |
436 | 436 | //We do an instance check to get the static instance values of |
437 | 437 | //the classes to be resolved with the make bind method. |
438 | - if(!isset(self::$instance[$class])){ |
|
438 | + if (!isset(self::$instance[$class])) { |
|
439 | 439 | |
440 | 440 | //bind params object |
441 | 441 | self::$bindParams[$class] = $bind; |
442 | 442 | |
443 | 443 | //By singleton checking, we solve the dependency injection of the given class. |
444 | 444 | //Thus, each class can be called together with its dependency. |
445 | - self::$instance[$class] = DIContainerManager::make($class,$this->applicationProviderBinding($this,self::$bindParams[$class])); |
|
445 | + self::$instance[$class] = DIContainerManager::make($class, $this->applicationProviderBinding($this, self::$bindParams[$class])); |
|
446 | 446 | $this->singleton()->resolved[$class] = self::$instance[$class]; |
447 | 447 | |
448 | 448 | //return resolve class |
@@ -460,9 +460,9 @@ discard block |
||
460 | 460 | * @param $class |
461 | 461 | * @return mixed |
462 | 462 | */ |
463 | - public function resolved($class){ |
|
463 | + public function resolved($class) { |
|
464 | 464 | |
465 | - if(isset($this['resolved'][$class])){ |
|
465 | + if (isset($this['resolved'][$class])) { |
|
466 | 466 | return $this['resolved'][$class]; |
467 | 467 | } |
468 | 468 | |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @throws DependencyException |
478 | 478 | * @throws NotFoundException |
479 | 479 | */ |
480 | - public function share($object=null,$callback=null) |
|
480 | + public function share($object = null, $callback = null) |
|
481 | 481 | { |
482 | 482 | //we check whether the boolean value of the singleton variable used |
483 | 483 | //for booting does not reset every time the object variable to be assigned to the kernel variable is true |
@@ -485,12 +485,12 @@ discard block |
||
485 | 485 | |
486 | 486 | //The console share is evaluated as a true variable to be assigned as the 3rd parameter in the classes to be bound. |
487 | 487 | //The work to be done here is to bind the classes to be included in the console share privately. |
488 | - $this->consoleShared($object,$callback); |
|
488 | + $this->consoleShared($object, $callback); |
|
489 | 489 | |
490 | 490 | //If the bind method does not have parameters object and callback, the value is directly assigned to the kernel object. |
491 | 491 | //Otherwise, when the bind object and callback are sent, the closure class inherits |
492 | 492 | //the applicationProvider object and the resolve method is called |
493 | - return ($object===null) ? $this->kernel() : $this->build($object,$callback); |
|
493 | + return ($object===null) ? $this->kernel() : $this->build($object, $callback); |
|
494 | 494 | |
495 | 495 | } |
496 | 496 | |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | */ |
511 | 511 | public function singleton() |
512 | 512 | { |
513 | - if($this->singleton===false){ |
|
513 | + if ($this->singleton===false) { |
|
514 | 514 | |
515 | 515 | //after first initializing, the singleton variable is set to true, |
516 | 516 | //and subsequent incoming classes can inherit the loaded object. |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | // for application instance |
532 | 532 | // if the values to be saved are to be saved without the concrete, |
533 | 533 | // if it is an array. |
534 | - if($this->values['concrete']===null) { |
|
534 | + if ($this->values['concrete']===null) { |
|
535 | 535 | |
536 | 536 | // Without concrete, |
537 | 537 | // the saved value will be saved |
538 | 538 | // if the it does not exist in application instance. |
539 | - if(!isset($instance->{$this->values['key']})) { |
|
539 | + if (!isset($instance->{$this->values['key']})) { |
|
540 | 540 | $this->registerProcess($instance); |
541 | 541 | } |
542 | 542 | return false; |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | |
545 | 545 | // We send concrete values to be recorded with concrete as true. |
546 | 546 | // these values will be recorded as a array. |
547 | - $this->registerProcess($instance,true); |
|
547 | + $this->registerProcess($instance, true); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | /** |
@@ -552,11 +552,11 @@ discard block |
||
552 | 552 | * @param null|string $object |
553 | 553 | * @return mixed |
554 | 554 | */ |
555 | - public function terminate($key,$object=null) |
|
555 | + public function terminate($key, $object = null) |
|
556 | 556 | { |
557 | 557 | // object null is |
558 | 558 | // sent to just terminate a key. |
559 | - if($object===null){ |
|
559 | + if ($object===null) { |
|
560 | 560 | unset(core()->{$key}); |
561 | 561 | unset($this->singleton()->{$key}); |
562 | 562 | return false; |
@@ -87,7 +87,9 @@ discard block |
||
87 | 87 | //If the console object returns true, |
88 | 88 | //we do not cancel binding operations |
89 | 89 | //We are getting what applies to console with consoleKernelObject. |
90 | - if($sync===false) return $this->consoleKernelObjectChecker($object,$callback); |
|
90 | + if($sync===false) { |
|
91 | + return $this->consoleKernelObjectChecker($object,$callback); |
|
92 | + } |
|
91 | 93 | |
92 | 94 | //the value corresponding to the bind value for the global object is assigned and |
93 | 95 | //the resolve method is called for the dependency injection. |
@@ -133,7 +135,9 @@ discard block |
||
133 | 135 | //If the console object returns true, |
134 | 136 | //we do not cancel binding operations |
135 | 137 | //We are getting what applies to console with consoleKernelObject. |
136 | - if($this->console() AND $isCallableForCallback) return $this->consoleKernelObject($object,$callback,$container); |
|
138 | + if($this->console() AND $isCallableForCallback) { |
|
139 | + return $this->consoleKernelObject($object,$callback,$container); |
|
140 | + } |
|
137 | 141 | |
138 | 142 | //If the application is not a console operation, we re-bind to existing methods synchronously. |
139 | 143 | return ($container) ? $this->containerBuild($object,$callback,true) : $this->build($object,$callback,true); |
@@ -167,7 +171,9 @@ discard block |
||
167 | 171 | //If the console object returns true, |
168 | 172 | //we do not cancel binding operations |
169 | 173 | //We are getting what applies to console with consoleKernelObject. |
170 | - if($sync===false) return $this->consoleKernelObjectChecker($object,$callback,true); |
|
174 | + if($sync===false) { |
|
175 | + return $this->consoleKernelObjectChecker($object,$callback,true); |
|
176 | + } |
|
171 | 177 | |
172 | 178 | //Since the objects that come to the build method are objects from the container method, |
173 | 179 | //we need to automatically create a kernel object named serviceContainer in this method. |
@@ -211,12 +217,10 @@ discard block |
||
211 | 217 | foreach (explode(".",$abstract) as $item){ |
212 | 218 | if(isset($container[$item])){ |
213 | 219 | $container = $container[$item]; |
214 | - } |
|
215 | - else{ |
|
220 | + } else{ |
|
216 | 221 | if(!is_array($container[$item]) && empty($container[$item])){ |
217 | 222 | $container = $container[$item]; |
218 | - } |
|
219 | - else{ |
|
223 | + } else{ |
|
220 | 224 | return null; |
221 | 225 | } |
222 | 226 | } |
@@ -251,8 +255,7 @@ discard block |
||
251 | 255 | // the control result is transferred to the bools array. |
252 | 256 | $container = $container[$item]; |
253 | 257 | $bools[] = is_null($container) ? false : true; |
254 | - } |
|
255 | - else{ |
|
258 | + } else{ |
|
256 | 259 | |
257 | 260 | // if the container array corresponds to a string, |
258 | 261 | // the bools array is filled with the isset control directly. |