Пример #1
0
 /**
  * call mode handler
  *
  * @throws Exception
  * @return void
  */
 public function main()
 {
     $modeSettings = $this->config->get('mode', $this->request->getMode());
     if ($modeSettings === null) {
         throw new RuntimeException('mode `' . $this->request->getMode() . '` not applied');
     }
     if (!isset($modeSettings['handler']) || !class_exists($modeSettings['handler'])) {
         throw new RuntimeException('mode `' . $this->request->getMode() . '` is invalid');
     }
     $handler = new $modeSettings['handler']($this->config, $this->request, $modeSettings);
     if (!$handler instanceof AbstractModeHandler) {
         throw new RuntimeException('mode `' . $this->request->getMode() . '` handler `' . $modeSettings['handler'] . '` is not instance of `handler\\mode\\AbstractModeHandler`');
     }
     $handler->handle();
 }
 /**
  * @param  int $code
  * @return AbstractModeHandler this
  */
 protected function error($code)
 {
     if (!HttpConst::isStatus($code)) {
         throw new RuntimeException('unknown HTTP-Status Code `' . $code . '`');
     }
     http_response_code($code);
     # pipe to URL
     if (isset($this->settings['err' . $code . '-pipe'])) {
         $target = new MAPUrl($this->settings['err' . $code . '-pipe'], $this->config);
         if ($target->get() === $this->request->get()) {
             Logger::error('endless pipe-loop (status: `' . $code . '`) - interrupted with HTTP-Status `508`');
             return $this->error(508);
         }
         $this->setLocation(new Url($this->settings['err' . $code . '-pipe']));
         return $this;
     }
     # default error output
     if (defined('peer\\http\\HttpConst::STATUS_' . $code)) {
         $message = constant('peer\\http\\HttpConst::STATUS_' . $code);
     } else {
         $message = 'N/A';
     }
     $this->setContentType('text/plain');
     echo '[' . $code . '] ' . $message;
     return $this;
 }