@@ -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 | /** |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | * @throws DependencyException |
| 67 | 67 | * @throws NotFoundException |
| 68 | 68 | */ |
| 69 | - public function bind($object=null,$callback=null,$alias=null) |
|
| 69 | + public function bind($object = null, $callback = null, $alias = null) |
|
| 70 | 70 | {
|
| 71 | - if(!is_null($alias)){
|
|
| 71 | + if (!is_null($alias)) {
|
|
| 72 | 72 | $object = $alias; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | //If the bind method does not have parameters object and callback, the value is directly assigned to the kernel object. |
| 76 | 76 | //Otherwise, when the bind object and callback are sent, the closure class inherits |
| 77 | 77 | //the applicationProvider object and the resolve method is called |
| 78 | - return $this->make($object,$callback,'container'); |
|
| 78 | + return $this->make($object, $callback, 'container'); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -87,16 +87,16 @@ discard block |
||
| 87 | 87 | * @throws DependencyException |
| 88 | 88 | * @throws NotFoundException |
| 89 | 89 | */ |
| 90 | - private function build($object,$callback,$sync=false) |
|
| 90 | + private function build($object, $callback, $sync = false) |
|
| 91 | 91 | {
|
| 92 | 92 | //If the console object returns true, |
| 93 | 93 | //we do not cancel binding operations |
| 94 | 94 | //We are getting what applies to console with consoleKernelObject. |
| 95 | - if($sync===false) return $this->consoleKernelObjectChecker($object,$callback); |
|
| 95 | + if ($sync===false) return $this->consoleKernelObjectChecker($object, $callback); |
|
| 96 | 96 | |
| 97 | 97 | //the value corresponding to the bind value for the global object is assigned and |
| 98 | 98 | //the resolve method is called for the dependency injection. |
| 99 | - $this->kernelAssigner()->setKernelObject($object,$callback); |
|
| 99 | + $this->kernelAssigner()->setKernelObject($object, $callback); |
|
| 100 | 100 | |
| 101 | 101 | //return kernel object |
| 102 | 102 | return $this->kernel(); |
@@ -111,11 +111,11 @@ discard block |
||
| 111 | 111 | * @throws DependencyException |
| 112 | 112 | * @throws NotFoundException |
| 113 | 113 | */ |
| 114 | - private function consoleKernelObject($object,$callback,$container=false) |
|
| 114 | + private function consoleKernelObject($object, $callback, $container = false) |
|
| 115 | 115 | {
|
| 116 | 116 | //we use the console bindings class to specify the classes to be preloaded in the console application. |
| 117 | 117 | //Thus, classes that can not be bound with http are called without closure in global loaders directory. |
| 118 | - $this->resolve(ConsoleBindings::class)->console($object,$callback,$container); |
|
| 118 | + $this->resolve(ConsoleBindings::class)->console($object, $callback, $container); |
|
| 119 | 119 | |
| 120 | 120 | //The console application must always return the kernel method. |
| 121 | 121 | return $this->kernel(); |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @throws DependencyException |
| 131 | 131 | * @throws NotFoundException |
| 132 | 132 | */ |
| 133 | - private function consoleKernelObjectChecker($object,$callback,$container=false) |
|
| 133 | + private function consoleKernelObjectChecker($object, $callback, $container = false) |
|
| 134 | 134 | {
|
| 135 | 135 | //we check whether the callback value is a callable function. |
| 136 | 136 | $isCallableForCallback = is_callable($callback); |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | //If the console object returns true, |
| 139 | 139 | //we do not cancel binding operations |
| 140 | 140 | //We are getting what applies to console with consoleKernelObject. |
| 141 | - if($this->console() AND $isCallableForCallback) return $this->consoleKernelObject($object,$callback,$container); |
|
| 141 | + if ($this->console() AND $isCallableForCallback) return $this->consoleKernelObject($object, $callback, $container); |
|
| 142 | 142 | |
| 143 | 143 | //If the application is not a console operation, we re-bind to existing methods synchronously. |
| 144 | - return ($container) ? $this->containerBuild($object,$callback,true) : $this->build($object,$callback,true); |
|
| 144 | + return ($container) ? $this->containerBuild($object, $callback, true) : $this->build($object, $callback, true); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | * @throws DependencyException |
| 152 | 152 | * @throws NotFoundException |
| 153 | 153 | */ |
| 154 | - private function consoleShared($object,$callback) |
|
| 154 | + private function consoleShared($object, $callback) |
|
| 155 | 155 | {
|
| 156 | 156 | //The console share is evaluated as a true variable to be assigned as the 3rd parameter in the classes to be bound. |
| 157 | 157 | //The work to be done here is to bind the classes to be included in the console share privately. |
| 158 | - $this->kernelAssigner()->consoleShared($object,$callback); |
|
| 158 | + $this->kernelAssigner()->consoleShared($object, $callback); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -167,12 +167,12 @@ discard block |
||
| 167 | 167 | * @throws DependencyException |
| 168 | 168 | * @throws NotFoundException |
| 169 | 169 | */ |
| 170 | - public function containerBuild($object,$callback,$sync=false) |
|
| 170 | + public function containerBuild($object, $callback, $sync = false) |
|
| 171 | 171 | {
|
| 172 | 172 | //If the console object returns true, |
| 173 | 173 | //we do not cancel binding operations |
| 174 | 174 | //We are getting what applies to console with consoleKernelObject. |
| 175 | - if($sync===false) return $this->consoleKernelObjectChecker($object,$callback,true); |
|
| 175 | + if ($sync===false) return $this->consoleKernelObjectChecker($object, $callback, true); |
|
| 176 | 176 | |
| 177 | 177 | //Since the objects that come to the build method are objects from the container method, |
| 178 | 178 | //we need to automatically create a kernel object named serviceContainer in this method. |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | //the value corresponding to the bind value for the global object is assigned and |
| 182 | 182 | //the resolve method is called for the dependency method. |
| 183 | - $this->kernelAssigner()->setKernelObject($object,$callback,'serviceContainer'); |
|
| 183 | + $this->kernelAssigner()->setKernelObject($object, $callback, 'serviceContainer'); |
|
| 184 | 184 | |
| 185 | 185 | //return kernel object |
| 186 | 186 | return $this->kernel(); |
@@ -190,11 +190,11 @@ discard block |
||
| 190 | 190 | * @param $class |
| 191 | 191 | * @param $bind |
| 192 | 192 | */ |
| 193 | - private function contextualBindCleaner($class,$bind) |
|
| 193 | + private function contextualBindCleaner($class, $bind) |
|
| 194 | 194 | {
|
| 195 | 195 | //the context bind objects are checked again and the bind sequence submitted by |
| 196 | 196 | //the user is checked and forced to re-instantiate the object. |
| 197 | - if(isset(self::$instance[$class]) && self::$bindParams[$class]!==$bind){
|
|
| 197 | + if (isset(self::$instance[$class]) && self::$bindParams[$class]!==$bind) {
|
|
| 198 | 198 | unset(self::$instance[$class]); |
| 199 | 199 | unset(self::$bindParams[$class]); |
| 200 | 200 | } |
@@ -213,11 +213,11 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | // the has method can have a dotted string value so |
| 215 | 215 | // we need to be able to control the string or array within the container. |
| 216 | - foreach (explode(".",$abstract) as $item){
|
|
| 217 | - if(isset($container[$item])){
|
|
| 216 | + foreach (explode(".", $abstract) as $item) {
|
|
| 217 | + if (isset($container[$item])) {
|
|
| 218 | 218 | $container = $container[$item]; |
| 219 | 219 | } |
| 220 | - else{
|
|
| 220 | + else {
|
|
| 221 | 221 | return null; |
| 222 | 222 | } |
| 223 | 223 | } |
@@ -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; |