@@ -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 = $serverParams ?? $_SERVER; |
|
| 51 | - $queryParams = $queryParams ?? $_GET; |
|
| 52 | - $cookieParams = $cookieParams ?? $_COOKIE; |
|
| 53 | - $uploadedFiles = $uploadedFiles ?? $_FILES; |
|
| 54 | - $parsedBody = $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 = $serverParams ?? $_SERVER; |
|
| 51 | + $queryParams = $queryParams ?? $_GET; |
|
| 52 | + $cookieParams = $cookieParams ?? $_COOKIE; |
|
| 53 | + $uploadedFiles = $uploadedFiles ?? $_FILES; |
|
| 54 | + $parsedBody = $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 | } |
@@ -27,35 +27,35 @@ |
||
| 27 | 27 | class StreamFactory implements StreamFactoryInterface |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * {@inheritdoc} |
|
| 32 | - */ |
|
| 33 | - public function createStream(string $content = ''): StreamInterface |
|
| 34 | - { |
|
| 35 | - $stream = new PhpTempStream(); |
|
| 36 | - if ($content === '') { |
|
| 37 | - return $stream; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $stream->write($content); |
|
| 41 | - $stream->rewind(); |
|
| 42 | - |
|
| 43 | - return $stream; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * {@inheritdoc} |
|
| 48 | - */ |
|
| 49 | - public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface |
|
| 50 | - { |
|
| 51 | - return new FileStream($filename, $mode); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * {@inheritdoc} |
|
| 56 | - */ |
|
| 57 | - public function createStreamFromResource($resource): StreamInterface |
|
| 58 | - { |
|
| 59 | - return new Stream($resource); |
|
| 60 | - } |
|
| 30 | + /** |
|
| 31 | + * {@inheritdoc} |
|
| 32 | + */ |
|
| 33 | + public function createStream(string $content = ''): StreamInterface |
|
| 34 | + { |
|
| 35 | + $stream = new PhpTempStream(); |
|
| 36 | + if ($content === '') { |
|
| 37 | + return $stream; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $stream->write($content); |
|
| 41 | + $stream->rewind(); |
|
| 42 | + |
|
| 43 | + return $stream; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * {@inheritdoc} |
|
| 48 | + */ |
|
| 49 | + public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface |
|
| 50 | + { |
|
| 51 | + return new FileStream($filename, $mode); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * {@inheritdoc} |
|
| 56 | + */ |
|
| 57 | + public function createStreamFromResource($resource): StreamInterface |
|
| 58 | + { |
|
| 59 | + return new Stream($resource); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -25,11 +25,11 @@ |
||
| 25 | 25 | class UriFactory implements UriFactoryInterface |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - */ |
|
| 31 | - public function createUri(string $uri = ''): UriInterface |
|
| 32 | - { |
|
| 33 | - return new Uri($uri); |
|
| 34 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + */ |
|
| 31 | + public function createUri(string $uri = ''): UriInterface |
|
| 32 | + { |
|
| 33 | + return new Uri($uri); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -26,26 +26,26 @@ |
||
| 26 | 26 | interface HeaderInterface extends IteratorAggregate |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Gets the header field name |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function getFieldName(): string; |
|
| 29 | + /** |
|
| 30 | + * Gets the header field name |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function getFieldName(): string; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Gets the header field value |
|
| 38 | - * |
|
| 39 | - * @return string |
|
| 40 | - */ |
|
| 41 | - public function getFieldValue(): string; |
|
| 36 | + /** |
|
| 37 | + * Gets the header field value |
|
| 38 | + * |
|
| 39 | + * @return string |
|
| 40 | + */ |
|
| 41 | + public function getFieldValue(): string; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Converts the header field to a string |
|
| 45 | - * |
|
| 46 | - * @link http://php.net/manual/en/language.oop5.magic.php#object.tostring |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function __toString(): string; |
|
| 43 | + /** |
|
| 44 | + * Converts the header field to a string |
|
| 45 | + * |
|
| 46 | + * @link http://php.net/manual/en/language.oop5.magic.php#object.tostring |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function __toString(): string; |
|
| 51 | 51 | } |
@@ -25,11 +25,11 @@ |
||
| 25 | 25 | class RequestFactory implements RequestFactoryInterface |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - */ |
|
| 31 | - public function createRequest(string $method, $uri): RequestInterface |
|
| 32 | - { |
|
| 33 | - return new Request($method, $uri); |
|
| 34 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + */ |
|
| 31 | + public function createRequest(string $method, $uri): RequestInterface |
|
| 32 | + { |
|
| 33 | + return new Request($method, $uri); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -31,53 +31,53 @@ |
||
| 31 | 31 | final class Scheme implements ComponentInterface |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Regular expression to validate the component value |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private const VALIDATE_REGEX = '/^(?:[A-Za-z][0-9A-Za-z\+\-\.]*)?$/'; |
|
| 34 | + /** |
|
| 35 | + * Regular expression to validate the component value |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private const VALIDATE_REGEX = '/^(?:[A-Za-z][0-9A-Za-z\+\-\.]*)?$/'; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The component value |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - private string $value = ''; |
|
| 41 | + /** |
|
| 42 | + * The component value |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + private string $value = ''; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Constructor of the class |
|
| 50 | - * |
|
| 51 | - * @param mixed $value |
|
| 52 | - * |
|
| 53 | - * @throws InvalidUriComponentException |
|
| 54 | - * If the component isn't valid. |
|
| 55 | - */ |
|
| 56 | - public function __construct($value) |
|
| 57 | - { |
|
| 58 | - if ($value === '') { |
|
| 59 | - return; |
|
| 60 | - } |
|
| 48 | + /** |
|
| 49 | + * Constructor of the class |
|
| 50 | + * |
|
| 51 | + * @param mixed $value |
|
| 52 | + * |
|
| 53 | + * @throws InvalidUriComponentException |
|
| 54 | + * If the component isn't valid. |
|
| 55 | + */ |
|
| 56 | + public function __construct($value) |
|
| 57 | + { |
|
| 58 | + if ($value === '') { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - if (!is_string($value)) { |
|
| 63 | - throw new InvalidUriComponentException('URI component "scheme" must be a string'); |
|
| 64 | - } |
|
| 62 | + if (!is_string($value)) { |
|
| 63 | + throw new InvalidUriComponentException('URI component "scheme" must be a string'); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if (!preg_match(self::VALIDATE_REGEX, $value)) { |
|
| 67 | - throw new InvalidUriComponentException('Invalid URI component "scheme"'); |
|
| 68 | - } |
|
| 66 | + if (!preg_match(self::VALIDATE_REGEX, $value)) { |
|
| 67 | + throw new InvalidUriComponentException('Invalid URI component "scheme"'); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - // the component is case-insensitive... |
|
| 71 | - $this->value = strtolower($value); |
|
| 72 | - } |
|
| 70 | + // the component is case-insensitive... |
|
| 71 | + $this->value = strtolower($value); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * {@inheritdoc} |
|
| 76 | - * |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public function getValue(): string |
|
| 80 | - { |
|
| 81 | - return $this->value; |
|
| 82 | - } |
|
| 74 | + /** |
|
| 75 | + * {@inheritdoc} |
|
| 76 | + * |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public function getValue(): string |
|
| 80 | + { |
|
| 81 | + return $this->value; |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -31,52 +31,52 @@ |
||
| 31 | 31 | final class Fragment implements ComponentInterface |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Regular expression to normalize the component value |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private const NORMALIZE_REGEX = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=\:@\/\?]+)|(.?))/u'; |
|
| 34 | + /** |
|
| 35 | + * Regular expression to normalize the component value |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private const NORMALIZE_REGEX = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=\:@\/\?]+)|(.?))/u'; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The component value |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - private string $value = ''; |
|
| 41 | + /** |
|
| 42 | + * The component value |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + private string $value = ''; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Constructor of the class |
|
| 50 | - * |
|
| 51 | - * @param mixed $value |
|
| 52 | - * |
|
| 53 | - * @throws InvalidUriComponentException |
|
| 54 | - * If the component isn't valid. |
|
| 55 | - */ |
|
| 56 | - public function __construct($value) |
|
| 57 | - { |
|
| 58 | - if ($value === '') { |
|
| 59 | - return; |
|
| 60 | - } |
|
| 48 | + /** |
|
| 49 | + * Constructor of the class |
|
| 50 | + * |
|
| 51 | + * @param mixed $value |
|
| 52 | + * |
|
| 53 | + * @throws InvalidUriComponentException |
|
| 54 | + * If the component isn't valid. |
|
| 55 | + */ |
|
| 56 | + public function __construct($value) |
|
| 57 | + { |
|
| 58 | + if ($value === '') { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - if (!is_string($value)) { |
|
| 63 | - throw new InvalidUriComponentException('URI component "fragment" must be a string'); |
|
| 64 | - } |
|
| 62 | + if (!is_string($value)) { |
|
| 63 | + throw new InvalidUriComponentException('URI component "fragment" must be a string'); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $this->value = preg_replace_callback(self::NORMALIZE_REGEX, function (array $match): string { |
|
| 67 | - /** @var array{0: string, 1?: string} $match */ |
|
| 66 | + $this->value = preg_replace_callback(self::NORMALIZE_REGEX, function (array $match): string { |
|
| 67 | + /** @var array{0: string, 1?: string} $match */ |
|
| 68 | 68 | |
| 69 | - return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 70 | - }, $value); |
|
| 71 | - } |
|
| 69 | + return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 70 | + }, $value); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * {@inheritdoc} |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function getValue(): string |
|
| 79 | - { |
|
| 80 | - return $this->value; |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * {@inheritdoc} |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function getValue(): string |
|
| 79 | + { |
|
| 80 | + return $this->value; |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -17,10 +17,10 @@ |
||
| 17 | 17 | interface ComponentInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Gets the component value |
|
| 22 | - * |
|
| 23 | - * @return mixed |
|
| 24 | - */ |
|
| 25 | - public function getValue(); |
|
| 20 | + /** |
|
| 21 | + * Gets the component value |
|
| 22 | + * |
|
| 23 | + * @return mixed |
|
| 24 | + */ |
|
| 25 | + public function getValue(); |
|
| 26 | 26 | } |
@@ -32,55 +32,55 @@ |
||
| 32 | 32 | final class Host implements ComponentInterface |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Regular expression to normalize the component value |
|
| 37 | - * |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - private const NORMALIZE_REGEX = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=]+)|(.?))/u'; |
|
| 35 | + /** |
|
| 36 | + * Regular expression to normalize the component value |
|
| 37 | + * |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + private const NORMALIZE_REGEX = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=]+)|(.?))/u'; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The component value |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - private string $value = ''; |
|
| 42 | + /** |
|
| 43 | + * The component value |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + private string $value = ''; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Constructor of the class |
|
| 51 | - * |
|
| 52 | - * @param mixed $value |
|
| 53 | - * |
|
| 54 | - * @throws InvalidUriComponentException |
|
| 55 | - * If the component isn't valid. |
|
| 56 | - */ |
|
| 57 | - public function __construct($value) |
|
| 58 | - { |
|
| 59 | - if ($value === '') { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 49 | + /** |
|
| 50 | + * Constructor of the class |
|
| 51 | + * |
|
| 52 | + * @param mixed $value |
|
| 53 | + * |
|
| 54 | + * @throws InvalidUriComponentException |
|
| 55 | + * If the component isn't valid. |
|
| 56 | + */ |
|
| 57 | + public function __construct($value) |
|
| 58 | + { |
|
| 59 | + if ($value === '') { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - if (!is_string($value)) { |
|
| 64 | - throw new InvalidUriComponentException('URI component "host" must be a string'); |
|
| 65 | - } |
|
| 63 | + if (!is_string($value)) { |
|
| 64 | + throw new InvalidUriComponentException('URI component "host" must be a string'); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $this->value = preg_replace_callback(self::NORMALIZE_REGEX, function (array $match): string { |
|
| 68 | - /** @var array{0: string, 1?: string} $match */ |
|
| 67 | + $this->value = preg_replace_callback(self::NORMALIZE_REGEX, function (array $match): string { |
|
| 68 | + /** @var array{0: string, 1?: string} $match */ |
|
| 69 | 69 | |
| 70 | - return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 71 | - }, $value); |
|
| 70 | + return isset($match[1]) ? rawurlencode($match[1]) : $match[0]; |
|
| 71 | + }, $value); |
|
| 72 | 72 | |
| 73 | - // the component is case-insensitive... |
|
| 74 | - $this->value = strtolower($this->value); |
|
| 75 | - } |
|
| 73 | + // the component is case-insensitive... |
|
| 74 | + $this->value = strtolower($this->value); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * {@inheritdoc} |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function getValue(): string |
|
| 83 | - { |
|
| 84 | - return $this->value; |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * {@inheritdoc} |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function getValue(): string |
|
| 83 | + { |
|
| 84 | + return $this->value; |
|
| 85 | + } |
|
| 86 | 86 | } |