Example #1
0
 /**
  * Register a file into memory and return an instantiated object, based on a dot notated path.
  *
  * @access public
  * @param string $slug
  * @param array $config
  * @return object
  * @static
  */
 public static function factory($slug, array $config = array())
 {
     if (isset(static::$__registered[$slug])) {
         return static::$__registered[$slug];
     }
     $namespace = App::toNamespace($slug);
     if (!class_exists($namespace)) {
         App::import($namespace);
     }
     if (class_exists($namespace)) {
         if (isset(static::$__config[$slug])) {
             $config = $config + static::$__config[$slug];
         }
         return static::store(new $namespace($config));
     } else {
         throw new Exception(sprintf('Class "%s" could not be instantiated into the registry.', $slug));
     }
 }
Example #2
0
 /**
  * Attempts to determine a View path and load the View. If found, returns the instance, else returns the AppView.
  *
  * @access public
  * @return object|null
  */
 public final function loadView()
 {
     $path = $this->routedPath(VIEWS);
     // Use created class if it exists
     if (file_exists($path)) {
         include_once $path;
         $class = App::toNamespace($path);
         if (class_exists($class)) {
             $View = new $class();
         }
         // Else use the AppView
     } else {
         $View = new \app\AppView();
     }
     if ($View instanceof \titon\system\View) {
         return $View;
     }
     throw new Exception(sprintf('The View %s must extend \\app\\AppView.', $this->_config['controller']));
 }