Example #1
0
 /**
  * Read Dependencies And Providers
  * Make a new (Child)Injector for the requested Object with Providers
  * Build Dependencies recursively
  * Build requested Object
  *
  * @param Injector $injector
  * @return mixed
  */
 function get(Injector $injector)
 {
     $className = $this->reflector->getClassName();
     $dependencies = $this->_getDependencies($className);
     //      print_r($dependencies);
     if (!empty($dependencies)) {
         $childInjector = $injector->getChild($this->_getProviders($className));
         //recursive build dependencies
         $params = array_map(function ($dependency) use($childInjector) {
             return $childInjector->get($dependency['token']);
         }, $dependencies);
     } else {
         $params = [];
     }
     return new $className(...array_values($params));
 }
Example #2
0
 public function read(Reflector $reflector, $proxyClassName)
 {
     //        print_r('read' . PHP_EOL);
     if (!isset(self::$config[$reflector->getClassName()])) {
         print_r('read !isset' . PHP_EOL);
         return false;
     }
     $cfg = self::$config[$reflector->getClassName()];
     $file = self::PATH . '/' . $cfg['proxyClassName'] . '.php';
     if ($this->filesystem->exists($file)) {
         include $file;
         return true;
     }
     return false;
 }