Skip to content

Commit 7201362

Browse files
Improved custom responses performance
1 parent 11e2bdb commit 7201362

File tree

5 files changed

+3
-63
lines changed

5 files changed

+3
-63
lines changed

src/Response/HtmlResponse.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,22 @@
1818
namespace Biurad\Http\Response;
1919

2020
use Biurad\Http\Response;
21-
use Biurad\Http\Traits\InjectContentTypeTrait;
22-
use Biurad\Http\Exception;
2321
use Psr\Http\Message\StreamInterface;
2422

2523
/**
2624
* HTML response with Content-Type header to text/html.
2725
*/
2826
class HtmlResponse extends Response
2927
{
30-
use InjectContentTypeTrait;
31-
3228
/**
3329
* Produces an HTML response with a Content-Type of text/html and a default status of 200.
3430
*
3531
* @param StreamInterface|string $html HTML or stream for the message body
3632
* @param int $status integer status code for the response; 200 by default
3733
* @param array $headers array of headers to use at initialization
38-
*
39-
* @throws Exception\InvalidArgumentException if $html is neither a string or stream
4034
*/
4135
public function __construct($html, int $status = 200, array $headers = [])
4236
{
43-
parent::__construct($status, $this->injectContentType('text/html; charset=utf-8', $headers), $html);
37+
parent::__construct($status, ['content-type' => ['text/html; charset=utf-8']] + $headers, $html);
4438
}
4539
}

src/Response/JsonResponse.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
use Biurad\Http\Response;
2121
use Biurad\Http\Exception;
22-
use Biurad\Http\Traits\InjectContentTypeTrait;
2322
use Symfony\Component\HttpFoundation\JsonResponse as HttpFoundationJsonResponse;
2423
use Symfony\Component\HttpFoundation\Response as HttpFoundationResponse;
2524

@@ -28,8 +27,6 @@
2827
*/
2928
class JsonResponse extends Response
3029
{
31-
use InjectContentTypeTrait;
32-
3330
/**
3431
* Create a JSON response with the given data.
3532
*

src/Response/TextResponse.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,22 @@
1818
namespace Biurad\Http\Response;
1919

2020
use Biurad\Http\Response;
21-
use Biurad\Http\Traits\InjectContentTypeTrait;
22-
use Biurad\Http\Exception;
2321
use Psr\Http\Message\StreamInterface;
2422

2523
/**
2624
* Plain text response with Content-Type header to text/plain.
2725
*/
2826
class TextResponse extends Response
2927
{
30-
use InjectContentTypeTrait;
31-
3228
/**
3329
* Produces a text response with a Content-Type of text/plain and a default status of 200.
3430
*
3531
* @param StreamInterface|string $text string or stream for the message body
3632
* @param int $status integer status code for the response; 200 by default
3733
* @param array $headers array of headers to use at initialization
38-
*
39-
* @throws Exception\InvalidArgumentException if $text is neither a string or stream
4034
*/
4135
public function __construct($text, int $status = 200, array $headers = [])
4236
{
43-
parent::__construct($status, $this->injectContentType('text/plain; charset=utf-8', $headers), $text);
37+
parent::__construct($status, ['content-type' => ['text/plain; charset=utf-8']] + $headers, $text);
4438
}
4539
}

src/Response/XmlResponse.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,22 @@
1818
namespace Biurad\Http\Response;
1919

2020
use Biurad\Http\Response;
21-
use Biurad\Http\Traits\InjectContentTypeTrait;
22-
use Biurad\Http\Exception;
2321
use Psr\Http\Message\StreamInterface;
2422

2523
/**
2624
* XML response with Content-Type header to application/xml.
2725
*/
2826
class XmlResponse extends Response
2927
{
30-
use InjectContentTypeTrait;
31-
3228
/**
3329
* Produces an XML response with a Content-Type of application/xml and a default status of 200.
3430
*
3531
* @param StreamInterface|string $xml string or stream for the message body
3632
* @param int $status integer status code for the response; 200 by default
3733
* @param array $headers array of headers to use at initialization
38-
*
39-
* @throws Exception\InvalidArgumentException if $text is neither a string or stream
4034
*/
4135
public function __construct($xml, int $status = 200, array $headers = [])
4236
{
43-
parent::__construct($status, $this->injectContentType('application/xml; charset=utf-8', $headers), $xml);
37+
parent::__construct($status, ['content-type' => ['application/xml; charset=utf-8']] + $headers, $xml);
4438
}
4539
}

src/Traits/InjectContentTypeTrait.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)