/** * @param string $filename Local filename to be send. * @param string $name Filename to be shown to client. * @param int $status * @param array $headers */ public function __construct($filename, $name = null, $status = 200, array $headers = []) { if (empty($name)) { $name = basename($filename); } //Forcing default set of headers $headers += ['Content-Disposition' => 'attachment; filename="' . addcslashes($name, '"') . '"', 'Content-Transfer-Encoding' => 'binary', 'Content-Type' => 'application/octet-stream', 'Content-Length' => (string) filesize($filename), 'Expires' => '0', 'Cache-Control' => 'no-cache, must-revalidate', 'Pragma' => 'public']; parent::__construct(fopen($filename, 'rb'), $status, $headers); }
/** * @param ClientException $exception * @param ViewInterface|null $view */ public function __construct(ClientException $exception, ViewInterface $view = null) { $this->exception = $exception; $headers = []; if (!empty($this->view = $view)) { $headers['Content-Type'] = 'text/html'; } //We will write to memory on demand, response can be freely modified until body is touched parent::__construct('php://memory', $exception->getCode(), $headers); }