コード例 #1
0
ファイル: App.php プロジェクト: stubbles/stubbles-ioc
 /**
  * creates an object via injection
  *
  * If the class to create an instance of contains a static __bindings() method
  * this method will be used to configure the ioc bindings before using the ioc
  * container to create the instance.
  *
  * @api
  * @param   string  $className    full qualified class name of class to create an instance of
  * @param   string  $projectPath  path to project
  * @return  \stubbles\App
  */
 public static function createInstance(string $className, string $projectPath) : App
 {
     Runtime::reset();
     self::$projectPath = $projectPath;
     $binder = new Binder();
     foreach (static::getBindingsForApp($className) as $bindingModule) {
         if (is_string($bindingModule)) {
             $bindingModule = new $bindingModule();
         }
         if ($bindingModule instanceof BindingModule) {
             $bindingModule->configure($binder, $projectPath);
         } elseif ($bindingModule instanceof \Closure) {
             $bindingModule($binder, $projectPath);
         } else {
             throw new \InvalidArgumentException('Given module class ' . get_class($bindingModule) . ' is not an instance of stubbles\\ioc\\module\\BindingModule');
         }
     }
     return $binder->getInjector()->getInstance($className);
 }
コード例 #2
0
ファイル: RuntimeTest.php プロジェクト: stubbles/stubbles-ioc
 /**
  * clean up test environment
  */
 public function tearDown()
 {
     Runtime::reset();
 }