/** * @param \Haf\Request|null $request * @throws \Haf\Exception */ public function dispatch(Request $request = null) { if (null === $request) { $this->request = Request::singleton(); } else { $this->request = $request; } while ($this->request->getDispatched() === false) { $this->request->setDispatched(true); $controller = $this->getController(); try { $obj = new $controller($this->request); if (!$obj instanceof Action) { $message = "Controller: {$controller} is not an instance of Haf/Action."; throw new Exception($message, Exception::ERRNO_INSTANCE_NOT_EXTENDS_ACTION); } $action = $this->getAction(); try { $obj->dispatch($action); } catch (Exception $e) { throw $e; } $obj = null; } catch (Exception $e) { throw $e; } } }
/** * Constructor */ public function __construct() { if (isset(self::$singleton) && !IS_CLI) { throw new NotSingletonException(get_called_class()); } self::$singleton = TRUE; self::init(); }
public function request() { return Request::singleton(); }