@@ -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,7 +208,7 @@ 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){
|
|
| 211 | + foreach (explode(".", $abstract) as $item) {
|
|
| 212 | 212 | $container = $container[$item]; |
| 213 | 213 | } |
| 214 | 214 | |
@@ -230,11 +230,11 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | // the has method can have a dotted string value so |
| 232 | 232 | // we need to be able to control the string or array within the container. |
| 233 | - foreach (explode(".",$abstract) as $item){
|
|
| 233 | + foreach (explode(".", $abstract) as $item) {
|
|
| 234 | 234 | |
| 235 | 235 | // this blog will work |
| 236 | 236 | // if the data in the container loop points to an array. |
| 237 | - if(!is_array($container)){
|
|
| 237 | + if (!is_array($container)) {
|
|
| 238 | 238 | |
| 239 | 239 | // we are querying the value of |
| 240 | 240 | // the items corresponding to the dotted value in the container. |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | $container = $container[$item]; |
| 243 | 243 | $bools[] = is_null($container) ? false : true; |
| 244 | 244 | } |
| 245 | - else{
|
|
| 245 | + else {
|
|
| 246 | 246 | |
| 247 | 247 | // if the container array corresponds to a string, |
| 248 | 248 | // the bools array is filled with the isset control directly. |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | // the method returns false if the bools sequence is false, |
| 254 | 254 | // otherwise it will return true. |
| 255 | - return in_array(false,$bools) ? false : true; |
|
| 255 | + return in_array(false, $bools) ? false : true; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @throws DependencyException |
| 303 | 303 | * @throws NotFoundException |
| 304 | 304 | */ |
| 305 | - public function make($object=null,$callback=null,$container=false) |
|
| 305 | + public function make($object = null, $callback = null, $container = false) |
|
| 306 | 306 | {
|
| 307 | 307 | //we check whether the boolean value of the singleton variable used |
| 308 | 308 | //for booting does not reset every time the object variable to be assigned to the kernel variable is true |
@@ -310,8 +310,8 @@ discard block |
||
| 310 | 310 | |
| 311 | 311 | //The console share is evaluated as a true variable to be assigned as the 3rd parameter in the classes to be bound. |
| 312 | 312 | //The work to be done here is to bind the classes to be included in the console share privately. |
| 313 | - if($container){
|
|
| 314 | - $this->consoleShared($object,$callback); |
|
| 313 | + if ($container) {
|
|
| 314 | + $this->consoleShared($object, $callback); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | //If the third parameter passed to the bind method carries a container value, |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | //If the bind method does not have parameters object and callback, the value is directly assigned to the kernel object. |
| 322 | 322 | //Otherwise, when the bind object and callback are sent, the closure class inherits |
| 323 | 323 | //the applicationProvider object and the resolve method is called |
| 324 | - return ($object===null) ? $this->kernel() : $this->{$makeBuild}($object,$callback);
|
|
| 324 | + return ($object===null) ? $this->kernel() : $this->{$makeBuild}($object, $callback);
|
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | public function offsetGet($offset) {
|
| 343 | 343 | |
| 344 | - return $this->resolve($this->instances['containerInstanceResolve'],[ |
|
| 344 | + return $this->resolve($this->instances['containerInstanceResolve'], [ |
|
| 345 | 345 | 'instances' => $this->instances |
| 346 | 346 | ])->{$offset}();
|
| 347 | 347 | } |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | * @param null $concrete |
| 366 | 366 | * @return bool|mixed |
| 367 | 367 | */ |
| 368 | - public function register($key,$object,$concrete=null) |
|
| 368 | + public function register($key, $object, $concrete = null) |
|
| 369 | 369 | {
|
| 370 | 370 | // we assign the values required |
| 371 | 371 | // for register to the global value variable. |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | // If there is an instance of the application class, |
| 377 | 377 | // the register method is saved both in this example and in the global. |
| 378 | - if(defined('appInstance')){
|
|
| 378 | + if (defined('appInstance')) {
|
|
| 379 | 379 | |
| 380 | 380 | // where we will assign both the global instance |
| 381 | 381 | // and the registered application object. |
@@ -394,19 +394,19 @@ discard block |
||
| 394 | 394 | * @param bool $withConcrete |
| 395 | 395 | * @return bool |
| 396 | 396 | */ |
| 397 | - private function registerProcess($instance,$withConcrete=false) |
|
| 397 | + private function registerProcess($instance, $withConcrete = false) |
|
| 398 | 398 | {
|
| 399 | 399 | // values recorded without concrete. |
| 400 | 400 | // or values deleted |
| 401 | - if(false===$withConcrete){
|
|
| 401 | + if (false===$withConcrete) {
|
|
| 402 | 402 | |
| 403 | 403 | //values registered without concrete |
| 404 | - $instance->{$this->values['key']}=$this->values['object'];
|
|
| 404 | + $instance->{$this->values['key']} = $this->values['object'];
|
|
| 405 | 405 | return false; |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | //values registered with concrete |
| 409 | - $instance->{$this->values['key']}[$this->values['object']]=$this->values['concrete'];
|
|
| 409 | + $instance->{$this->values['key']}[$this->values['object']] = $this->values['concrete'];
|
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,22 +417,22 @@ discard block |
||
| 417 | 417 | * @throws DependencyException |
| 418 | 418 | * @throws NotFoundException |
| 419 | 419 | */ |
| 420 | - public function resolve($class,$bind=array()) |
|
| 420 | + public function resolve($class, $bind = array()) |
|
| 421 | 421 | {
|
| 422 | 422 | //the context bind objects are checked again and the bind sequence submitted by |
| 423 | 423 | //the user is checked and forced to re-instantiate the object. |
| 424 | - $this->contextualBindCleaner($class,$bind); |
|
| 424 | + $this->contextualBindCleaner($class, $bind); |
|
| 425 | 425 | |
| 426 | 426 | //We do an instance check to get the static instance values of |
| 427 | 427 | //the classes to be resolved with the make bind method. |
| 428 | - if(!isset(self::$instance[$class])){
|
|
| 428 | + if (!isset(self::$instance[$class])) {
|
|
| 429 | 429 | |
| 430 | 430 | //bind params object |
| 431 | 431 | self::$bindParams[$class] = $bind; |
| 432 | 432 | |
| 433 | 433 | //By singleton checking, we solve the dependency injection of the given class. |
| 434 | 434 | //Thus, each class can be called together with its dependency. |
| 435 | - self::$instance[$class] = DIContainerManager::make($class,$this->applicationProviderBinding($this,self::$bindParams[$class])); |
|
| 435 | + self::$instance[$class] = DIContainerManager::make($class, $this->applicationProviderBinding($this, self::$bindParams[$class])); |
|
| 436 | 436 | $this->singleton()->resolved[$class] = self::$instance[$class]; |
| 437 | 437 | |
| 438 | 438 | //return resolve class |
@@ -450,9 +450,9 @@ discard block |
||
| 450 | 450 | * @param $class |
| 451 | 451 | * @return mixed |
| 452 | 452 | */ |
| 453 | - public function resolved($class){
|
|
| 453 | + public function resolved($class) {
|
|
| 454 | 454 | |
| 455 | - if(isset($this['resolved'][$class])){
|
|
| 455 | + if (isset($this['resolved'][$class])) {
|
|
| 456 | 456 | return $this['resolved'][$class]; |
| 457 | 457 | } |
| 458 | 458 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | * @throws DependencyException |
| 468 | 468 | * @throws NotFoundException |
| 469 | 469 | */ |
| 470 | - public function share($object=null,$callback=null) |
|
| 470 | + public function share($object = null, $callback = null) |
|
| 471 | 471 | {
|
| 472 | 472 | //we check whether the boolean value of the singleton variable used |
| 473 | 473 | //for booting does not reset every time the object variable to be assigned to the kernel variable is true |
@@ -475,12 +475,12 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | //The console share is evaluated as a true variable to be assigned as the 3rd parameter in the classes to be bound. |
| 477 | 477 | //The work to be done here is to bind the classes to be included in the console share privately. |
| 478 | - $this->consoleShared($object,$callback); |
|
| 478 | + $this->consoleShared($object, $callback); |
|
| 479 | 479 | |
| 480 | 480 | //If the bind method does not have parameters object and callback, the value is directly assigned to the kernel object. |
| 481 | 481 | //Otherwise, when the bind object and callback are sent, the closure class inherits |
| 482 | 482 | //the applicationProvider object and the resolve method is called |
| 483 | - return ($object===null) ? $this->kernel() : $this->build($object,$callback); |
|
| 483 | + return ($object===null) ? $this->kernel() : $this->build($object, $callback); |
|
| 484 | 484 | |
| 485 | 485 | } |
| 486 | 486 | |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | */ |
| 501 | 501 | public function singleton() |
| 502 | 502 | {
|
| 503 | - if($this->singleton===false){
|
|
| 503 | + if ($this->singleton===false) {
|
|
| 504 | 504 | |
| 505 | 505 | //after first initializing, the singleton variable is set to true, |
| 506 | 506 | //and subsequent incoming classes can inherit the loaded object. |
@@ -521,12 +521,12 @@ discard block |
||
| 521 | 521 | // for application instance |
| 522 | 522 | // if the values to be saved are to be saved without the concrete, |
| 523 | 523 | // if it is an array. |
| 524 | - if($this->values['concrete']===null) {
|
|
| 524 | + if ($this->values['concrete']===null) {
|
|
| 525 | 525 | |
| 526 | 526 | // Without concrete, |
| 527 | 527 | // the saved value will be saved |
| 528 | 528 | // if the it does not exist in application instance. |
| 529 | - if(!isset($instance->{$this->values['key']})) {
|
|
| 529 | + if (!isset($instance->{$this->values['key']})) {
|
|
| 530 | 530 | $this->registerProcess($instance); |
| 531 | 531 | } |
| 532 | 532 | return false; |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | |
| 535 | 535 | // We send concrete values to be recorded with concrete as true. |
| 536 | 536 | // these values will be recorded as a array. |
| 537 | - $this->registerProcess($instance,true); |
|
| 537 | + $this->registerProcess($instance, true); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -542,11 +542,11 @@ discard block |
||
| 542 | 542 | * @param null|string $object |
| 543 | 543 | * @return mixed |
| 544 | 544 | */ |
| 545 | - public function terminate($key,$object=null) |
|
| 545 | + public function terminate($key, $object = null) |
|
| 546 | 546 | {
|
| 547 | 547 | // object null is |
| 548 | 548 | // sent to just terminate a key. |
| 549 | - if($object===null){
|
|
| 549 | + if ($object===null) {
|
|
| 550 | 550 | unset(core()->{$key});
|
| 551 | 551 | unset($this->singleton()->{$key});
|
| 552 | 552 | 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. |
@@ -241,8 +247,7 @@ discard block |
||
| 241 | 247 | // the control result is transferred to the bools array. |
| 242 | 248 | $container = $container[$item]; |
| 243 | 249 | $bools[] = is_null($container) ? false : true; |
| 244 | - } |
|
| 245 | - else{
|
|
| 250 | + } else{
|
|
| 246 | 251 | |
| 247 | 252 | // if the container array corresponds to a string, |
| 248 | 253 | // the bools array is filled with the isset control directly. |