/** * 获取前端控制器 * * @return RThink_Controller_Front */ protected static function getFrontController() { // Used cache version if found if (null === self::$_front_controller) { class_exists('RThink_Controller_Front', false) || (require 'RThink/Controller/Front.php'); self::$_front_controller = RThink_Controller_Front::getInstance(); } return self::$_front_controller; }
/** * 获取前端控制器 * * @return RThink_Controller_Front */ public function getFrontController() { // Used cache version if found if (null !== $this->_front_controller) { return $this->_front_controller; } class_exists('RThink_Controller_Front', false) || (require 'RThink/Controller/Front.php'); $this->_front_controller = RThink_Controller_Front::getInstance(); return $this->_front_controller; }
/** * 获取指定键值的配置参数 * * @param string $key * @return null string array */ public static function get($key = '') { if ('' != $key) { if (isset(self::$_config_cache[$key])) { return self::$_config_cache[$key]; } } else { if (!empty(self::$_config_struct)) { return self::$_config_struct; } } class_exists('RThink_Controller_Front', false) || (require 'RThink/Controller/Front.php'); $config_file = RThink_Controller_Front::getInstance()->getParam('config_file'); $config_section = RThink_Controller_Front::getInstance()->getParam('config_section'); if (empty(self::$_config_struct)) { include $config_file; self::$_config_struct = ${$config_section}; } if ('' == $key) { return self::$_config_struct; } $key_list = explode('.', $key); foreach ($key_list as $key_node) { if (isset(self::$_config_cache[$key])) { if (!isset(self::$_config_cache[$key][$key_node])) { class_exists('RThink_Config_Exception', false) || (require 'RThink/Config/Exception.php'); throw new RThink_Config_Exception('配置文件节点链{' . $key . '}中[' . $key_node . ']节点不存在'); } self::$_config_cache[$key] = self::$_config_cache[$key][$key_node]; } else { if (!isset(self::$_config_struct[$key_node])) { class_exists('RThink_Config_Exception', false) || (require 'RThink/Config/Exception.php'); throw new RThink_Config_Exception('配置文件节点链{' . $key . '}中[' . $key_node . ']节点不存在'); } self::$_config_cache[$key] = self::$_config_struct[$key_node]; } } return self::$_config_cache[$key]; }
/** * Handle errors and exceptions * * If the 'noErrorHandler' front Controller flag has been set, * returns early. * * @param Zend_Controller_Request_Abstract $request * @return void */ protected function _handleError(RThink_Controller_Request $request, RThink_Controller_Response $response) { $frontController = RThink_Controller_Front::getInstance(); if ($frontController->getParam('noErrorHandler')) { return; } if ($this->_isInsideErrorHandlerLoop) { $exceptions = $response->getException(); if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) { // Exception thrown by error handler; tell the front Controller to throw it $frontController->throwExceptions(true); throw array_pop($exceptions); } } // check for an exception AND allow the error handler Controller the option to forward if ($response->isException() && !$this->_isInsideErrorHandlerLoop) { $this->_isInsideErrorHandlerLoop = true; // Get exception information $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); $exceptions = $response->getException(); $exception = $exceptions[0]; $error->exception = $exception; $exceptionType = get_class($exception); $error->exception = $exception; switch ($exceptionType) { case 'RThink_Controller_Router_Exception': if (404 == $exception->getCode()) { $error->type = self::EXCEPTION_NO_ROUTE; } else { $error->type = self::EXCEPTION_OTHER; } break; case 'RThink_Controller_Dispatcher_Exception': $error->type = self::EXCEPTION_NO_CONTROLLER; break; case 'RThink_Controller_Action_Exception': if (404 == $exception->getCode()) { $error->type = self::EXCEPTION_NO_ACTION; } else { $error->type = self::EXCEPTION_OTHER; } break; default: $error->type = self::EXCEPTION_OTHER; break; } // get a count of the number of exceptions encountered $this->_exceptionCountAtFirstEncounter = count($exceptions); // Keep a copy of the original Request $error->request = clone $request; // Forward to the error handler $request->setParam('error_handler', $error)->setModuleName($this->getErrorHandlerModule())->setControllerName($this->getErrorHandlerController())->setActionName($this->getErrorHandlerAction())->setDispatched(false); } }
/** * Called before RThink_Controller_Front exits its dispatch loop. * * @param RThink_Controller_Request $request * @return void */ public function dispatchLoopShutdown(RThink_Controller_Response $response) { foreach ($this->_plugins as $plugin) { try { $plugin->dispatchLoopShutdown($response); } catch (Exception $e) { if (RThink_Controller_Front::getInstance()->throwExceptions()) { throw new RThink_Exception($e->getMessage() . $e->getTraceAsString(), $e->getCode(), $e); } else { $response->setException($e); } } } }
/** * 获取前端控制器实例 * * @return RThink_Controller_Front */ public function getFrontController() { if (null === $this->_front_controller) { class_exists('RThink_Controller_Front') || (require 'RThink/Controller/Front.php'); $this->_front_controller = RThink_Controller_Front::getInstance(); } return $this->_front_controller; }
<?php /** * app 入口文件 */ header("Content-Type:text/html;Charset=utf-8"); error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE); //app路径 define('APP_PATH', realpath(dirname(__FILE__) . '/../')); //库文件路径 ini_set('include_path', APP_PATH . '/lib'); include 'RThink/Controller/Front.php'; /* {xhproc 测速 */ // include APP_PATH . '/public/xhprof/xhprof_lib/utils/xhprof_lib.php'; // include APP_PATH . '/public/xhprof/xhprof_lib/utils/xhprof_runs.php'; // xhprof_enable(XHPROF_FLAGS_MEMORY); /* xhproc} */ $controller_front = RThink_Controller_Front::getInstance(); $controller_front->throwExceptions(false); $controller_front->setParams(array('config_file' => APP_PATH . '/conf/app.php', 'config_section' => 'development')); $controller_front->dispatch(); /* {xhproc */ // $xhprof_data = xhprof_disable(); // $xhprof_runs = new XHProfRuns_Default(); // $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo"); // echo "性能报告地址===="."<a href=/xhprof/xhprof_html/index.php?run=$run_id&source=xhprof_foo>点击查看报告</a>"; /* xhproc} */