本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::sendContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::sendContent方法的具体用法?PHP Response::sendContent怎么用?PHP Response::sendContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::sendContent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendContent
/**
* 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);
}
示例2: sendContent
/**
* 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());
}
}
示例3: sendContent
/**
* 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);
}
示例4: testSendContent
public function testSendContent()
{
$response = new Response('test response rendering', 200);
ob_start();
$response->sendContent();
$string = ob_get_clean();
$this->assertContains('test response rendering', $string);
}
示例5: deliver
/**
* 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();
}
示例6: filterResponse
/**
* 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);
}
示例7: createResponse
/**
* {@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;
}
示例8: sendContent
/**
* 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);
}
示例9: filterResponse
/**
* 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());
}
示例10: sendContent
/**
* 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();
}
示例11: mapResponse
/**
* 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);
}
示例12: download
/**
*
* @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;
}
示例13: handleBackupAction
/**
* 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;
}