Ejemplo n.º 1
0
 public static function getConfiguredInstance(IoCClass $class, $constructorArgs)
 {
     // Check if the class, if the scope is singleton or global,
     // was requested before.
     if ($class->scope == IoCClass::CLASSSCOPE_GLOBAL && isset($GLOBALS[$class->alias]) && $GLOBALS[$class->alias] instanceof $class->name) {
         $toreturn = $GLOBALS[$class->alias];
     } elseif ($class->scope == IoCClass::CLASSSCOPE_SINGLETON && self::$singletons[$class->alias] instanceof $class->name) {
         $toreturn = self::$singletons[$class->alias];
     } else {
         // Check if the class exists and if not try to find it
         if (!class_exists($class->name)) {
             require_once $class->name . '.class.php';
             if (!class_exists($class->name)) {
                 throw new Exception("Class {$class->name} not found");
             }
         }
         $toreturn = $class->getInstance($constructorArgs);
         if ($class->scope == IoCClass::CLASSSCOPE_GLOBAL) {
             $GLOBALS[$class->alias] = $toreturn;
         } elseif ($class->scope == IoCClass::CLASSSCOPE_SINGLETON) {
             self::$singletons[$class->alias] = $toreturn;
         }
     }
     return $toreturn;
 }
Ejemplo n.º 2
0
 public function getInstance($constructorArgs)
 {
     $factory = parent::getInstance(array());
     if (!$factory instanceof IoCClassFactorable) {
         throw new Exception('Factory do not implements IoCClassFactorable');
     }
     $instance = IoCFactory::getInstance($this->subject);
     if (count($constructorArgs)) {
         $args = $this->constructArgs->getArgsArray();
         array_unshift($args, $instance);
         call_user_func_array(array($newClass, $method), $args);
     } else {
         $factory->produce($instance);
     }
     return $instance;
 }
Ejemplo n.º 3
0
 private function setClassProperty(IoCClass $class, XMLReader $property)
 {
     $name = $property->getAttribute('name');
     $class->withProperty($name, reset($this->getArguments($property)));
 }