/**
  * @return void
  */
 protected function prepareNamesMapping()
 {
     $resolver = $this->getFactory()->getNameResolver();
     $this->scanPhpDefinitions('src/Ext', function ($extended) use($resolver) {
         if (!$this->metadriver->isExtendable($extended)) {
             CompileTimeError::create('Class `%s` must implement <ExtendableInterface>', [$extended])->_throw();
         }
         // follow inheritence path of the extended class upto the abstract
         // class and add mapping entry of the current class URI to the name
         // of the extended class
         while (($parentClass = Php\Aux::getInstantiableParentClass($extended)) != null) {
             $parent_URI = $resolver->classNameTo_URI($parentClass);
             $this->metadriver->addURI_classNameMappingEntry($parent_URI, $extended);
         }
     });
     $this->scanPhpDefinitions('src', function ($className) use($resolver) {
         if (empty($className) || !Php\Aux::isInstantiable($className)) {
             return;
         }
         $URI_str = $resolver->classNameTo_URI($className);
         $this->metadriver->addURI_classNameMappingEntry($URI_str, $className);
     }, ['Ext', 'Component']);
 }
Exemple #2
0
 /**
  * @return string
  */
 private function extendableResolveClassName($base)
 {
     $appNS = $this->getApplication()->getNamespace();
     $extended = "\\{$appNS}\\Ext";
     $extended .= Php\Aux::isFullyQualifiedName($base) ? "{$base}" : "\\{$base}";
     return class_exists($extended) ? $extended : $base;
 }
Exemple #3
0
 /**
  * @return object
  */
 public function createObject($className, $factoryArgs = [])
 {
     if ($this->singletonHasInstance($className)) {
         return $this->singletonGetInstance($className);
     }
     if (Php\Aux::implementsInterface($className, DI_INTERFACE)) {
         $injector = $this->DI_Manager->getInjectorReflection($className);
         $constructorArgs = $this->DI_Manager->getDependencies($injector);
     } else {
         $constructorArgs = $factoryArgs;
     }
     $newObject = $className::isSingleton() ? $this->singletonNewInstance($className, $constructorArgs) : new $className(...$constructorArgs);
     $this->bind($newObject);
     $newObject->setFactoryArgs(Container\FactoryArgs::createFromArray($factoryArgs));
     return $newObject;
 }