Exemplo n.º 1
0
 public static function handleError($err_level, $err_message, $err_file, $err_line, $err_context)
 {
     // 不在error_reporting 里的非用户非致命错误级别不做处理
     isset(self::$_error_reporting) || (self::$_error_reporting = error_reporting());
     if (!(self::$_error_reporting & $err_level) && !in_array($err_level, array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE))) {
         return;
     }
     if (IS_DEBUG) {
         self::$_errors[] = '==== handleError ====';
         self::$_errors[] = array('level' => $err_level, 'message' => $err_message, 'file' => $err_file, 'line' => $err_line, 'context' => $err_context);
     }
     // 转换为相对路径,降低log 长度=。=!
     $err_file = str_replace(APPLICATION_PATH, '', $err_file);
     switch ($err_level) {
         case E_USER_ERROR:
         case E_RECOVERABLE_ERROR:
             Core_Log::getInstance()->error("{$err_message} LEVEL:{$err_level} FILE:{$err_file} LINE:{$err_line}");
             // 终止运行,故在此输出错误信息
             self::showErrors();
             exit;
             break;
         default:
             Core_Log::getInstance()->warn("{$err_message} LEVEL:{$err_level} FILE:{$err_file} LINE:{$err_line}");
     }
 }
Exemplo n.º 2
0
 public static function run()
 {
     error_reporting(C('error_reporting'));
     session_start();
     date_default_timezone_set(C('date_timezone'));
     register_shutdown_function(array('Core_Exception', 'handleFatalError'));
     set_error_handler(array('Core_Exception', 'handleError'));
     set_exception_handler(array('Core_Exception', 'handleException'));
     // If already slashed, strip it
     if (get_magic_quotes_gpc()) {
         $_GET = stripslashes_deep($_GET);
         $_POST = stripslashes_deep($_POST);
         $_COOKIE = stripslashes_deep($_COOKIE);
     }
     // 链接数据库
     Core_Model::connectDb();
     $controller_class_name = 'Controller_' . str_replace('/', '_', CONTROLLER_NAME);
     $method_name = ACTION_NAME . 'Action';
     $controller = new $controller_class_name();
     // 禁止直接调用基类Core_Controller的方法
     if (in_array($method_name, get_class_methods('Core_Controller'))) {
         throw new Core_Exception("Method '{$method_name}' access denied");
     }
     // Controller 不存在
     if (!$controller) {
         throw new Core_Exception("Fail to new {$controller_class_name} object");
     }
     // 给cli 模式下来个起始换行 = =!
     IS_CLI && (print "\n");
     // 页面缓存 [ CLI 模式不缓存 ]
     IS_CLI || ob_start();
     // 执行操作
     call_user_func(array($controller, $method_name));
     // 页面输出 [ CLI 模式没缓存 ]
     IS_CLI || ob_end_flush();
     // 断开数据库
     Core_Model::closeDb();
     // 打印错误信息
     IS_DEBUG && Core_Exception::showErrors();
     // 给cli 模式下来个结束换行 = =!
     IS_CLI && (print "\n");
 }
Exemplo n.º 3
0
 /**
  * web app请求派发
  * @return [type] [description]
  */
 public function dispatch()
 {
     if ('cli' == PHP_SAPI) {
         exit("[ERROR] can't call dispatch under CLI environment!");
     }
     try {
         $this->_initPlugin();
         $this->_callPlugin('onStart');
         $this->_doStart();
         $this->_callPlugin('onRoute');
         $this->_doRoute();
         $this->_callPlugin('onRun');
         $this->_doRun();
         $this->_callPlugin('onStop');
         $this->_doStop();
     } catch (Exception $e) {
         // 交由统一异常程序处理
         Core_Exception::getInstance()->handleException($e);
     }
 }
Exemplo n.º 4
0
Arquivo: Core.php Projeto: techart/tao
 /**
  * @param string $name
  * @param        $value
  */
 public function __construct($name, $value)
 {
     $this->arg_name = (string) $name;
     $this->arg_value = $value;
     parent::__construct("Invalid argument value for '{$this->arg_name}': ({$this->arg_value})");
 }
Exemplo n.º 5
0
<?php

/**
 * 框架入口文件
 * @author  hitzheng
 */
// 常量定义
define('SYSTEM_VERSION', '1.0.0');
define('SYSTEM_START_TIME', microtime(true));
define('CODE_SUCCESS', 1000);
define('CODE_FAILED', 1001);
define('CODE_PARAM_ERROR', 1002);
define('CODE_NEED_LOGIN', 1003);
// 自动加载
require SYS_PATH . '/library/core/loader.php';
spl_autoload_register(array(Core_Loader::getInstance(), 'loadClass'));
// 异常处理
Core_Exception::getInstance()->init();
Exemplo n.º 6
0
Arquivo: API.php Projeto: techart/tao
 public function __construct($name)
 {
     $this->arg_name = (string) $name;
     parent::__construct("Access token not found for project: '{$this->arg_name}'.\n");
 }
Exemplo n.º 7
0
 public function __construct($controller, $action, $role)
 {
     parent::__construct("For the role '{$role}' access denied to controller '{$controller}' in action '{$action}'");
 }
Exemplo n.º 8
0
 /**
  */
 public function __construct($message = '', $code = null)
 {
     $res = explode('@', trim($message, '[] '));
     if (count($res) > 1) {
         $type_reason = explode('.', $res[0]);
         $this->type = trim($type_reason[0]);
         $this->reason = trim($type_reason[1]);
         $attrs = explode(';', $res[1]);
         if (isset($attrs[0])) {
             $this->attrs['operand'] = $attrs[0];
         }
         unset($attrs[0]);
         foreach ($attrs as $a) {
             $name_value = explode(':', $a);
             switch (count($name_value)) {
                 case 1:
                     $this->attrs[] = trim($a);
                     break;
                 case 2:
                     $this->attrs[trim($name_value[0])] = trim($name_value[1]);
                 default:
                     $name = trim($name_value[0]);
                     unset($name_value[0]);
                     $this->attrs[$name] = implode(':', $name_value);
             }
         }
     }
     parent::__construct($message, $code);
 }
Exemplo n.º 9
0
 /**
  * Конструктор
  *
  * @param mixed $value значение константы
  */
 public function __construct($value)
 {
     parent::__construct("Bad constant value: {$value}");
 }
Exemplo n.º 10
0
 public function __construct()
 {
     parent::__construct("No accounts found for this user.\n");
 }
Exemplo n.º 11
0
 public function __construct()
 {
     parent::__construct("User account not found in session");
 }