/** * 全局异常处理 * 异常有两个来源 * 1. 通过set_exception_handler设置的全局未捕获异常 * 2. 通过Core_App::dispatch()捕获的异常 * @param [type] $e [description] * @return [type] [description] */ public function handleException($e) { $controller = Core_App::getInstance()->controllerObj; $isBaseExp = $e instanceof Exception_Base; $info = array('exp' => get_class($e), 'code' => $e->getCode(), 'msg' => $e->getMessage(), 'expParams' => $isBaseExp ? $e->getParams() : null, 'line' => sprintf('%s:%d', $e->getFile(), $e->getLine()), 'uri' => Comm_Context::getServer('REQUEST_URI'), 'elapse' => sprintf('%.3f', microtime(true) - SYSTEM_START_TIME), 'reqParams' => empty($controller) ? null : $controller->getParams()); Tool_Log::error('request exception, ' . Tool_Json::encode($info)); if ($isBaseExp) { // 异常自身处理过程 $e->handle(); } else { // 默认异常处理过程 $a = new Exception_Base(); $a->__real__ = $e; $a->handle(); } }
public function forward($controller, $action = 'index', $params = array()) { $dispatchInfo = array('controller' => $controller, 'action' => $action, 'params' => $params); Core_App::getInstance()->setDispatchInfo($dispatchInfo)->setDispatched(false); }
<?php define('APP_PATH', dirname(__DIR__) . '/'); define('SYS_PATH', dirname(APP_PATH) . '/System/'); require SYS_PATH . 'Core/App.php'; Core_App::getInstance()->run();
<?php header('Content-Type: text/html; charset=utf-8'); header('Pragma: no-cache'); define('DS', DIRECTORY_SEPARATOR); define('APP_PATH', dirname(__FILE__)); define('SYS_PATH', dirname(APP_PATH) . DS . 'system'); require SYS_PATH . '/bootstrap.php'; Core_App::getInstance()->dispatch();
public static function getParam($name, $default = null) { $controllerParams = Core_App::getInstance()->controllerParams; return isset($controllerParams[$name]) ? $controllerParams[$name] : $default; }