Esempio 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;
 }
Esempio n. 2
0
 /**
  * Returns an instance of the local cache driver
  * 
  * @return Pfw_Cache|null instance of a Pfw_Cache object or null if none
  * is configured
  */
 public static function getInstance()
 {
     if (!is_null(self::$instance)) {
         return self::$instance;
     }
     if (null == ($local_cache = Pfw_Config::get('local_cache'))) {
         return null;
     }
     if (is_array($local_cache)) {
         $class = $local_cache['class'];
         unset($local_cache['class']);
         $options = $local_cache;
     } else {
         $class = $local_cache;
         $options = array();
     }
     Pfw_Loader::loadClass($class);
     self::$instance = new $class($options);
     return self::$instance;
 }
Esempio n. 3
0
 protected function mapAction($controller_class, $action)
 {
     try {
         Pfw_Loader::loadController($controller_class);
     } catch (Pfw_Exception_Loader $e) {
         throw new Pfw_Exception_NotFound("Could not find controller class '{$controller_class}'. " . "Please ensure class '{$controller_class}.php' exists within the 'controllers' directory", Pfw_Exception_NotFound::ROUTE_MISSING_ACTION);
     }
     $inst = new $controller_class();
     $methods_key = '_pfw_' . strtolower($controller_class) . '_methods';
     if (false === ($methods = Pfw_Cache_Local::get($methods_key))) {
         $methods = get_class_methods($inst);
         Pfw_Cache_Local::set($methods_key, $methods);
     }
     $methods = get_class_methods($inst);
     $n_action = $this->normalizeAct($action);
     foreach ($methods as $method) {
         if (!$this->isAlpha($method[0])) {
             continue;
         }
         if (self::ACTION_SUFFIX == substr($method, -6)) {
             $act_part = substr($method, 0, strlen($method) - 6);
             if ($n_action == $this->normalizeAct($act_part)) {
                 return array('controller' => $inst, 'controller_class' => $controller_class, 'method' => $method);
             }
         }
     }
     return array();
 }
 public function testOptions()
 {
     Pfw_Config::setConfig(array('local_cache' => array('class' => 'Pfw_Cache_Stub', 'stuff' => 'ok')));
     $this->assertEquals(array('stuff' => 'ok'), Pfw_Cache_Local::getInstance()->options);
 }
Esempio n. 5
0
 /**
  * Compiles all route paths into component pieces of literals, variables,
  * wildcards
  *
  * @param array $routes
  * @return array
  */
 protected function _compileRoutePaths($routes)
 {
     $cache_key = md5('_pfw_route_paths');
     if (false == ($comp = Pfw_Cache_Local::get($cache_key))) {
         $comp = array();
         foreach ($routes as $name => $params) {
             $comp[$name] = $this->_compileRoutePath($params[0]);
         }
         Pfw_Cache_Local::set($cache_key, $comp);
     }
     return $comp;
 }
Esempio n. 6
0
 public function getTableSchema($table)
 {
     if (empty($table)) {
         return array();
     }
     // try static, local caches
     if (isset(self::$schemas[$table])) {
         return self::$schemas[$table];
     }
     if (false !== ($schema = Pfw_Cache_Local::get('schema_' . $table))) {
         return $schema;
     }
     $rs = $this->fetchAll("DESCRIBE `{$table}`");
     $schema = array();
     #print_r($rs);
     foreach ($rs as $d) {
         $f = $d['Field'];
         $tls = $this->_descTypeLenSign($d['Type']);
         $schema[$f]['type'] = $tls[0];
         $schema[$f]['length'] = $tls[1];
         $schema[$f]['sign'] = $tls[2];
         $schema[$f]['default'] = $this->_descDef($d['Default']);
         $schema[$f]['key'] = $this->_descKey($d['Key']);
         $schema[$f]['nullable'] = $this->_descIsNullable($d['Null']);
         $schema[$f]['extra'] = $this->_descExtra($d['Extra']);
     }
     // cache back
     self::$schemas[$table] = $schema;
     Pfw_Cache_Local::set('schema_' . $table, $schema);
     return $schema;
 }