Пример #1
0
 function dispatch($module = null, $action = null, $parameters = null)
 {
     if (is_null($module)) {
         $defaultModule = Core_Helper::getDefaultModuleName();
         $module = Core_Common::getRequestVar('module', $defaultModule, 'string');
     }
     if (is_null($action)) {
         $action = Core_Common::getRequestVar('action', false);
     }
     if (is_null($parameters)) {
         $parameters = array();
     }
     if (!ctype_alnum($module)) {
         throw new Exception("Invalid module name '{$module}'");
     }
     $controllerClassName = "Module_" . $module . "_Controller";
     /* Check if the plugin has been activated */
     if (!Core_ModuleManager::getInstance()->isModuleActivated($module)) {
         throw new Core_FrontController_PluginDeactivatedException($module);
     }
     // Dynamically create the class
     $controller = new $controllerClassName();
     if ($action === false) {
         $action = $controller->getDefaultAction();
     }
     // Dynamically call the action
     if (!is_callable(array($controller, $action))) {
         throw new Exception("Action not found in {$controllerClassName}::{$action}().");
     }
     try {
         $controller->preDispatch();
         return call_user_func_array(array($controller, $action), $parameters);
     } catch (Core_Access_NoAccessException $e) {
         Core_PostEvent('FrontController.NoAccessException');
     } catch (Exception $e) {
         echo 'Error: ' . $e;
         return null;
     }
 }
Пример #2
0
 /**
  * Returns the plugin currently being used to display the page
  *
  * @return Core_Module
  */
 public static function getCurrentModule()
 {
     return Core_ModuleManager::getInstance()->getLoadedModule(Core_Helper::getModule());
 }
Пример #3
0
/**
 * Register an action to execute for a given event
 */
function Core_AddAction($hookName, $function)
{
    Core_ModuleManager::getInstance()->dispatcher->addObserver($function, $hookName);
}