/** * 入口点 */ function run() { $response = new response(); $cacheConfig = config('cache'); if ($cacheConfig['cache']) { $cache = cache::getInstance($cacheConfig); $content = $cache->check($this->http->url()); if (!empty($content)) { $response->setBody($content); $response->send(); } } try { $handler = $this->parseUrl(); if (is_array($handler)) { list($control, $action) = $handler; $path = ROOT . '/application/control/' . $control . '.php'; if (file_exists($path)) { include $path; $class = 'application\\control\\' . $control . 'Control'; if (class_exists($class)) { //$class = new \ReflectionClass($class); $class = new $class(); $class->response =& $response; if (method_exists($class, $action) && is_callable(array($class, $action)) || method_exists($class, '__call')) { $response->setCode(200); $response->setBody($this->__200($class, $action)); } else { $response->setCode(404); $response->setBody($this->__404($control, $action)); } } else { $response->setCode(404); $response->setBody($this->__404($control, $action)); } } else { $response->setCode(404); $response->setBody($this->__404($control, $action)); } } else { include ROOT . '/application/thread/' . $handler . '.php'; $class = 'application\\thread\\' . $handler . 'Thread'; $class = new $class(); $class->run(); } } catch (\Exception $e) { $response->setCode(500); $response->setBody($this->__500($e)); } finally { $response->send(); } }