/** * Sends the file. */ public function sendContent() { if (!$this->isSuccessful()) { parent::sendContent(); return; } $outStream = fopen('php://output', 'wb'); $fileStream = $this->file->readStream(); stream_copy_to_stream($fileStream, $outStream); fclose($outStream); fclose($fileStream); }
/** * Sends content for the current web response. * * @param ReactResponse $response * @param SymfonyResponse $sf_response */ private function sendContent(ReactResponse $response, SymfonyResponse $sf_response) { if ($sf_response instanceof StreamedResponse || $sf_response instanceof BinaryFileResponse) { ob_start(function ($buffer) use($response) { $response->write($buffer); }); $sf_response->sendContent(); ob_get_clean(); $response->end(); } else { $response->end($sf_response->getContent()); } }
/** * Sends the file. */ public function sendContent() { if (!$this->isSuccessful()) { parent::sendContent(); return; } if (0 === $this->maxlen) { return; } $out = fopen('php://output', 'wb'); $file = fopen($this->file->getPathname(), 'rb'); stream_copy_to_stream($file, $out, $this->maxlen, $this->offset); fclose($out); fclose($file); }
public function testSendContent() { $response = new Response('test response rendering', 200); ob_start(); $response->sendContent(); $string = ob_get_clean(); $this->assertContains('test response rendering', $string); }
/** * Delivers the Response as a string. * * When the Response is a StreamedResponse, the content is streamed immediately * instead of being returned. * * @param Response $response A Response instance * * @return string|null The Response content or null when the Response is streamed * * @throws \RuntimeException when the Response is not successful */ protected function deliver(Response $response) { if (!$response->isSuccessful()) { throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->requests[0]->getUri(), $response->getStatusCode())); } if (!$response instanceof StreamedResponse) { return $response->getContent(); } $response->sendContent(); }
/** * Converts the HttpKernel response to a BrowserKit response. * * @param Response $response A Response instance * * @return DomResponse A DomResponse instance */ protected function filterResponse($response) { $headers = $response->headers->all(); if ($response->headers->getCookies()) { $cookies = array(); foreach ($response->headers->getCookies() as $cookie) { $cookies[] = new DomCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } $headers['Set-Cookie'] = $cookies; } // this is needed to support StreamedResponse ob_start(); $response->sendContent(); $content = ob_get_clean(); return new DomResponse($content, $response->getStatusCode(), $headers); }
/** * {@inheritdoc} */ public function createResponse(Response $symfonyResponse) { if ($symfonyResponse instanceof BinaryFileResponse) { $stream = new DiactorosStream($symfonyResponse->getFile()->getPathname(), 'r'); } else { $stream = new DiactorosStream('php://temp', 'wb+'); if ($symfonyResponse instanceof StreamedResponse) { ob_start(function ($buffer) use($stream) { $stream->write($buffer); return false; }); $symfonyResponse->sendContent(); ob_end_clean(); } else { $stream->write($symfonyResponse->getContent()); } } $headers = $symfonyResponse->headers->all(); $cookies = $symfonyResponse->headers->getCookies(); if (!empty($cookies)) { $headers['Set-Cookie'] = array(); foreach ($cookies as $cookie) { $headers['Set-Cookie'][] = $cookie->__toString(); } } $response = new DiactorosResponse($stream, $symfonyResponse->getStatusCode(), $headers); $protocolVersion = $symfonyResponse->getProtocolVersion(); if ('1.1' !== $protocolVersion) { $response = $response->withProtocolVersion($protocolVersion); } return $response; }
/** * Sends the file. */ public function sendContent() { if (!$this->isSuccessful()) { parent::sendContent(); return; } if (0 === $this->maxlen) { return; } $out = fopen('php://output', 'wb'); $in = $this->ioService->getFileInputStream($this->file); stream_copy_to_stream($in, $out, $this->maxlen, $this->offset); fclose($out); }
/** * Converts the HttpKernel response to a BrowserKit response. * * @param Response $response A Response instance * * @return DomResponse A DomResponse instance */ protected function filterResponse($response) { // this is needed to support StreamedResponse ob_start(); $response->sendContent(); $content = ob_get_clean(); return new DomResponse($content, $response->getStatusCode(), $response->headers->all()); }
/** * Allow Tlog to write log stuff in the fina content. * * @see \Thelia\Core\HttpFoundation\Response::sendContent() */ public function sendContent() { Tlog::getInstance()->write($this->content); parent::sendContent(); }
/** * Convert Symfony\Component\HttpFoundation\Response to React\Http\Response * * @param ReactResponse $reactResponse * @param SymfonyResponse $syResponse */ protected static function mapResponse(ReactResponse $reactResponse, SymfonyResponse $syResponse) { $headers = $syResponse->headers->all(); $reactResponse->writeHead($syResponse->getStatusCode(), $headers); // @TODO convert StreamedResponse in an async manner if ($syResponse instanceof SymfonyStreamedResponse) { ob_start(); $syResponse->sendContent(); $content = ob_get_contents(); ob_end_clean(); } else { $content = $syResponse->getContent(); } $reactResponse->end($content); }
/** * * @return \Symfony\Component\HttpFoundation\Response */ public function download() { $response = new Response($this->_data, 200, array('Content-Type' => 'text/plain', 'Content-Disposition' => 'attachment; filename="' . $this->getFilename() . '"')); $response->sendHeaders(); $response->sendContent(); $this->_incrementFileIndex(); return $response; }
/** * Handle and execute backup of connection * * @Route("/backup/{key}", name="handleBackup") * * @param int $key key of connected device * @return \Symfony\Component\HttpFoundation\Response */ public function handleBackupAction($key) { $dataClass = $this->get('DataModel'); $params = array('key' => $key, 'filter' => ''); $res = $dataClass->handle('backup', $params, false); $resp = new Response(); $resp->setStatusCode(200); $resp->headers->set('Cache-Control', 'private'); $resp->headers->set('Content-Length', strlen($res)); $resp->headers->set('Content-Type', 'application/force-download'); $resp->headers->set('Content-Disposition', sprintf('attachment; filename="%s-%s.xml"', date("Y-m-d"), $dataClass->getHostFromKey($key))); $resp->sendHeaders(); $resp->setContent($res); $resp->sendContent(); die; }