Example #1
0
 /**
  * @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;
         }
     }
 }
Example #2
0
 /**
  * Constructor
  */
 public function __construct()
 {
     if (isset(self::$singleton) && !IS_CLI) {
         throw new NotSingletonException(get_called_class());
     }
     self::$singleton = TRUE;
     self::init();
 }
Example #3
0
 public function request()
 {
     return Request::singleton();
 }