Esempio n. 1
0
 /**
  * @return \Swilab\Exception\Manager
  */
 public static function getDefault()
 {
     if (static::$instance) {
         return static::$instance;
     }
     static::$instance = new self();
     static::$instance->setDI(Swilab::getDI());
     return static::$instance;
 }
Esempio n. 2
0
 public function __construct($message = '', $code = 0, \Exception $previous = null, $level = self::WARNING, $automaticLog = null, $logName = null)
 {
     parent::__construct($message, $code, $previous);
     $this->level = $level;
     $this->logName = $logName ?: static::$defaultLogName;
     false !== $automaticLog && static::$automaticLog and ExceptionManager::getDefault()->addException($this);
 }
Esempio n. 3
0
 public function handle($uri = null)
 {
     $this->router->handle();
     $this->dispatcher->setNamespaceName($this->router->getNamespaceName());
     $this->dispatcher->setControllerName($this->router->getControllerName());
     $this->dispatcher->setActionName($this->router->getActionName());
     $this->dispatcher->setParams($this->router->getParams());
     $this->view->start();
     try {
         $this->dispatcher->dispatch();
     } catch (\Exception $exception) {
         if (!$exception instanceof Exception) {
             ExceptionManager::getDefault()->addException($exception);
         }
         switch ($exception->getCode()) {
             case Dispatcher::EXCEPTION_FORBIDDEN:
                 $this->{$dispatcher}->forward($this->router->getForbidden());
                 break;
             case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
             case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
             case Dispatcher::EXCEPTION_NOT_FOUND:
                 $this->{$dispatcher}->forward($this->router->getNotFound());
                 break;
             case Dispatcher::EXCEPTION_SERVER_ERROR:
             default:
                 $this->dispatcher->forward($this->router->getServerError());
         }
         $this->dispatcher->dispatch();
     }
     $possibleResponse = $this->dispatcher->getReturnedValue();
     $returnedResponse = $possibleResponse instanceof ResponseInterface;
     if (!$returnedResponse) {
         $this->view->render($this->dispatcher->getControllerName(), $this->dispatcher->getActionName(), $this->dispatcher->getParams());
     }
     $this->view->finish();
     if (!$returnedResponse) {
         $this->response->setContent($this->view->getContent());
     }
     $this->response->sendHeaders();
     $this->response->sendCookies();
     if ($this->config->get('app.log.enable', false)) {
         ExceptionManager::getDefault()->handle();
     }
     return $this->response;
 }
Esempio n. 4
0
 protected function registerException()
 {
     return ExceptionManager::getDefault();
 }