Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge f32bec3 into e2f9569
Browse files Browse the repository at this point in the history
  • Loading branch information
franzliedke committed Jun 20, 2015
2 parents e2f9569 + f32bec3 commit a02149e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Response/StringResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ public static function json($data, $status = 200, array $headers = [])
return static::createResponse($json, $status, $headers, 'application/json');
}

/**
* Create an empty response with the given status code.
*
* @param int $status Status code for the response, if any.
* @param array $headers Headers for the response, if any.
* @return Response
*/
public static function blank($status = 200, array $headers = [])
{
return static::createResponse('', $status, $headers);
}

/**
* This class is non-instantiable.
*/
Expand All @@ -71,7 +83,7 @@ private function __construct()
* Create a Response from the provided information.
*
* Creates a Response using a php://temp stream, and writes the provided
* body to the stream; if non content-type header was provided, the given
* body to the stream; if no content-type header was provided, any given
* $contentType is injected for it.
*
* @param string $body
Expand All @@ -80,12 +92,12 @@ private function __construct()
* @param string $contentType
* @return Response
*/
private static function createResponse($body, $status, array $headers, $contentType)
private static function createResponse($body, $status, array $headers, $contentType = null)
{
$response = new Response('php://temp', $status, $headers);
$response->getBody()->write($body);

if ($response->hasHeader('content-type')) {
if ($contentType === null || $response->hasHeader('content-type')) {
return $response;
}

Expand Down

0 comments on commit a02149e

Please sign in to comment.