injectOn() public method

Inject all dependencies on an existing instance.
public injectOn ( object $instance ) : object
$instance object Object to perform injection upon
return object $instance Returns the same instance
 public function getController(Request $request)
 {
     $controller = $this->resolver->getController($request);
     if (!$controller instanceof \Closure) {
         $instance = is_array($controller) ? reset($controller) : $controller;
         if (is_object($instance)) {
             $this->container->injectOn($instance);
         }
     }
     return $controller;
 }
示例#2
0
文件: Router.php 项目: offdev/router
 /**
  * @param string $controller
  *
  * @return GenericController
  */
 private function getControllerInstance(string $controller)
 {
     if ($this->container && $this->container->has($controller)) {
         $obj = $this->container->get($controller);
     }
     if (!isset($obj)) {
         $obj = new $controller();
         if ($this->container) {
             $this->container->injectOn($obj);
         }
     }
     return $obj;
 }