Exemplo n.º 1
0
 public function init($file = "plugins.xml")
 {
     self::$initialized = true;
     if (!is_null(self::$plugins)) {
         return self::$plugins;
     }
     $classes_key = md5('_pfw_plugins_classes_' . $file);
     $cache_key = md5('_pfw_plugins_' . $file);
     if (false !== ($class_list = Pfw_Cache_Local::get($classes_key))) {
         // load all of the classes we're about to deserialize
         foreach ($class_list as $class) {
             Pfw_Loader::loadClass($class);
         }
         if (false !== (self::$plugins = Pfw_Cache_Local::get($cache_key))) {
             return true;
         }
     }
     self::$plugins = array();
     $class_list = array();
     foreach (self::$phases as $phase) {
         self::$plugins[$phase] = array();
     }
     global $_PATHS;
     $file = $_PATHS['conf'] . DIRECTORY_SEPARATOR . $file;
     try {
         $conf_plugins = simplexml_load_file($file);
     } catch (Exception $e) {
         throw new Pfw_Exception_System("Failed to parse plugin config file: {$file}");
     }
     if (!empty($conf_plugins)) {
         foreach ($conf_plugins as $plugin) {
             $attr = $plugin->attributes();
             $class = (string) $attr['class'];
             Pfw_Loader::loadClass($class);
             array_push($class_list, $class);
             $inst = new $class();
             $methods = get_class_methods($inst);
             foreach ($methods as $method) {
                 if (in_array($method, self::$phases)) {
                     $name = isset($attr['name']) ? (string) $attr['name'] : null;
                     $i =& $inst;
                     array_push(self::$plugins[$method], array('inst' => $i, 'name' => $name));
                 }
             }
         }
     }
     Pfw_Cache_Local::set($classes_key, $class_list, self::CACHE_TTL_S);
     Pfw_Cache_Local::set($cache_key, self::$plugins, self::CACHE_TTL_S);
     return true;
 }
Exemplo n.º 2
0
<?php

/**
 * Add a project specific startup here
 */
global $_PATHS, $_ENVIRONMENT;
Pfw_Loader::loadFile("pfw_routes.php", $_PATHS['conf']);
Pfw_Loader::loadClass('Pfw_Controller_Front');
Pfw_Loader::loadClass('Pfw_PluginManager');
Pfw_Loader::loadClass('Pfw_Session');
Pfw_Loader::loadClass('Pfw_Alert');
// initialize the session
Pfw_Session::start();
// initialize the plugin manager
Pfw_PluginManager::init();
// initialize alerts
Pfw_Alert::init();
// turn off error display for production
if ($_ENVIRONMENT == "production") {
    ini_set('display_errors', 0);
    ini_set('log_errors', 1);
}
// setup front controller and routing
$front = Pfw_Controller_Front::getInstance();
$front->getRouter()->setRoutes($_pfw_routes)->setModules($_pfw_modules);
$four_oh_four = false;
try {
    $front->dispatch();
} catch (Pfw_Exception_System $e) {
    $e->emitLog();
    if ($_ENVIRONMENT == "development") {
Exemplo n.º 3
0
 /**
  * Routes the request through the router with assigned routes
  *
  * @param array $routes
  */
 public function dispatch()
 {
     Pfw_PluginManager::execPreRoute();
     $script_url = $_SERVER['REQUEST_URI'];
     if (false !== ($qpos = strpos($script_url, '?'))) {
         $script_url = substr($script_url, 0, $qpos);
     }
     $route_params = $this->getRouter()->route($script_url);
     Pfw_Request::setParams($route_params);
     if (empty($route_params)) {
         Pfw_Loader::loadClass('Pfw_Exception_NoRoute');
         throw new Pfw_Exception_NoRoute("Failed to find matching route for url path: '{$script_url}'");
     }
     Pfw_PluginManager::execPostRoute();
     $module = isset($route_params['module']) ? $route_params['module'] : null;
     Pfw_PluginManager::execPreMap();
     $cont_action = $this->getMapper()->map($route_params['controller'], $route_params['action'], $module);
     Pfw_PluginManager::execPostMap();
     Pfw_PluginManager::execPreDispatch();
     $controller = $cont_action['controller'];
     $method = $cont_action['method'];
     $controller->_setFrontController($this);
     $this->controller = $controller;
     $controller->{$method}();
     Pfw_PluginManager::execPostDispatch();
 }