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); } }
private function displayError(Response $response) { $presenterConfig = $this->config->getPresenter(); \Twig_Autoloader::register(); $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../../template'); //TODO przekazywać do presentera config $twig = new \Twig_Environment($loader); $exception = $response->getContent(); $data = array('statusCode' => $response->getStatusCode(), 'message' => $exception->getMessage(), 'exception' => get_class($exception), 'file' => $exception->getFile(), 'line' => $exception->getLine()); if ($this->config->isDebug()) { echo $twig->render('error.twig', $data); } else { echo $twig->render($response->getStatusCode() . '.twig'); } }
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); } }