/**
     * 错误列表显示
     *
     * @param string $message
     * @param code   $code
     */
    public function __construct($message = 0, $code = null)
    {
        if (_CLI_) {
            $file = $this->getFile();
            $line = $this->getLine();
            $now = date('Y-m-d H:i:s');
            $out = <<<EOF
==================================================================================
--                         Uncaught exception!
--时间:{$now}
--信息:{$message}
--代码:{$code}
--文件:{$file}
--行数:{$line}
==================================================================================

EOF;
            echo $out;
        } elseif (_DEV_) {
            $this->_viewer = Leb_View::getInstance();
            $this->_viewer->setLayoutPath('_template/layout/');
            $this->_viewer->setLayout('exception');
            $this->_viewer->setTemplate($this->_exceptionFile);
            $this->_viewer->title = '出错了!';
            $time = date('Y-m-d H:i:s', time());
            $this->_viewer->time = $time;
            $this->_viewer->message = $message;
            $this->_viewer->code = $code;
            $this->_viewer->file = $this->getFile();
            $this->_viewer->line = $this->getLine();
            $this->_viewer->run();
            Leb_Debuger::showVar();
        } elseif (defined('_ER_PAGE_')) {
            $this->_viewer = Leb_View::getInstance();
            $this->_viewer->setLayoutPath('_template/layout/');
            $this->_viewer->setLayout('exception');
            $this->_viewer->setTemplate(_ER_PAGE_);
            $this->_viewer->title = '出错了!';
            $time = date('Y-m-d H:i:s', time());
            $this->_viewer->time = $time;
            $this->_viewer->message = $message;
            $this->_viewer->code = $code;
            $this->_viewer->file = $this->getFile();
            $this->_viewer->line = $this->getLine();
            $this->_viewer->run();
            Leb_Debuger::showVar();
        }
        if (_RUNTIME_) {
            $now = time();
            $file = _RUNTIME_ . date('-Y-m-d', $now);
            $line = date('H:i:s') . "\t" . getClientIp() . "\r\n";
        }
    }
Example #2
0
 /**
  * 初始化运行时间
  *
  */
 protected function __construct()
 {
     self::$_time = self::$_sectionTime = self::getMicroTime();
 }
Example #3
0
 /**
  * 调试变量
  *
  * @param mixed $var
  */
 public function __debug($var)
 {
     Leb_Debuger::debug($var);
 }
 /**
  * 分发过程
  *
  * 可供程序直接跳转
  *
  * @param string $appName
  * @param string $controllerName
  * @param string $actionName
  * @param array  $params 查询参数,相当于post 或 get过来的参数值
  */
 public function dispatch($appName, $controllerName, $actionName, $params = array(), $plugins = null)
 {
     if (empty($plugins)) {
         $plugins = self::getInstance();
     }
     // 找到相关程序并执行
     $classPath = (_CLI_ ? _CMD_ : _APP_) . $appName . "/" . $controllerName . ".php";
     if (!file_exists($classPath)) {
         //如果不存在,则按默认执行
         $page_path = "{$appName}/{$controllerName}/{$actionName}";
         $controllerName = $plugins->getDefaultController();
         $actionName = $plugins->getDefaultAction();
         $classPath = _APP_ . $appName . "/" . $controllerName . ".php";
         if (!file_exists($classPath)) {
             $page_path = "{$page_path}|{$appName}/{$controllerName}/{$actionName}";
             throw new Leb_Exception('Error 404, error page not found!' . $page_path, 404);
         }
         // 转发
         $this->setAppName($appName);
         $this->setControllerName($controllerName);
         $this->setActionName($actionName);
     } else {
         try {
             require_once $classPath;
         } catch (Leb_Exception $e) {
             throw $e;
         }
     }
     // 默认动作如果动作为空
     $controllerClassName = $controllerName . (_CLI_ ? 'Command' : 'Controller');
     $actionFunctionName = $actionName . 'Action';
     // 新建控制器
     $controller = new $controllerClassName($plugins);
     if (!empty($params)) {
         $controller->setParam($params);
     }
     if (!method_exists($controller, $actionFunctionName)) {
         $refc = new ReflectionClass($controllerClassName);
         $mtdc = $refc->getMethod('__call');
         $decl = $mtdc->getDeclaringClass();
         // if ((new ReflectionClass($controllerClassName))->getMethod('__call')->getDeclaringClass()->name == $controllerClassName)
         if ($decl->name == $controllerClassName) {
             // $controller->$actionFunctionName();
             // goon 继续下面的调用,因为我们知道该controller中对此有处理。
         } else {
             throw new Leb_Exception('Page <strong>[' . $actionFunctionName . ']</strong>' . 'not found! The reason cause this error may be Method not exist' . 'in the Controller <strong>[' . $controllerClassName . ']</strong>');
         }
     }
     // 运行类的run方法,主要是用于加载一些共用操作,如layout数据
     $controller->run();
     defined('__FRM_ACTION_BEGIN__') or define('__FRM_ACTION_BEGIN__', microtime(true));
     $beforeMethod = $actionName . 'Before';
     if (method_exists($controller, $beforeMethod)) {
         $controller->{$beforeMethod}();
     }
     $method = new ReflectionMethod($controllerClassName, $actionFunctionName);
     if ($method->getNumberOfParameters() > 0) {
         $this->_act_return = $response = $this->runWithParams($controller, $method, _CLI_ ? $_SERVER['argv'] : $_GET);
     } else {
         $this->_act_return = $response = $controller->{$actionFunctionName}();
     }
     $afterMethod = $actionName . 'After';
     if (method_exists($controller, $afterMethod)) {
         $controller->{$afterMethod}();
     }
     defined('__FRM_ACTION_END__') or define('__FRM_ACTION_END__', microtime(true));
     //显示调试信息
     $request = Leb_Request::getInstance();
     if (!$request->isXmlHttpRequest() && !$request->isFlashRequest) {
         Leb_Debuger::showVar();
     }
     $obj = FirePHP::getInstance(true);
     $obj->info('Response:' . (__FRM_ACTION_END__ - __FRM_ACTION_BEGIN__));
     $obj->info('Framework:' . (__FRM_ACTION_BEGIN__ - __FRM_BEGIN__));
     if (!empty($response) && $response instanceof Leb_Response) {
         $response->run();
     } else {
         //shiling 计划任务forward的返回值
         return $response;
     }
 }
Example #5
0
 /**
  * 数据库调试 记录当前SQL
  * @access protected
  */
 protected function debug()
 {
     // 记录操作结束时间
     if ($this->debug) {
         $runtime = number_format(microtime(TRUE) - $this->beginTime, 6);
         Leb_Debuger::debug(" RunTime:" . $runtime . "s SQL = " . $this->queryStr);
         if ($error = $this->error()) {
             throw new Leb_Exception($error);
         }
     }
 }
/**
 * 调试变量
 *
 * @param mixed $var         调试变量
 * @param boolean $display   是否在浏览器中显示,为false时,输出到信息变量X-LebPHP-Data中
 */
function debug($var, $display = true)
{
    Leb_Debuger::debug($var, $display);
}