public function render(RequestConfig $config, Response $response) { header('HTTP/1.1 ' . $response->getStatusCode() . ' ' . $response->getStatusMessage()); foreach ($response->getHeaders() as $name => $value) { header($name . ': ' . $value); } if ($response->getStatusCode() < 299) { $startRange = 0; $endRange = filesize($response->getContent()) - 1; try { $contentRange = $response->getHeader('Content-Range'); if (preg_match('/^bytes ([0-9]+)-([0-9]+)\\/([0-9]+)$/', $contentRange, $match)) { $startRange = (int) $match[1]; $endRange = (int) $match[2]; } } catch (HeaderNotFoundException $e) { //skipp } $buffer = 1024 * 8; $file = @fopen($response->getContent(), 'rb'); fseek($file, $startRange); while (!feof($file) && ($p = ftell($file)) <= $endRange) { if ($p + $buffer > $endRange) { $buffer = $endRange - $p + 1; } set_time_limit(0); echo fread($file, $buffer); flush(); } fclose($file); } }
public function render(RequestConfig $config, Response $response) { if (!$config->isSilent()) { header('HTTP/1.1 ' . $response->getStatusCode() . ' ' . $response->getStatusMessage()); } foreach ($response->getHeaders() as $name => $value) { header($name . ': ' . $value); } echo (string) $response->getContent(); }
private function renderFail(Response $response) { if (!$this->config->isSilent()) { header('HTTP/1.1 ' . $response->getStatusCode() . ' ' . $response->getStatusMessage()); } if ($response->getContent() instanceof \Exception) { $exception = $response->getContent(); $message = 'Błąd wewnętrzny!'; if ($exception instanceof \Arbor\Core\Exception) { $message = $exception->getSafeMessage(); } if ($this->config->isDebug()) { $message = $exception->getMessage(); } $data = array('code' => $exception->getCode(), 'message' => $message); if ($this->config->isDebug()) { $data = array_merge($data, array('file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString(), 'exception' => get_class($exception))); } echo json_encode($data); } }
public function render(RequestConfig $requestConfig, Response $response) { $this->config = $requestConfig; if (!$requestConfig->isSilent()) { header('HTTP/1.1 ' . $response->getStatusCode() . ' ' . $response->getStatusMessage()); } switch ($response->getStatusCode()) { case 300: case 301: case 302: case 303: case 305: case 307: $this->redirect($response); break; default: if ($response->getStatusCode() >= 400) { $this->displayError($response); } else { $this->displaySuccess($response); } } }