library/core/class.factory.php
public function Factory($Alias, $Args = NULL) {
      //if (!$this->Exists($Alias))
      if (!array_key_exists($Alias, $this->_Objects))
         return NULL;
      
      $Def = &$this->_Objects[$Alias];
      $ClassName = $Def['ClassName'];
      
      // Make sure the class has beeen included.
      if (!class_exists($ClassName)) {
         $Path = $Def['Path'];
         if (substr($Path, 0, 1) == '~') {
            // Replace the beginning of the path with the root of the application.
            $Path = PATH_ROOT . substr($Path, 1);
            $Def['Path'] = $Path;
         }
         
         if (file_exists($Path))
            require_once($Path);
      }
      
      if (!class_exists($ClassName, FALSE)) {
         throw new Exception(sprintf('Class %s not found while trying to get an object for %s. Check the path %s.', $ClassName, $Alias, $Def['Path']));
      }
      
      // Create the object differently depending on the type.
      $Result = NULL;
      $FactoryType = $Def['FactoryType'];
      $FactorySupplimentData = isset($Def[$FactoryType]) ? $Def[$FactoryType] : NULL;
      switch($FactoryType) {
         case Gdn::FactoryInstance:
            // Instantiate a new instance of the class.
            $Result = $this->_InstantiateObject($Alias, $ClassName, $Args);
            break;
         case Gdn::FactoryPrototype:
            $Prototype = $FactorySupplimentData;
            $Result = clone $Prototype;
            break;
         case Gdn::FactorySingleton:
            $SingletonDef = $FactorySupplimentData;
            if(is_array($SingletonDef)) {
               // The singleton has arguments for instantiation.
               $Singleton = NULL;
               $Args = $SingletonDef;
            } else {
               $Singleton = $SingletonDef;
            }
            
            if(is_null($Singleton)) {
               // Lazy create the singleton instance.
               $Singleton = $this->_InstantiateObject($Alias, $ClassName, $Args);
               $Def[$FactoryType] = $Singleton;
            }
            $Result = $Def[$FactoryType];
            break;
         case Gdn::FactoryRealSingleton:
            $RealSingletonDef = $FactorySupplimentData;
            
            // Not yet stored as an object... need to instantiate
            if (!is_object($RealSingletonDef)) {
               $RealSingleton = NULL;
            } else {
               $RealSingleton = $RealSingletonDef;
            }
            
            if (is_null($RealSingleton)) {
               // Lazy create the singleton instance.
               $RealSingleton = call_user_func_array(array($ClassName,$RealSingletonDef), $Args);
               $this->_SetDependancies($Alias, $RealSingleton);
               $Def[$FactoryType] = $RealSingleton;
            }
            $Result = $Def[$FactoryType];
            break;
         default:
            /** @todo Throw an exception. */
            throw new Exception();
            break;
      }
      return $Result;
   }
public function Factory($Alias, $Args = NULL) {
      //if (!$this->Exists($Alias))
      if (!array_key_exists($Alias, $this->_Objects))
         return NULL;
      
      $Def = &$this->_Objects[$Alias];
      $ClassName = $Def['ClassName'];
      
      // Make sure the class has beeen included.
      if (!class_exists($ClassName)) {
         $Path = $Def['Path'];
         if (substr($Path, 0, 1) == '~') {
            // Replace the beginning of the path with the root of the application.
            $Path = PATH_ROOT . substr($Path, 1);
            $Def['Path'] = $Path;
         }
         
         if (file_exists($Path))
            require_once($Path);
      }
      
      if (!class_exists($ClassName, FALSE)) {
         throw new Exception(sprintf('Class %s not found while trying to get an object for %s. Check the path %s.', $ClassName, $Alias, $Def['Path']));
      }
      
      // Create the object differently depending on the type.
      $Result = NULL;
      $FactoryType = $Def['FactoryType'];
      $FactorySupplimentData = isset($Def[$FactoryType]) ? $Def[$FactoryType] : NULL;
      switch($FactoryType) {
         case Gdn::FactoryInstance:
            // Instantiate a new instance of the class.
            $Result = $this->_InstantiateObject($Alias, $ClassName, $Args);
            break;
         case Gdn::FactoryPrototype:
            $Prototype = $FactorySupplimentData;
            $Result = clone $Prototype;
            break;
         case Gdn::FactorySingleton:
            $SingletonDef = $FactorySupplimentData;
            if(is_array($SingletonDef)) {
               // The singleton has arguments for instantiation.
               $Singleton = NULL;
               $Args = $SingletonDef;
            } else {
               $Singleton = $SingletonDef;
            }
            
            if(is_null($Singleton)) {
               // Lazy create the singleton instance.
               $Singleton = $this->_InstantiateObject($Alias, $ClassName, $Args);
               $Def[$FactoryType] = $Singleton;
            }
            $Result = $Def[$FactoryType];
            break;
         case Gdn::FactoryRealSingleton:
            $RealSingletonDef = $FactorySupplimentData;
            
            // Not yet stored as an object... need to instantiate
            if (!is_object($RealSingletonDef)) {
               $RealSingleton = NULL;
            } else {
               $RealSingleton = $RealSingletonDef;
            }
            
            if (is_null($RealSingleton)) {
               // Lazy create the singleton instance.
               $RealSingleton = call_user_func_array(array($ClassName,$RealSingletonDef), $Args);
               $this->_SetDependancies($Alias, $RealSingleton);
               $Def[$FactoryType] = $RealSingleton;
            }
            $Result = $Def[$FactoryType];
            break;
         default:
            /** @todo Throw an exception. */
            throw new Exception();
            break;
      }
      return $Result;
   }
public function Factory ( $ Alias , $ Args = NULL ) { //if (!$this->Exists($Alias)) if ( ! array_key_exists ( $ Alias , $ this -> _Objects ) ) return NULL ; $ Def = & $ this -> _Objects [ $ Alias ] ; $ ClassName = $ Def [ 'ClassName' ] ; // Make sure the class has beeen included. if ( ! class_exists ( $ ClassName ) ) { $ Path = $ Def [ 'Path' ] ; if ( substr ( $ Path , 0 , 1 ) == '~' ) { // Replace the beginning of the path with the root of the application. $ Path = PATH_ROOT . substr ( $ Path , 1 ) ; $ Def [ 'Path' ] = $ Path ; } if ( file_exists ( $ Path ) ) require_once ( $ Path ) ; } if ( ! class_exists ( $ ClassName , FALSE ) ) { throw new Exception ( sprintf ( 'Class %s not found while trying to get an object for %s. Check the path %s.' , $ ClassName , $ Alias , $ Def [ 'Path' ] ) ) ; } // Create the object differently depending on the type. $ Result = NULL ; $ FactoryType = $ Def [ 'FactoryType' ] ; $ FactorySupplimentData = isset ( $ Def [ $ FactoryType ] ) ? $ Def [ $ FactoryType ] : NULL ; switch ( $ FactoryType ) { case Gdn :: FactoryInstance : // Instantiate a new instance of the class. $ Result = $ this -> _InstantiateObject ( $ Alias , $ ClassName , $ Args ) ; break ; case Gdn :: FactoryPrototype : $ Prototype = $ FactorySupplimentData ; $ Result = clone $ Prototype ; break ; case Gdn :: FactorySingleton : $ SingletonDef = $ FactorySupplimentData ; if ( is_array ( $ SingletonDef ) ) { // The singleton has arguments for instantiation. $ Singleton = NULL ; $ Args = $ SingletonDef ; } else { $ Singleton = $ SingletonDef ; } if ( is_null ( $ Singleton ) ) { // Lazy create the singleton instance. $ Singleton = $ this -> _InstantiateObject ( $ Alias , $ ClassName , $ Args ) ; $ Def [ $ FactoryType ] = $ Singleton ; } $ Result = $ Def [ $ FactoryType ] ; break ; case Gdn :: FactoryRealSingleton : $ RealSingletonDef = $ FactorySupplimentData ; // Not yet stored as an object... need to instantiate if ( ! is_object ( $ RealSingletonDef ) ) { $ RealSingleton = NULL ; } else { $ RealSingleton = $ RealSingletonDef ; } if ( is_null ( $ RealSingleton ) ) { // Lazy create the singleton instance. $ RealSingleton = call_user_func_array ( array ( $ ClassName , $ RealSingletonDef ) , $ Args ) ; $ this -> _SetDependancies ( $ Alias , $ RealSingleton ) ; $ Def [ $ FactoryType ] = $ RealSingleton ; } $ Result = $ Def [ $ FactoryType ] ; break ; default : /** @todo Throw an exception. */ throw new Exception ( ) ; break ; } return $ Result ; }
Creates an object with mapped to the name.

@param $Alias The class code of the object to create.
@param $Args The arguments to pass to the constructor of the object.
Creates an object with mapped to the name .