Ejemplo n.º 1
0
 /**
  * Autoload
  * @param $className
  */
 protected static function autoload($className)
 {
     $path = str_replace(array('_', '\\'), array('/', '/'), $className);
     $path = sprintf('%s/library/%s.php', self::$workingDir, $path);
     if (is_file($path)) {
         require $path;
     } else {
         self::log(Zhpe_I18in::en('File not exists', ': ') . $path . "\n");
     }
 }
Ejemplo n.º 2
0
Archivo: Model.php Proyecto: zhpe/zhpe
 /**
  * @return Zhpe_DbInterface
  * @throws Exception
  */
 public static function data()
 {
     if (is_null(static::$data)) {
         if (!isset(Config::$modules[static::$module]['dsn'])) {
             $err = Zhpe_I18in::en('Config not exists', ": Config::\$modules['%s']['dsn']");
             throw new Exception(sprintf($err, static::$module));
         }
         $dsnKey = Config::$modules[static::$module]['dsn'];
         if (!isset(Config::$dsn[$dsnKey]['type'])) {
             $err = Zhpe_I18in::en('Config not exists', ": Config::\$dsn['%s']['type']");
             throw new Exception(sprintf($err, $dsnKey));
         }
         // Data Access Objects
         $cls = 'Zhpe_Db' . Config::$dsn[$dsnKey]['type'];
         static::$data = new $cls(static::$module, static::$table, static::$primary, static::$joins);
     }
     //Return static::$data anywhere.
     return static::$data;
 }
Ejemplo n.º 3
0
 /**
  * @param string $moduleName
  * @return mixed
  * @throws Exception
  */
 private function transactionObj($moduleName = '')
 {
     if (empty($moduleName)) {
         $moduleName = Zhpe_Web::$request['module'];
     }
     if (!isset(Config::$modules[$moduleName]['dsn']) || !isset(Config::$dsn[Config::$modules[$moduleName]['dsn']])) {
         throw new Exception(Zhpe_I18in::en('Module DB error'));
     }
     if (!isset(Config::$dsn[Config::$modules[$moduleName]['dsn']]['type'])) {
         throw new Exception(Zhpe_I18in::en('Module DB type error'));
     }
     $obj = array('Zhpe_Db' . Config::$dsn[Config::$modules[$moduleName]['dsn']]['type'], 'db');
     return call_user_func_array($obj, array($moduleName));
 }
Ejemplo n.º 4
0
Archivo: Web.php Proyecto: zhpe/zhpe
 /**
  * Action
  * @throws Exception
  */
 private static function initAction()
 {
     if (self::$request['module'] == '') {
         $className = sprintf("%sController", self::$request['controller']);
     } else {
         $className = sprintf("%s_%sController", self::$request['module'], self::$request['controller']);
     }
     if (!class_exists($className)) {
         throw new Exception(Zhpe_I18in::en('Class not exists', ': ' . $className));
     }
     self::$action = new $className();
     if (!method_exists(self::$action, self::$request['action'])) {
         throw new Exception(Zhpe_I18in::en('Method not exists', ': ' . $className . '->' . self::$request['action']));
     }
     // User can write custorm code in this method.
     self::$action->init();
     // If init() is ok, start the action.
     return call_user_func_array(array(self::$action, self::$request['action']), self::$request['args']);
 }