1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bone\Http\Response; |
4
|
|
|
|
5
|
|
|
use Bone\Http\Response; |
6
|
|
|
use Bone\Server\Traits\HasAttributesTrait; |
|
|
|
|
7
|
|
|
use Laminas\Diactoros\Response\InjectContentTypeTrait; |
8
|
|
|
|
9
|
|
|
class HtmlResponse extends Response |
10
|
|
|
{ |
11
|
|
|
use InjectContentTypeTrait; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Create an HTML response. |
15
|
|
|
* |
16
|
|
|
* Produces an HTML response with a Content-Type of text/html and a default |
17
|
|
|
* status of 200. |
18
|
|
|
* |
19
|
|
|
* @param string|StreamInterface $html HTML or stream for the message body. |
|
|
|
|
20
|
|
|
* @param int $status Integer status code for the response; 200 by default. |
21
|
|
|
* @param array $headers Array of headers to use at initialization. |
22
|
|
|
* @throws Exception\InvalidArgumentException if $html is neither a string or stream. |
23
|
|
|
*/ |
24
|
|
|
public function __construct($html, int $status = 200, array $headers = []) |
25
|
|
|
{ |
26
|
|
|
parent::__construct( |
27
|
|
|
$this->createBody($html), |
28
|
|
|
$status, |
29
|
|
|
$this->injectContentType('text/html; charset=utf-8', $headers) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Create the message body. |
35
|
|
|
* |
36
|
|
|
* @param string|StreamInterface $html |
37
|
|
|
* @throws Exception\InvalidArgumentException if $html is neither a string or stream. |
38
|
|
|
*/ |
39
|
|
|
private function createBody($html) : StreamInterface |
40
|
|
|
{ |
41
|
|
|
if ($html instanceof StreamInterface) { |
42
|
|
|
return $html; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (! is_string($html)) { |
|
|
|
|
46
|
|
|
throw new Exception\InvalidArgumentException(sprintf( |
|
|
|
|
47
|
|
|
'Invalid content (%s) provided to %s', |
48
|
|
|
(is_object($html) ? get_class($html) : gettype($html)), |
49
|
|
|
__CLASS__ |
50
|
|
|
)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$body = new Stream('php://temp', 'wb+'); |
|
|
|
|
54
|
|
|
$body->write($html); |
55
|
|
|
$body->rewind(); |
56
|
|
|
return $body; |
57
|
|
|
} |
58
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths