@@ -27,13 +27,13 @@ |
||
27 | 27 | final class PhpMemoryStream extends Stream |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Constructor of the class |
|
32 | - * |
|
33 | - * @param string $mode |
|
34 | - */ |
|
35 | - public function __construct(string $mode = 'r+b') |
|
36 | - { |
|
37 | - parent::__construct(fopen('php://memory', $mode)); |
|
38 | - } |
|
30 | + /** |
|
31 | + * Constructor of the class |
|
32 | + * |
|
33 | + * @param string $mode |
|
34 | + */ |
|
35 | + public function __construct(string $mode = 'r+b') |
|
36 | + { |
|
37 | + parent::__construct(fopen('php://memory', $mode)); |
|
38 | + } |
|
39 | 39 | } |
@@ -28,18 +28,18 @@ |
||
28 | 28 | final class PhpInputStream extends Stream |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Constructor of the class |
|
33 | - */ |
|
34 | - public function __construct() |
|
35 | - { |
|
36 | - $input = fopen('php://input', 'rb'); |
|
37 | - $resource = fopen('php://temp', 'r+b'); |
|
31 | + /** |
|
32 | + * Constructor of the class |
|
33 | + */ |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + $input = fopen('php://input', 'rb'); |
|
37 | + $resource = fopen('php://temp', 'r+b'); |
|
38 | 38 | |
39 | - stream_copy_to_stream($input, $resource); |
|
39 | + stream_copy_to_stream($input, $resource); |
|
40 | 40 | |
41 | - parent::__construct($resource); |
|
41 | + parent::__construct($resource); |
|
42 | 42 | |
43 | - $this->rewind(); |
|
44 | - } |
|
43 | + $this->rewind(); |
|
44 | + } |
|
45 | 45 | } |
@@ -31,30 +31,30 @@ |
||
31 | 31 | final class FileStream extends Stream |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * Constructor of the class |
|
36 | - * |
|
37 | - * @param string $filename |
|
38 | - * @param string $mode |
|
39 | - * |
|
40 | - * @throws RuntimeException |
|
41 | - */ |
|
42 | - public function __construct(string $filename, string $mode) |
|
43 | - { |
|
44 | - try { |
|
45 | - $resource = fopen($filename, $mode); |
|
46 | - } catch (Throwable $e) { |
|
47 | - $resource = false; |
|
48 | - } |
|
49 | - |
|
50 | - if (!is_resource($resource)) { |
|
51 | - throw new RuntimeException(sprintf( |
|
52 | - 'Unable to open the file "%s" in the mode "%s"', |
|
53 | - $filename, |
|
54 | - $mode |
|
55 | - )); |
|
56 | - } |
|
57 | - |
|
58 | - parent::__construct($resource); |
|
59 | - } |
|
34 | + /** |
|
35 | + * Constructor of the class |
|
36 | + * |
|
37 | + * @param string $filename |
|
38 | + * @param string $mode |
|
39 | + * |
|
40 | + * @throws RuntimeException |
|
41 | + */ |
|
42 | + public function __construct(string $filename, string $mode) |
|
43 | + { |
|
44 | + try { |
|
45 | + $resource = fopen($filename, $mode); |
|
46 | + } catch (Throwable $e) { |
|
47 | + $resource = false; |
|
48 | + } |
|
49 | + |
|
50 | + if (!is_resource($resource)) { |
|
51 | + throw new RuntimeException(sprintf( |
|
52 | + 'Unable to open the file "%s" in the mode "%s"', |
|
53 | + $filename, |
|
54 | + $mode |
|
55 | + )); |
|
56 | + } |
|
57 | + |
|
58 | + parent::__construct($resource); |
|
59 | + } |
|
60 | 60 | } |
@@ -35,23 +35,23 @@ |
||
35 | 35 | final class TmpfileStream extends Stream |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * Constructor of the class |
|
40 | - * |
|
41 | - * @throws RuntimeException |
|
42 | - */ |
|
43 | - public function __construct() |
|
44 | - { |
|
45 | - $dirname = sys_get_temp_dir(); |
|
46 | - if (!is_writable($dirname)) { |
|
47 | - throw new RuntimeException('Temporary files directory is not writable'); |
|
48 | - } |
|
49 | - |
|
50 | - $resource = tmpfile(); |
|
51 | - if (!is_resource($resource)) { |
|
52 | - throw new RuntimeException('Temporary file cannot be created or opened'); |
|
53 | - } |
|
54 | - |
|
55 | - parent::__construct($resource); |
|
56 | - } |
|
38 | + /** |
|
39 | + * Constructor of the class |
|
40 | + * |
|
41 | + * @throws RuntimeException |
|
42 | + */ |
|
43 | + public function __construct() |
|
44 | + { |
|
45 | + $dirname = sys_get_temp_dir(); |
|
46 | + if (!is_writable($dirname)) { |
|
47 | + throw new RuntimeException('Temporary files directory is not writable'); |
|
48 | + } |
|
49 | + |
|
50 | + $resource = tmpfile(); |
|
51 | + if (!is_resource($resource)) { |
|
52 | + throw new RuntimeException('Temporary file cannot be created or opened'); |
|
53 | + } |
|
54 | + |
|
55 | + parent::__construct($resource); |
|
56 | + } |
|
57 | 57 | } |
@@ -26,59 +26,59 @@ |
||
26 | 26 | class ServerRequestFactory implements ServerRequestFactoryInterface |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Creates a new request from superglobals variables |
|
31 | - * |
|
32 | - * @param array|null $serverParams |
|
33 | - * @param array|null $queryParams |
|
34 | - * @param array|null $cookieParams |
|
35 | - * @param array|null $uploadedFiles |
|
36 | - * @param array|null $parsedBody |
|
37 | - * |
|
38 | - * @return ServerRequestInterface |
|
39 | - * |
|
40 | - * @link http://php.net/manual/en/language.variables.superglobals.php |
|
41 | - * @link https://www.php-fig.org/psr/psr-15/meta/ |
|
42 | - */ |
|
43 | - public static function fromGlobals( |
|
44 | - ?array $serverParams = null, |
|
45 | - ?array $queryParams = null, |
|
46 | - ?array $cookieParams = null, |
|
47 | - ?array $uploadedFiles = null, |
|
48 | - ?array $parsedBody = null |
|
49 | - ): ServerRequestInterface { |
|
50 | - $serverParams ??= $_SERVER; |
|
51 | - $queryParams ??= $_GET; |
|
52 | - $cookieParams ??= $_COOKIE; |
|
53 | - $uploadedFiles ??= $_FILES; |
|
54 | - $parsedBody ??= $_POST; |
|
29 | + /** |
|
30 | + * Creates a new request from superglobals variables |
|
31 | + * |
|
32 | + * @param array|null $serverParams |
|
33 | + * @param array|null $queryParams |
|
34 | + * @param array|null $cookieParams |
|
35 | + * @param array|null $uploadedFiles |
|
36 | + * @param array|null $parsedBody |
|
37 | + * |
|
38 | + * @return ServerRequestInterface |
|
39 | + * |
|
40 | + * @link http://php.net/manual/en/language.variables.superglobals.php |
|
41 | + * @link https://www.php-fig.org/psr/psr-15/meta/ |
|
42 | + */ |
|
43 | + public static function fromGlobals( |
|
44 | + ?array $serverParams = null, |
|
45 | + ?array $queryParams = null, |
|
46 | + ?array $cookieParams = null, |
|
47 | + ?array $uploadedFiles = null, |
|
48 | + ?array $parsedBody = null |
|
49 | + ): ServerRequestInterface { |
|
50 | + $serverParams ??= $_SERVER; |
|
51 | + $queryParams ??= $_GET; |
|
52 | + $cookieParams ??= $_COOKIE; |
|
53 | + $uploadedFiles ??= $_FILES; |
|
54 | + $parsedBody ??= $_POST; |
|
55 | 55 | |
56 | - return new ServerRequest( |
|
57 | - server_request_protocol_version($serverParams), |
|
58 | - server_request_method($serverParams), |
|
59 | - server_request_uri($serverParams), |
|
60 | - server_request_headers($serverParams), |
|
61 | - new PhpInputStream(), |
|
62 | - $serverParams, |
|
63 | - $queryParams, |
|
64 | - $cookieParams, |
|
65 | - server_request_files($uploadedFiles), |
|
66 | - $parsedBody |
|
67 | - ); |
|
68 | - } |
|
56 | + return new ServerRequest( |
|
57 | + server_request_protocol_version($serverParams), |
|
58 | + server_request_method($serverParams), |
|
59 | + server_request_uri($serverParams), |
|
60 | + server_request_headers($serverParams), |
|
61 | + new PhpInputStream(), |
|
62 | + $serverParams, |
|
63 | + $queryParams, |
|
64 | + $cookieParams, |
|
65 | + server_request_files($uploadedFiles), |
|
66 | + $parsedBody |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * {@inheritdoc} |
|
72 | - */ |
|
73 | - public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface |
|
74 | - { |
|
75 | - return new ServerRequest( |
|
76 | - server_request_protocol_version($serverParams), |
|
77 | - $method, |
|
78 | - $uri, |
|
79 | - server_request_headers($serverParams), |
|
80 | - null, // body |
|
81 | - $serverParams |
|
82 | - ); |
|
83 | - } |
|
70 | + /** |
|
71 | + * {@inheritdoc} |
|
72 | + */ |
|
73 | + public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface |
|
74 | + { |
|
75 | + return new ServerRequest( |
|
76 | + server_request_protocol_version($serverParams), |
|
77 | + $method, |
|
78 | + $uri, |
|
79 | + server_request_headers($serverParams), |
|
80 | + null, // body |
|
81 | + $serverParams |
|
82 | + ); |
|
83 | + } |
|
84 | 84 | } |
@@ -22,52 +22,52 @@ |
||
22 | 22 | interface HeaderInterface extends IteratorAggregate |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Date format according to RFC-822 |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O'; |
|
25 | + /** |
|
26 | + * Date format according to RFC-822 |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O'; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Regular Expression used for a token validation according to RFC-7230 |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - public const RFC7230_TOKEN_REGEX = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/'; |
|
32 | + /** |
|
33 | + * Regular Expression used for a token validation according to RFC-7230 |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + public const RFC7230_TOKEN_REGEX = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Regular Expression used for a field-value validation according to RFC-7230 |
|
41 | - * |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - public const RFC7230_FIELD_VALUE_REGEX = '/^[\x09\x20-\x7E\x80-\xFF]*$/'; |
|
39 | + /** |
|
40 | + * Regular Expression used for a field-value validation according to RFC-7230 |
|
41 | + * |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + public const RFC7230_FIELD_VALUE_REGEX = '/^[\x09\x20-\x7E\x80-\xFF]*$/'; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Regular Expression used for a quoted-string validation according to RFC-7230 |
|
48 | - * |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - public const RFC7230_QUOTED_STRING_REGEX = '/^(?:[\x5C][\x22]|[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF])*$/'; |
|
46 | + /** |
|
47 | + * Regular Expression used for a quoted-string validation according to RFC-7230 |
|
48 | + * |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + public const RFC7230_QUOTED_STRING_REGEX = '/^(?:[\x5C][\x22]|[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF])*$/'; |
|
52 | 52 | |
53 | - /** |
|
54 | - * Gets the header field name |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function getFieldName(): string; |
|
53 | + /** |
|
54 | + * Gets the header field name |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function getFieldName(): string; |
|
59 | 59 | |
60 | - /** |
|
61 | - * Gets the header field value |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getFieldValue(): string; |
|
60 | + /** |
|
61 | + * Gets the header field value |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getFieldValue(): string; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Converts the header to a field |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function __toString(): string; |
|
67 | + /** |
|
68 | + * Converts the header to a field |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function __toString(): string; |
|
73 | 73 | } |
@@ -28,14 +28,14 @@ |
||
28 | 28 | final class PhpTempStream extends Stream |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Constructor of the class |
|
33 | - * |
|
34 | - * @param string $mode |
|
35 | - * @param int<0, max> $maxmemory |
|
36 | - */ |
|
37 | - public function __construct(string $mode = 'r+b', int $maxmemory = 2097152) |
|
38 | - { |
|
39 | - parent::__construct(fopen(sprintf('php://temp/maxmemory:%d', $maxmemory), $mode)); |
|
40 | - } |
|
31 | + /** |
|
32 | + * Constructor of the class |
|
33 | + * |
|
34 | + * @param string $mode |
|
35 | + * @param int<0, max> $maxmemory |
|
36 | + */ |
|
37 | + public function __construct(string $mode = 'r+b', int $maxmemory = 2097152) |
|
38 | + { |
|
39 | + parent::__construct(fopen(sprintf('php://temp/maxmemory:%d', $maxmemory), $mode)); |
|
40 | + } |
|
41 | 41 | } |
@@ -32,30 +32,30 @@ |
||
32 | 32 | final class TempFileStream extends Stream |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Constructor of the class |
|
37 | - * |
|
38 | - * @param string $prefix |
|
39 | - * |
|
40 | - * @throws RuntimeException |
|
41 | - */ |
|
42 | - public function __construct(string $prefix = '') |
|
43 | - { |
|
44 | - $dirname = sys_get_temp_dir(); |
|
45 | - if (!is_writable($dirname)) { |
|
46 | - throw new RuntimeException('Temporary files directory is not writable'); |
|
47 | - } |
|
48 | - |
|
49 | - $filename = tempnam($dirname, $prefix); |
|
50 | - if ($filename === false) { |
|
51 | - throw new RuntimeException('Temporary file name cannot be generated'); |
|
52 | - } |
|
53 | - |
|
54 | - $resource = fopen($filename, 'w+b'); |
|
55 | - if (!is_resource($resource)) { |
|
56 | - throw new RuntimeException('Temporary file cannot be created or opened'); |
|
57 | - } |
|
58 | - |
|
59 | - parent::__construct($resource); |
|
60 | - } |
|
35 | + /** |
|
36 | + * Constructor of the class |
|
37 | + * |
|
38 | + * @param string $prefix |
|
39 | + * |
|
40 | + * @throws RuntimeException |
|
41 | + */ |
|
42 | + public function __construct(string $prefix = '') |
|
43 | + { |
|
44 | + $dirname = sys_get_temp_dir(); |
|
45 | + if (!is_writable($dirname)) { |
|
46 | + throw new RuntimeException('Temporary files directory is not writable'); |
|
47 | + } |
|
48 | + |
|
49 | + $filename = tempnam($dirname, $prefix); |
|
50 | + if ($filename === false) { |
|
51 | + throw new RuntimeException('Temporary file name cannot be generated'); |
|
52 | + } |
|
53 | + |
|
54 | + $resource = fopen($filename, 'w+b'); |
|
55 | + if (!is_resource($resource)) { |
|
56 | + throw new RuntimeException('Temporary file cannot be created or opened'); |
|
57 | + } |
|
58 | + |
|
59 | + parent::__construct($resource); |
|
60 | + } |
|
61 | 61 | } |
@@ -32,51 +32,51 @@ |
||
32 | 32 | final class HtmlResponse extends Response |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Constructor of the class |
|
37 | - * |
|
38 | - * @param int $statusCode |
|
39 | - * @param mixed $html |
|
40 | - * |
|
41 | - * @throws InvalidArgumentException |
|
42 | - */ |
|
43 | - public function __construct(int $statusCode, $html) |
|
44 | - { |
|
45 | - parent::__construct($statusCode); |
|
35 | + /** |
|
36 | + * Constructor of the class |
|
37 | + * |
|
38 | + * @param int $statusCode |
|
39 | + * @param mixed $html |
|
40 | + * |
|
41 | + * @throws InvalidArgumentException |
|
42 | + */ |
|
43 | + public function __construct(int $statusCode, $html) |
|
44 | + { |
|
45 | + parent::__construct($statusCode); |
|
46 | 46 | |
47 | - $this->setBody($this->createBody($html)); |
|
47 | + $this->setBody($this->createBody($html)); |
|
48 | 48 | |
49 | - $this->setHeader('Content-Type', 'text/html; charset=utf-8'); |
|
50 | - } |
|
49 | + $this->setHeader('Content-Type', 'text/html; charset=utf-8'); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Creates the response body from the given HTML data |
|
54 | - * |
|
55 | - * @param mixed $html |
|
56 | - * |
|
57 | - * @return StreamInterface |
|
58 | - * |
|
59 | - * @throws InvalidArgumentException |
|
60 | - */ |
|
61 | - private function createBody($html): StreamInterface |
|
62 | - { |
|
63 | - if ($html instanceof StreamInterface) { |
|
64 | - return $html; |
|
65 | - } |
|
52 | + /** |
|
53 | + * Creates the response body from the given HTML data |
|
54 | + * |
|
55 | + * @param mixed $html |
|
56 | + * |
|
57 | + * @return StreamInterface |
|
58 | + * |
|
59 | + * @throws InvalidArgumentException |
|
60 | + */ |
|
61 | + private function createBody($html): StreamInterface |
|
62 | + { |
|
63 | + if ($html instanceof StreamInterface) { |
|
64 | + return $html; |
|
65 | + } |
|
66 | 66 | |
67 | - if (is_object($html) && method_exists($html, '__toString')) { |
|
68 | - /** @var string */ |
|
69 | - $html = $html->__toString(); |
|
70 | - } |
|
67 | + if (is_object($html) && method_exists($html, '__toString')) { |
|
68 | + /** @var string */ |
|
69 | + $html = $html->__toString(); |
|
70 | + } |
|
71 | 71 | |
72 | - if (!is_string($html)) { |
|
73 | - throw new InvalidArgumentException('Unable to create HTML response due to unexpected HTML data'); |
|
74 | - } |
|
72 | + if (!is_string($html)) { |
|
73 | + throw new InvalidArgumentException('Unable to create HTML response due to unexpected HTML data'); |
|
74 | + } |
|
75 | 75 | |
76 | - $stream = new PhpTempStream('r+b'); |
|
77 | - $stream->write($html); |
|
78 | - $stream->rewind(); |
|
76 | + $stream = new PhpTempStream('r+b'); |
|
77 | + $stream->write($html); |
|
78 | + $stream->rewind(); |
|
79 | 79 | |
80 | - return $stream; |
|
81 | - } |
|
80 | + return $stream; |
|
81 | + } |
|
82 | 82 | } |