/** * @param Request $request * @param Response $response */ public function render(Request $request, Response $response) { if (!$this->environment->isSilent()) { 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); } }
/** * @param Response $response */ private function redirect(Response $response) { if ($this->environment->isSilent()) { return; } header('Location: ' . $response->getHeader('location')); }
/** * * @param Environment $environment */ public function __construct(Environment $environment) { if (!$environment->isSilent()) { session_start(); $this->id = session_id(); } else { //test $this->id = mt_rand(1, 10000000); } }