Ejemplo n.º 1
0
/**
 * Handles autoloading of classes that have been specified in autoload.ini.
 *
 * @param string A class name.
 *
 * @return void
 *
 * @author Sean Kerr (skerr@mojavi.org)
 * @since  3.0.0
 */
function __autoload($class)
{
    // this static variable is generated by the $config file below
    static $classes;
    if (!isset($classes)) {
        try {
            // include the list of autoload classes
            $config = ConfigCache::checkConfig('config/autoload.ini');
        } catch (MojaviException $e) {
            $e->printStackTrace();
        } catch (Exception $e) {
            // unknown exception
            $e = new MojaviException($e->getMessage());
            $e->printStackTrace();
        }
        require_once $config;
    }
    if (!isset($classes[$class])) {
        // unspecified class
        $error = 'Autoloading of class "%s" failed';
        $error = sprintf($error, $class);
        $e = new AutoloadException($error);
        $e->printStackTrace();
    }
    // class exists, let's include it
    require_once $classes[$class];
}
Ejemplo n.º 2
0
 /**
  * Dispatch a request.
  *
  * This will determine which module and action to use by request parameters
  * specified by the user.
  *
  * @return void
  *
  * @author Sean Kerr (skerr@mojavi.org)
  * @since  3.0.0
  */
 public function dispatch()
 {
     try {
         // initialize the controller
         $this->initialize();
         // get the application context
         $context = $this->getContext();
         // determine our module and action
         $moduleName = $context->getRequest()->getParameter(MO_MODULE_ACCESSOR);
         $actionName = $context->getRequest()->getParameter(MO_ACTION_ACCESSOR);
         if ($moduleName == null) {
             // no module has been specified
             $moduleName = MO_DEFAULT_MODULE;
         }
         if ($actionName == null) {
             // no action has been specified
             if ($this->actionExists($moduleName, 'Index')) {
                 // an Index action exists
                 $actionName = 'Index';
             } else {
                 // use the default action
                 $actionName = MO_DEFAULT_ACTION;
             }
         }
         // make the first request
         $this->forward($moduleName, $actionName);
     } catch (MojaviException $e) {
         $e->printStackTrace();
     } catch (Exception $e) {
         // most likely an exception from a third-party library
         $e = new MojaviException($e->getMessage());
         $e->printStackTrace();
     }
 }
Ejemplo n.º 3
0
 /**
  * Dispatch a request.
  *
  * @param string A module name.
  * @param string An action name.
  * @param array  An associative array of parameters to be set.
  *
  * @return void
  *
  * @author Sean Kerr (skerr@mojavi.org)
  * @since  3.0.0
  */
 public function dispatch($moduleName, $actionName, $parameters = null)
 {
     try {
         // initialize the controller
         $this->initialize();
         // set parameters
         if ($parameters != null) {
             $this->getContext()->getRequest()->setParametersByRef($parameters);
         }
         // make the first request
         $this->forward($moduleName, $actionName);
     } catch (MojaviException $e) {
         $e->printStackTrace();
     } catch (Exception $e) {
         // most likely an exception from a third-party library
         $e = new MojaviException($e->getMessage());
         $e->printStackTrace();
     }
 }
Ejemplo n.º 4
0
 /**
  * Retrieve a new Controller implementation instance.
  *
  * @param string A Controller implementation name.
  *
  * @return Controller A Controller implementation instance.
  *
  * @throws <b>FactoryException</b> If a new controller implementation
  *                                 instance cannot be created.
  *
  * @author Sean Kerr (skerr@mojavi.org)
  * @since  3.0.0
  */
 public static function newInstance($class)
 {
     try {
         if (!isset(self::$instance)) {
             // the class exists
             $object = new $class();
             if (!$object instanceof Controller) {
                 // the class name is of the wrong type
                 $error = 'Class "%s" is not of the type Controller';
                 $error = sprintf($error, $class);
                 throw new FactoryException($error);
             }
             // set our singleton instance
             self::$instance = $object;
             return $object;
         } else {
             $type = get_class(self::$instance);
             // an instance has already been created
             $error = 'A Controller implementation instance has already ' . 'been created';
             throw new FactoryException($error);
         }
     } catch (MojaviException $e) {
         $e->printStackTrace();
     } catch (Exception $e) {
         // most likely an exception from a third-party library
         $e = new MojaviException($e->getMessage());
         $e->printStackTrace();
     }
 }