Exemple #1
0
 private function createResponseRedirect($redirect, $request)
 {
     $response = new Response();
     if ($request->isAjax()) {
         $response->setStatusCode(401);
         $response->setHeader('X-Location', $redirect);
     } else {
         $response->redirect($redirect);
     }
     return $response;
 }
Exemple #2
0
 /**
  * Parse view for exception.
  *
  * @param \Exception $exception
  * @since 0.1.0
  */
 private function parseView($exception)
 {
     if (!$this->resources->getEnviorment()->isSilent()) {
         error_log($exception->getMessage() . " " . $exception->getFile() . "(" . $exception->getLine() . ")");
     }
     $response = new Response();
     $response->setStatusCode(500);
     $response->setContent($exception);
     $this->resources->registerResponse($response);
     $presenter = null;
     try {
         $presenter = $this->resources->getPresenter();
     } catch (ResourcesNotRegisteredException $e) {
         $presenter = $this->findPresenter();
     }
     try {
         $request = $this->resources->getRequest();
     } catch (ResourcesNotRegisteredException $e) {
         $requestConfig = new RequestConfig('', '', $this->resources->getEnviorment(), array('route' => '', 'presenter' => array('class' => ''), 'class' => ''));
         if ($this->resources->getEnviorment()->isSilent()) {
             $request = new RequestTest($this->resources->getUrl(), $this->resources->getEnviorment());
             $request->setConfig($requestConfig);
         } else {
             $session = new Session($this->resources->getEnviorment());
             $request = new Request($requestConfig, $this->resources->getUrl(), $session);
         }
         $this->resources->registerRequest($request);
     }
     if ($presenter) {
         $event = new ExecutePresenterEvent($this->resources->getRequest(), $response);
         $this->eventManager->fire('executePresenter', $event);
         $presenter->render($request->getConfig(), $response);
     }
 }
Exemple #3
0
 /**
  * Set headers for range data support.
  *
  * @param \Arbor\Provider\Response $response
  * @param long $fileSize
  * @since 0.1.0
  */
 private function rangeSupport($response, $fileSize)
 {
     try {
         $request = $this->getRequest();
         $range = $request->getHeader('Range');
         $invalidRange = false;
         if (preg_match('/^bytes=([0-9]+)-([0-9]*)$/', $range, $match)) {
             $startRange = $match[1];
             $endRange = $match[2];
             if ($endRange == '' || $endRange > $filesize) {
                 $endRange = $fileSize - 1;
             }
             if ($startRange > $endRange) {
                 $invalidRange = true;
             } else {
                 $response->setHeader('Accept-Ranges', '0-' . $fileSize);
                 $response->setHeader('Content-Range', 'bytes ' . $startRange . '-' . $endRange . '/' . $fileSize);
                 $response->setHeader('content-length', $endRange - $startRange + 1);
                 $response->setStatusCode(206);
             }
         } else {
             $invalidRange = true;
         }
         if ($invalidRange) {
             $response->setStatusCode(416);
             $response->setHeader('Content-Range', 'bytes *-/' . $filesize);
         }
     } catch (HeaderNotFoundException $e) {
         //skipp
     }
 }