/** * fire * run controller as module. * * @param string segment * * @return string output */ public static function fire($requestSegment, $print = true) { $request = preg_split('/\\//', $requestSegment, -1, PREG_SPLIT_NO_EMPTY); $method = 'action' . str_replace(' ', '', ucwords(str_replace('-', ' ', $request))); if (!self::hasMethod($method)) { return false; } $classname = self::classname(); try { $controller = isset(self::$loadedControllers[$classname]) ? self::$loadedControllers[$classname] : self::createInstance(); $ref = new ReflectionMethod($classname, $method); $output = $ref->invokeArgs($controller, $request); if (!is_null($output)) { if (true !== $print) { return $output; } echo $output; return true; } } catch (ReflectionException $e) { Debugger::handleException($e); } }
/** * run * execute or running the application. */ public function run() { $this->dispatcher->dispatch(Http\Request::createFromGlobals(), Configure::read('url_suffix')); $handler = $this->dispatcher->fetchHandler(); if (empty($handler)) { throw new Exception('handler does not found'); } try { $reflection = new ReflectionFunction($handler); $output = $reflection->invoke($this->dispatcher->fetchParams()); $this->response->send($output); } catch (ReflectionException $e) { Debugger::handleException($e); } }