/** * 单例模式 * @param $module * @param null $method * @return null|TXRequest */ public static function create($module, $method = null) { if (NULL === self::$_instance) { self::$_instance = new self($module, $method); } return self::$_instance; }
/** * 执行请求 * @param TXRequest $request * @throws TXException * @return mixed */ private function call(TXRequest $request) { $module = $request->getModule() . 'Action'; $method = $request->getMethod(); $args = $this->getArgs($module, $method); $object = $this->getAction($module, $request); if ($object instanceof TXResponse || $object instanceof TXJSONResponse) { TXEvent::trigger(afterAction, array($request)); return $object; } if ($object instanceof TXAction) { $result = call_user_func_array([$object, $method], $args); TXEvent::trigger(afterAction, array($request)); return $result; } else { throw new TXException(2001, $request->getModule(), 404); } }
/** * shell路由入口 */ public function shellRouter() { global $argv; if (isset($argv[1]) && substr($argv[1], 0, 1) == "-") { array_splice($argv, 1, 0, $this->routerInfo['base_shell']); } $router = isset($argv[1]) ? explode('/', $argv[1]) : [$this->routerInfo['base_shell']]; $module = $router[0]; $method = isset($router[1]) ? $router[1] : 'index'; TXRequest::create($module, $method); }
/** * 获取单例全局量 * @param $name * @return mixed * @throws TXException */ public function __get($name) { switch ($name) { case 'person': return Person::get(); case 'request': return TXRequest::getInstance(); case 'redis': return TXRedis::instance(); case 'memcache': return TXMemcache::instance(); case 'session': return TXSession::instance(); case 'router': case 'cache': $module = 'TX' . ucfirst($name); return TXFactory::create($module); default: throw new TXException(1006, $name); } }