From 15c0be7030ec99c73c6dd3a10e5b40df7cf8d46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D0=B8=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= Date: Mon, 27 Jun 2016 10:42:00 +0300 Subject: [PATCH 001/132] Fix #41: Response builder broke header value (#42) Fix #41: Response builder broke header value As specified at [RFC7230](https://tools.ietf.org/html/rfc7230#section-3.2.4), headers charset should be limited to US-ASCII. --- CHANGELOG.md | 7 +++++++ spec/Builder/ResponseBuilderSpec.php | 9 ++++++--- src/Builder/ResponseBuilder.php | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6776f57..ab7a8ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## Unreleased + +### Fixed + +- #41: Response builder broke header value + + ## 1.2.0 - 2016-03-29 ### Added diff --git a/spec/Builder/ResponseBuilderSpec.php b/spec/Builder/ResponseBuilderSpec.php index 606884a..c4cc81e 100644 --- a/spec/Builder/ResponseBuilderSpec.php +++ b/spec/Builder/ResponseBuilderSpec.php @@ -23,13 +23,16 @@ function it_reads_headers_from_array(ResponseInterface $response) $this->setHeadersFromArray(['HTTP/1.1 200 OK', 'Content-type: text/html']); } - function it_reads_headers_from_string(ResponseInterface $response) + /** + * @link https://github.com/php-http/message/issues/41 + */ + function it_splits_headers_correctly(ResponseInterface $response) { $response->withStatus(200, 'OK')->willReturn($response); $response->withProtocolVersion('1.1')->willReturn($response); $response->hasHeader('Content-type')->willReturn(false); - $response->withHeader('Content-type', 'text/html')->willReturn($response); + $response->withHeader('Content-type', 'application/xml+atom')->willReturn($response); $this->beConstructedWith($response); - $this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: text/html\r\n"); + $this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: application/xml+atom\r\n"); } } diff --git a/src/Builder/ResponseBuilder.php b/src/Builder/ResponseBuilder.php index 0a198f4..e6933a0 100644 --- a/src/Builder/ResponseBuilder.php +++ b/src/Builder/ResponseBuilder.php @@ -135,8 +135,8 @@ public function addHeader($headerLine) sprintf('"%s" is not a valid HTTP header line', $headerLine) ); } - $name = trim(urldecode($parts[0])); - $value = trim(urldecode($parts[1])); + $name = trim($parts[0]); + $value = trim($parts[1]); if ($this->response->hasHeader($name)) { $this->response = $this->response->withAddedHeader($name, $value); } else { From 4e3de15100f7d143cbc44a6a48f5036a502ad26d Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 4 Jul 2016 08:44:27 +0200 Subject: [PATCH 002/132] Added a formatter that shows the full header and body of the HTTP message (#44) Added a formatter that shows the full header and body of the HTTP message --- CHANGELOG.md | 5 +- src/Formatter/FullHttpMessageFormatter.php | 72 ++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/Formatter/FullHttpMessageFormatter.php diff --git a/CHANGELOG.md b/CHANGELOG.md index ab7a8ce..dc0b33d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,14 @@ ## Unreleased +### Added + +- The FullHttpMessageFormatter was added + ### Fixed - #41: Response builder broke header value - ## 1.2.0 - 2016-03-29 ### Added diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php new file mode 100644 index 0000000..0afe38c --- /dev/null +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -0,0 +1,72 @@ + + */ +class FullHttpMessageFormatter implements Formatter +{ + /** + * The maximum length of the body. + * + * @var int + */ + private $maxBodyLength; + + /** + * @param int $maxBodyLength + */ + public function __construct($maxBodyLength = 1000) + { + $this->maxBodyLength = $maxBodyLength; + } + + /** + * {@inheritdoc} + */ + public function formatRequest(RequestInterface $request) + { + $message = sprintf( + "%s %s HTTP/%s\n", + $request->getMethod(), + $request->getRequestTarget(), + $request->getProtocolVersion() + ); + + foreach ($request->getHeaders() as $name => $values) { + $message .= $name.': '.implode(', ', $values)."\n"; + } + + $message .= "\n".mb_substr($request->getBody()->__toString(), 0, $this->maxBodyLength); + + return $message; + } + + /** + * {@inheritdoc} + */ + public function formatResponse(ResponseInterface $response) + { + $message = sprintf( + "HTTP/%s %s %s\n", + $response->getProtocolVersion(), + $response->getStatusCode(), + $response->getReasonPhrase() + ); + + foreach ($response->getHeaders() as $name => $values) { + $message .= $name.': '.implode(', ', $values)."\n"; + } + + $message .= "\n".mb_substr($response->getBody()->__toString(), 0, $this->maxBodyLength); + + return $message; + } +} From f2a8627d35d17105391fc4d6682b1f67fa3f1caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Mon, 4 Jul 2016 09:08:37 +0200 Subject: [PATCH 003/132] Update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc0b33d..1558fb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,17 @@ # Change Log + ## Unreleased ### Added -- The FullHttpMessageFormatter was added +- FullHttpMessageFormatter to include headers and body in the formatted message ### Fixed - #41: Response builder broke header value + ## 1.2.0 - 2016-03-29 ### Added From 619dfedc5de6ac3c52c8f849402b44402bec7bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Thu, 14 Jul 2016 11:40:45 +0200 Subject: [PATCH 004/132] Prepare release --- CHANGELOG.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1558fb6..01719d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log -## Unreleased +## 1.3.0 - 2016-07-14 ### Added diff --git a/composer.json b/composer.json index 0511073..a0da5dd 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.4-dev" } } } From 6d9c2d682dcf80cb2cc641eebc5693eacee95fa4 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 15 Jul 2016 16:48:03 +0200 Subject: [PATCH 005/132] Rewind streams (#47) * Make sure we rewind stream if we can. This will fix #46 * style fix * Updated changelog with fixes for FullHttpMessageFormatter --- CHANGELOG.md | 7 ++++++ src/Formatter/FullHttpMessageFormatter.php | 27 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01719d0..b90aaca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 1.3.1 - 2016-07-15 + +### Fixed + +- FullHttpMessageFormatter will not read from streams that you cannot rewind (non-seekable) +- FullHttpMessageFormatter will not read from the stream if $maxBodyLength is zero +- FullHttpMessageFormatter rewinds streams after they are read. ## 1.3.0 - 2016-07-14 diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index 0afe38c..3fa1029 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -3,6 +3,7 @@ namespace Http\Message\Formatter; use Http\Message\Formatter; +use Psr\Http\Message\MessageInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -44,9 +45,7 @@ public function formatRequest(RequestInterface $request) $message .= $name.': '.implode(', ', $values)."\n"; } - $message .= "\n".mb_substr($request->getBody()->__toString(), 0, $this->maxBodyLength); - - return $message; + return $this->addBody($request, $message); } /** @@ -65,7 +64,27 @@ public function formatResponse(ResponseInterface $response) $message .= $name.': '.implode(', ', $values)."\n"; } - $message .= "\n".mb_substr($response->getBody()->__toString(), 0, $this->maxBodyLength); + return $this->addBody($response, $message); + } + + /** + * Add the message body if the stream is seekable. + * + * @param MessageInterface $request + * @param string $message + * + * @return string + */ + private function addBody(MessageInterface $request, $message) + { + $stream = $request->getBody(); + if (!$stream->isSeekable() || $this->maxBodyLength === 0) { + // Do not read the stream + $message .= "\n"; + } else { + $message .= "\n".mb_substr($stream->__toString(), 0, $this->maxBodyLength); + $stream->rewind(); + } return $message; } From a69d952659b5caaa2f9ab2794f9727d7eb36eba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Sat, 16 Jul 2016 00:05:03 +0200 Subject: [PATCH 006/132] Improve package (#48) * Improve package * Improve package * Fix styleci config --- .gitattributes | 28 +++++++++++++++------------- .gitignore | 12 ++++++------ .styleci.yml | 3 +++ .travis.yml | 5 +++-- CHANGELOG.md | 6 ++++-- composer.json | 2 +- phpspec.yml.ci => phpspec.ci.yml | 0 7 files changed, 32 insertions(+), 24 deletions(-) rename phpspec.yml.ci => phpspec.ci.yml (100%) diff --git a/.gitattributes b/.gitattributes index 7ae0617..c47225a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,15 @@ -.editorconfig export-ignore -.gitattributes export-ignore -.github/ export-ignore -.gitignore export-ignore -.php_cs export-ignore -.scrutinizer.yml export-ignore -.styleci.yml export-ignore -.travis.yml export-ignore -phpspec.yml.ci export-ignore -phpspec.yml.dist export-ignore -phpunit.xml.dist export-ignore -spec/ export-ignore -tests/ export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +/.github/ export-ignore +.gitignore export-ignore +/.php_cs export-ignore +/.scrutinizer.yml export-ignore +/.styleci.yml export-ignore +/.travis.yml export-ignore +/behat.yml.dist export-ignore +/features/ export-ignore +/phpspec.ci.yml export-ignore +/phpspec.yml.dist export-ignore +/phpunit.xml.dist export-ignore +/spec/ export-ignore +/tests/ export-ignore diff --git a/.gitignore b/.gitignore index da734f1..16b4a20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -.puli/ -build/ -vendor/ -composer.lock -phpspec.yml -phpunit.xml +/behat.yml +/build/ +/composer.lock +/phpspec.yml +/phpunit.xml +/vendor/ diff --git a/.styleci.yml b/.styleci.yml index 3417c41..5328b61 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -9,3 +9,6 @@ finder: enabled: - short_array_syntax + +disabled: + - phpdoc_annotation_without_dot # This is still buggy: https://github.com/symfony/symfony/pull/19198 diff --git a/.travis.yml b/.travis.yml index 7a4a218..9bbb449 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ matrix: env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" before_install: + - if [[ $COVERAGE != true && $TRAVIS_PHP_VERSION != hhvm ]]; then phpenv config-rm xdebug.ini; fi - travis_retry composer self-update install: @@ -37,5 +38,5 @@ script: - $TEST_COMMAND after_success: - - if [[ "$COVERAGE" = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [[ "$COVERAGE" = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi + - if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi + - if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi diff --git a/CHANGELOG.md b/CHANGELOG.md index b90aaca..ce2c410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,14 @@ # Change Log + ## 1.3.1 - 2016-07-15 ### Fixed - FullHttpMessageFormatter will not read from streams that you cannot rewind (non-seekable) - FullHttpMessageFormatter will not read from the stream if $maxBodyLength is zero -- FullHttpMessageFormatter rewinds streams after they are read. +- FullHttpMessageFormatter rewinds streams after they are read + ## 1.3.0 - 2016-07-14 @@ -15,7 +17,7 @@ - FullHttpMessageFormatter to include headers and body in the formatted message ### Fixed - + - #41: Response builder broke header value diff --git a/composer.json b/composer.json index a0da5dd..0efd08a 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ }, "scripts": { "test": "vendor/bin/phpspec run", - "test-ci": "vendor/bin/phpspec run -c phpspec.yml.ci" + "test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml" }, "extra": { "branch-alias": { diff --git a/phpspec.yml.ci b/phpspec.ci.yml similarity index 100% rename from phpspec.yml.ci rename to phpspec.ci.yml From 1c3a53f69b25570fef47db5899a7453c34691e6f Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 2 Aug 2016 14:15:59 +0200 Subject: [PATCH 007/132] Added cURL formatter (#50) Added cURL formatter inspired by namshi/cuzzle --- README.md | 3 + spec/Formatter/CurlCommandFormatterSpec.php | 61 ++++++++++++++++ src/Formatter/CurlCommandFormatter.php | 80 +++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 spec/Formatter/CurlCommandFormatterSpec.php create mode 100644 src/Formatter/CurlCommandFormatter.php diff --git a/README.md b/README.md index 34580fe..338b415 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,9 @@ $ composer test Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html). +## Cretids + +Thanks to [Cuzzle](https://github.com/namshi/cuzzle) for inpiration for the `CurlCommandFormatter`. ## Security diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php new file mode 100644 index 0000000..50fd374 --- /dev/null +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -0,0 +1,61 @@ +shouldHaveType('Http\Message\Formatter\CurlCommandFormatter'); + } + + function it_is_a_formatter() + { + $this->shouldImplement('Http\Message\Formatter'); + } + + function it_formats_the_request(RequestInterface $request, UriInterface $uri, StreamInterface $body) + { + $request->getUri()->willReturn($uri); + $request->getBody()->willReturn($body); + + $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); + $request->getMethod()->willReturn('GET'); + $request->getProtocolVersion()->willReturn('1.1'); + + $request->getHeaders()->willReturn(['foo'=>['bar', 'baz']]); + $request->getHeaderLine('foo')->willReturn('bar, baz'); + + $this->formatRequest($request)->shouldReturn('curl \'http://foo.com/bar\' -H \'foo: bar, baz\''); + } + + function it_formats_post_request(RequestInterface $request, UriInterface $uri, StreamInterface $body) + { + $request->getUri()->willReturn($uri); + $request->getBody()->willReturn($body); + + $body->__toString()->willReturn('body " data'." test' bar"); + $body->getSize()->willReturn(1); + $body->isSeekable()->willReturn(true); + $body->rewind()->willReturn(true); + + $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); + $request->getMethod()->willReturn('POST'); + $request->getProtocolVersion()->willReturn('2.0'); + + $request->getHeaders()->willReturn([]); + + $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --http2 --request POST --data 'body \" data test'\'' bar'"); + } + + function it_does_nothing_for_response(ResponseInterface $response) + { + $this->formatResponse($response)->shouldReturn(''); + } +} diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php new file mode 100644 index 0000000..5364ccc --- /dev/null +++ b/src/Formatter/CurlCommandFormatter.php @@ -0,0 +1,80 @@ + + */ +class CurlCommandFormatter implements Formatter +{ + /** + * {@inheritdoc} + */ + public function formatRequest(RequestInterface $request) + { + $command = sprintf('curl %s', escapeshellarg((string) $request->getUri()->withFragment(''))); + if ($request->getProtocolVersion() === '1.0') { + $command .= ' --http1.0'; + } elseif ($request->getProtocolVersion() === '2.0') { + $command .= ' --http2'; + } + + $method = strtoupper($request->getMethod()); + if ('HEAD' === $method) { + $command .= ' --head'; + } elseif ('GET' !== $method) { + $command .= ' --request '.$method; + } + + $command .= $this->getHeadersAsCommandOptions($request); + + $body = $request->getBody(); + if ($body->getSize() > 0) { + if (!$body->isSeekable()) { + return 'Cant format Request as cUrl command if body stream is not seekable.'; + } + $command .= sprintf(' --data %s', escapeshellarg($body->__toString())); + $body->rewind(); + } + + return $command; + } + + /** + * {@inheritdoc} + */ + public function formatResponse(ResponseInterface $response) + { + return ''; + } + + /** + * @param RequestInterface $request + * + * @return string + */ + private function getHeadersAsCommandOptions(RequestInterface $request) + { + $command = ''; + foreach ($request->getHeaders() as $name => $values) { + if ('host' === strtolower($name) && $values[0] === $request->getUri()->getHost()) { + continue; + } + + if ('user-agent' === strtolower($name)) { + $command .= sprintf('-A %s', escapeshellarg($values[0])); + continue; + } + + $command .= sprintf(' -H %s', escapeshellarg($name.': '.$request->getHeaderLine($name))); + } + + return $command; + } +} From 8cd7fb123ed5b920ad694382378185e67450373c Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 2 Aug 2016 22:02:45 +0100 Subject: [PATCH 008/132] Test on PHP 7.1 (#51) * Test on PHP 7.1 * Fixed travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9bbb449..95980fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 - hhvm env: @@ -28,7 +29,7 @@ matrix: env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" before_install: - - if [[ $COVERAGE != true && $TRAVIS_PHP_VERSION != hhvm ]]; then phpenv config-rm xdebug.ini; fi + - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi - travis_retry composer self-update install: From ffad01fe6b2cb915712fcee65de097396735232d Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Sun, 7 Aug 2016 14:58:01 +0200 Subject: [PATCH 009/132] Add buffered stream (#52) Add buffered stream --- spec/Stream/BufferedStreamSpec.php | 184 ++++++++++++++++++++ src/Stream/BufferedStream.php | 270 +++++++++++++++++++++++++++++ 2 files changed, 454 insertions(+) create mode 100644 spec/Stream/BufferedStreamSpec.php create mode 100644 src/Stream/BufferedStream.php diff --git a/spec/Stream/BufferedStreamSpec.php b/spec/Stream/BufferedStreamSpec.php new file mode 100644 index 0000000..c1cbba6 --- /dev/null +++ b/spec/Stream/BufferedStreamSpec.php @@ -0,0 +1,184 @@ +beConstructedWith($stream); + + $stream->getSize()->willReturn(null); + } + + public function it_is_castable_to_string(StreamInterface $stream) + { + $eofCounter = 0; + $stream->eof()->will(function () use(&$eofCounter) { + return (++$eofCounter > 1); + }); + + $stream->read(8192)->willReturn('foo'); + + $this->__toString()->shouldReturn('foo'); + } + + public function it_detachs(StreamInterface $stream) + { + $stream->eof()->willReturn(true); + $stream->read(8192)->willReturn(''); + $stream->close()->shouldBeCalled(); + + $this->detach()->shouldBeResource(); + $this->detach()->shouldBeNull(); + } + + public function it_gets_size(StreamInterface $stream) + { + $stream->eof()->willReturn(false); + $this->getSize()->shouldReturn(null); + + $eofCounter = 0; + $stream->eof()->will(function () use(&$eofCounter) { + return (++$eofCounter > 1); + }); + + $stream->read(8192)->willReturn('foo'); + + $this->getContents()->shouldReturn('foo'); + $this->getSize()->shouldReturn(3); + } + + public function it_tells(StreamInterface $stream) + { + $this->tell()->shouldReturn(0); + + $eofCounter = 0; + $stream->eof()->will(function () use(&$eofCounter) { + return (++$eofCounter > 1); + }); + + $stream->read(8192)->willReturn('foo'); + $this->getContents()->shouldReturn('foo'); + $this->tell()->shouldReturn(3); + } + + public function it_eof(StreamInterface $stream) + { + // Case when underlying is false + $stream->eof()->willReturn(false); + $this->eof()->shouldReturn(false); + + // Case when sync and underlying is true + $stream->eof()->willReturn(true); + $this->eof()->shouldReturn(true); + + // Case not sync but underlying is true + $eofCounter = 0; + $stream->eof()->will(function () use(&$eofCounter) { + return (++$eofCounter > 1); + }); + + $stream->read(8192)->willReturn('foo'); + + $this->getContents()->shouldReturn('foo'); + $this->seek(0); + + $stream->eof()->willReturn(true); + $this->eof()->shouldReturn(false); + } + + public function it_is_seekable(StreamInterface $stream) + { + $this->isSeekable()->shouldReturn(true); + } + + public function it_seeks(StreamInterface $stream) + { + $this->seek(0); + $this->tell()->shouldReturn(0); + + $eofCounter = 0; + $stream->eof()->will(function () use(&$eofCounter) { + return (++$eofCounter > 1); + }); + + $stream->read(8192)->willReturn('foo'); + + $this->getContents()->shouldReturn('foo'); + $this->seek(2); + $this->tell()->shouldReturn(2); + } + + public function it_rewinds(StreamInterface $stream) + { + $this->rewind(); + $this->tell()->shouldReturn(0); + + $eofCounter = 0; + $stream->eof()->will(function () use(&$eofCounter) { + return (++$eofCounter > 1); + }); + + $stream->read(8192)->willReturn('foo'); + + $this->getContents()->shouldReturn('foo'); + $this->tell()->shouldReturn(3); + $this->rewind(); + $this->tell()->shouldReturn(0); + } + + public function it_is_not_writable(StreamInterface $stream) + { + $this->isWritable()->shouldReturn(false); + $this->shouldThrow('\RuntimeException')->duringWrite('foo'); + } + + public function it_is_readable(StreamInterface $stream) + { + $this->isReadable()->shouldReturn(true); + } + + public function it_reads(StreamInterface $stream) + { + $eofCounter = 0; + $stream->eof()->will(function () use(&$eofCounter) { + return (++$eofCounter > 1); + }); + + $stream->read(3)->willReturn('foo'); + $this->read(3)->shouldReturn('foo'); + + $stream->read(3)->willReturn('bar'); + $this->read(3)->shouldReturn('bar'); + + $this->rewind(); + $this->read(4)->shouldReturn('foob'); + + $stream->read(3)->willReturn('baz'); + $this->read(5)->shouldReturn('arbaz'); + } + + public function it_get_contents(StreamInterface $stream) + { + $eofCounter = 0; + $stream->eof()->will(function () use(&$eofCounter) { + return (++$eofCounter > 1); + }); + + $stream->read(8192)->willReturn('foo'); + + $this->getContents()->shouldReturn('foo'); + $this->eof()->shouldReturn(true); + } + + public function it_get_metadatas(StreamInterface $stream) + { + $this->getMetadata()->shouldBeArray(); + $this->getMetadata('unexistant')->shouldBeNull(); + $this->getMetadata('stream_type')->shouldReturn('TEMP'); + } +} diff --git a/src/Stream/BufferedStream.php b/src/Stream/BufferedStream.php new file mode 100644 index 0000000..1eac974 --- /dev/null +++ b/src/Stream/BufferedStream.php @@ -0,0 +1,270 @@ +stream = $stream; + $this->size = $stream->getSize(); + + if ($useFileBuffer) { + $this->resource = fopen('php://temp/maxmemory:'.$memoryBuffer, 'rw+'); + } else { + $this->resource = fopen('php://memory', 'rw+'); + } + + if (false === $this->resource) { + throw new \RuntimeException('Cannot create a resource over temp or memory implementation'); + } + } + + /** + * {@inheritdoc} + */ + public function __toString() + { + try { + $this->rewind(); + + return $this->getContents(); + } catch (\Throwable $throwable) { + return ''; + } catch (\Exception $exception) { // Layer to be BC with PHP 5, remove this when we only support PHP 7+ + return ''; + } + } + + /** + * {@inheritdoc} + */ + public function close() + { + if (null === $this->resource) { + throw new \RuntimeException('Cannot close on a detached stream'); + } + + $this->stream->close(); + fclose($this->resource); + } + + /** + * {@inheritdoc} + */ + public function detach() + { + if (null === $this->resource) { + return; + } + + // Force reading the remaining data of the stream + $this->getContents(); + + $resource = $this->resource; + $this->stream->close(); + $this->stream = null; + $this->resource = null; + + return $resource; + } + + /** + * {@inheritdoc} + */ + public function getSize() + { + if (null === $this->resource) { + return; + } + + if (null === $this->size && $this->stream->eof()) { + return $this->written; + } + + return $this->size; + } + + /** + * {@inheritdoc} + */ + public function tell() + { + if (null === $this->resource) { + throw new \RuntimeException('Cannot tell on a detached stream'); + } + + return ftell($this->resource); + } + + /** + * {@inheritdoc} + */ + public function eof() + { + if (null === $this->resource) { + throw new \RuntimeException('Cannot call eof on a detached stream'); + } + + // We are at the end only when both our resource and underlying stream are at eof + return $this->stream->eof() && (ftell($this->resource) === $this->written); + } + + /** + * {@inheritdoc} + */ + public function isSeekable() + { + return null !== $this->resource; + } + + /** + * {@inheritdoc} + */ + public function seek($offset, $whence = SEEK_SET) + { + if (null === $this->resource) { + throw new \RuntimeException('Cannot seek on a detached stream'); + } + + fseek($this->resource, $offset, $whence); + } + + /** + * {@inheritdoc} + */ + public function rewind() + { + if (null === $this->resource) { + throw new \RuntimeException('Cannot rewind on a detached stream'); + } + + rewind($this->resource); + } + + /** + * {@inheritdoc} + */ + public function isWritable() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function write($string) + { + throw new \RuntimeException('Cannot write on this stream'); + } + + /** + * {@inheritdoc} + */ + public function isReadable() + { + return null !== $this->resource; + } + + /** + * {@inheritdoc} + */ + public function read($length) + { + if (null === $this->resource) { + throw new \RuntimeException('Cannot read on a detached stream'); + } + + $read = ''; + + // First read from the resource + if (ftell($this->resource) !== $this->written) { + $read = fread($this->resource, $length); + } + + $bytesRead = strlen($read); + + if ($bytesRead < $length) { + $streamRead = $this->stream->read($length - $bytesRead); + + // Write on the underlying stream what we read + $this->written += fwrite($this->resource, $streamRead); + $read .= $streamRead; + } + + return $read; + } + + /** + * {@inheritdoc} + */ + public function getContents() + { + if (null === $this->resource) { + throw new \RuntimeException('Cannot read on a detached stream'); + } + + $read = ''; + + while (!$this->eof()) { + $read .= $this->read(8192); + } + + return $read; + } + + /** + * {@inheritdoc} + */ + public function getMetadata($key = null) + { + if (null === $this->resource) { + if (null === $key) { + return []; + } + + return; + } + + $metadata = stream_get_meta_data($this->resource); + + if (null === $key) { + return $metadata; + } + + if (!array_key_exists($key, $metadata)) { + return; + } + + return $metadata[$key]; + } +} From 1395f1485e50e208ba6091af167c42318a94223a Mon Sep 17 00:00:00 2001 From: Mika Tuupola Date: Fri, 14 Oct 2016 22:31:46 +0300 Subject: [PATCH 010/132] Test also body and headers --- spec/MessageFactory/MessageFactoryBehavior.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/MessageFactory/MessageFactoryBehavior.php b/spec/MessageFactory/MessageFactoryBehavior.php index 9472ed4..29a7eab 100644 --- a/spec/MessageFactory/MessageFactoryBehavior.php +++ b/spec/MessageFactory/MessageFactoryBehavior.php @@ -11,11 +11,13 @@ function it_is_a_message_factory() function it_creates_a_request() { - $request = $this->createRequest('GET', '/'); + $request = $this->createRequest('GET', '/', array('X-hello' => 'world'), 'lorem'); $request->shouldHaveType('Psr\Http\Message\RequestInterface'); $request->getMethod()->shouldReturn('GET'); $request->getRequestTarget()->shouldReturn('/'); + $request->getBody()->__toString()->shouldReturn('lorem'); + $request->getHeaderLine('X-hello')->shouldReturn('world'); } function it_creates_a_response() From 51a0aa56c5bfe7a7f71a38ae75e4df31806226d9 Mon Sep 17 00:00:00 2001 From: Mika Tuupola Date: Sat, 15 Oct 2016 00:28:34 +0300 Subject: [PATCH 011/132] Add message, stream and URI factories for Slim Framework (#53) * Add message, stream and URI factories for Slim Framework * Do not test Slim factories with PHP 5.4 * Add missing test for Slim stream factory * Slim should be development dependency * Remove slim/slim before running composer install on PHP 5.4 * HHVM does not have rw mode, use r+ instead https://github.com/facebook/hhvm/issues/6999 * Better wording for suggestion * Mention Slim Framework factories --- .travis.yml | 1 + CHANGELOG.md | 5 ++ composer.json | 5 +- phpspec.ci.yml | 1 + phpspec.yml.dist | 1 + .../MessageFactory/SlimMessageFactorySpec.php | 18 +++++ spec/StreamFactory/SlimStreamFactorySpec.php | 26 +++++++ spec/UriFactory/SlimUriFactorySpec.php | 27 +++++++ src/MessageFactory/SlimMessageFactory.php | 72 +++++++++++++++++++ src/StreamFactory/SlimStreamFactory.php | 40 +++++++++++ src/UriFactory/SlimUriFactory.php | 31 ++++++++ 11 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 spec/MessageFactory/SlimMessageFactorySpec.php create mode 100644 spec/StreamFactory/SlimStreamFactorySpec.php create mode 100644 spec/UriFactory/SlimUriFactorySpec.php create mode 100644 src/MessageFactory/SlimMessageFactory.php create mode 100644 src/StreamFactory/SlimStreamFactory.php create mode 100644 src/UriFactory/SlimUriFactory.php diff --git a/.travis.yml b/.travis.yml index 95980fc..1d51b60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,7 @@ matrix: before_install: - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi + - if [[ "${TRAVIS_PHP_VERSION}" == "5.4" ]]; then composer remove slim/slim --dev --no-update; fi - travis_retry composer self-update install: diff --git a/CHANGELOG.md b/CHANGELOG.md index ce2c410..99f4cce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Unreleased + +### Added + +- Message, stream and URI factories for [Slim Framework](https://github.com/slimphp/Slim) ## 1.3.1 - 2016-07-15 diff --git a/composer.json b/composer.json index 0efd08a..9dd876b 100644 --- a/composer.json +++ b/composer.json @@ -22,11 +22,14 @@ "ext-zlib": "*", "phpspec/phpspec": "^2.4", "henrikbjorn/phpspec-code-coverage" : "^1.0", - "coduo/phpspec-data-provider-extension": "^1.0" + "coduo/phpspec-data-provider-extension": "^1.0", + "akeneo/phpspec-skip-example-extension": "^1.0", + "slim/slim": "^3.5" }, "suggest": { "zendframework/zend-diactoros": "Used with Diactoros Factories", "guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories", + "slim/slim": "Used with Slim Framework PSR-7 implementation", "ext-zlib": "Used with compressor/decompressor streams" }, "autoload": { diff --git a/phpspec.ci.yml b/phpspec.ci.yml index f08e148..a4a288f 100644 --- a/phpspec.ci.yml +++ b/phpspec.ci.yml @@ -6,6 +6,7 @@ formatter.name: pretty extensions: - PhpSpec\Extension\CodeCoverageExtension - Coduo\PhpSpec\DataProvider\DataProviderExtension + - Akeneo\SkipExampleExtension code_coverage: format: clover output: build/coverage.xml diff --git a/phpspec.yml.dist b/phpspec.yml.dist index 8d38a4e..56d3c89 100644 --- a/phpspec.yml.dist +++ b/phpspec.yml.dist @@ -5,3 +5,4 @@ suites: formatter.name: pretty extensions: - Coduo\PhpSpec\DataProvider\DataProviderExtension + - Akeneo\SkipExampleExtension diff --git a/spec/MessageFactory/SlimMessageFactorySpec.php b/spec/MessageFactory/SlimMessageFactorySpec.php new file mode 100644 index 0000000..e39452e --- /dev/null +++ b/spec/MessageFactory/SlimMessageFactorySpec.php @@ -0,0 +1,18 @@ +shouldHaveType('Http\Message\MessageFactory\SlimMessageFactory'); + } +} diff --git a/spec/StreamFactory/SlimStreamFactorySpec.php b/spec/StreamFactory/SlimStreamFactorySpec.php new file mode 100644 index 0000000..c3bfef3 --- /dev/null +++ b/spec/StreamFactory/SlimStreamFactorySpec.php @@ -0,0 +1,26 @@ +shouldHaveType('Http\Message\StreamFactory\SlimStreamFactory'); + } + + function it_creates_a_stream_from_stream() + { + $resource = fopen('php://memory', 'rw'); + $this->createStream(new Stream($resource)) + ->shouldHaveType('Psr\Http\Message\StreamInterface'); + } +} diff --git a/spec/UriFactory/SlimUriFactorySpec.php b/spec/UriFactory/SlimUriFactorySpec.php new file mode 100644 index 0000000..b373f5f --- /dev/null +++ b/spec/UriFactory/SlimUriFactorySpec.php @@ -0,0 +1,27 @@ +shouldHaveType('Http\Message\UriFactory\SlimUriFactory'); + } + + /** + * TODO: Remove this when https://github.com/phpspec/phpspec/issues/825 is resolved + */ + function it_creates_a_uri_from_uri(UriInterface $uri) + { + $this->createUri($uri)->shouldReturn($uri); + } +} diff --git a/src/MessageFactory/SlimMessageFactory.php b/src/MessageFactory/SlimMessageFactory.php new file mode 100644 index 0000000..cdad2ec --- /dev/null +++ b/src/MessageFactory/SlimMessageFactory.php @@ -0,0 +1,72 @@ + + */ +final class SlimMessageFactory implements MessageFactory +{ + /** + * @var SlimStreamFactory + */ + private $streamFactory; + + /** + * @var SlimUriFactory + */ + private $uriFactory; + + public function __construct() + { + $this->streamFactory = new SlimStreamFactory(); + $this->uriFactory = new SlimUriFactory(); + } + + /** + * {@inheritdoc} + */ + public function createRequest( + $method, + $uri, + array $headers = [], + $body = null, + $protocolVersion = '1.1' + ) { + return (new Request( + $method, + $this->uriFactory->createUri($uri), + new Headers($headers), + [], + [], + $this->streamFactory->createStream($body), + [] + ))->withProtocolVersion($protocolVersion); + } + + /** + * {@inheritdoc} + */ + public function createResponse( + $statusCode = 200, + $reasonPhrase = null, + array $headers = [], + $body = null, + $protocolVersion = '1.1' + ) { + return (new Response( + $statusCode, + new Headers($headers), + $this->streamFactory->createStream($body) + ))->withProtocolVersion($protocolVersion); + } +} diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php new file mode 100644 index 0000000..e779f3b --- /dev/null +++ b/src/StreamFactory/SlimStreamFactory.php @@ -0,0 +1,40 @@ + + */ +final class SlimStreamFactory implements StreamFactory +{ + /** + * {@inheritdoc} + */ + public function createStream($body = null) + { + if ($body instanceof StreamInterface) { + return $body; + } + + if (is_resource($body)) { + $stream = new Stream($body); + } else { + $resource = fopen('php://memory', 'r+'); + $stream = new Stream($resource); + + if (null !== $body) { + $stream->write((string) $body); + } + } + + $stream->rewind(); + + return $stream; + } +} diff --git a/src/UriFactory/SlimUriFactory.php b/src/UriFactory/SlimUriFactory.php new file mode 100644 index 0000000..c013d54 --- /dev/null +++ b/src/UriFactory/SlimUriFactory.php @@ -0,0 +1,31 @@ + + */ +final class SlimUriFactory implements UriFactory +{ + /** + * {@inheritdoc} + */ + public function createUri($uri) + { + if ($uri instanceof UriInterface) { + return $uri; + } + + if (is_string($uri)) { + return Uri::createFromString($uri); + } + + throw new \InvalidArgumentException('URI must be a string or UriInterface'); + } +} From 5b53182aa32f0794edc73b28ef3345b313aaf7be Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 15 Oct 2016 12:56:54 +0200 Subject: [PATCH 012/132] Added Slim to puli.json --- puli.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/puli.json b/puli.json index 9237b10..024a85d 100644 --- a/puli.json +++ b/puli.json @@ -10,6 +10,16 @@ "depends": "Zend\\Diactoros\\Request" } }, + "0836751e-6558-4d1b-8993-4a52012947c3": { + "_class": "Puli\\Discovery\\Binding\\ClassBinding", + "class": "Http\\Message\\MessageFactory\\SlimMessageFactory", + "type": "Http\\Message\\ResponseFactory" + }, + "1d127622-dc61-4bfa-b9da-d221548d72c3": { + "_class": "Puli\\Discovery\\Binding\\ClassBinding", + "class": "Http\\Message\\MessageFactory\\SlimMessageFactory", + "type": "Http\\Message\\RequestFactory" + }, "2438c2d0-0658-441f-8855-ddaf0f87d54d": { "_class": "Puli\\Discovery\\Binding\\ClassBinding", "class": "Http\\Message\\MessageFactory\\GuzzleMessageFactory", @@ -50,6 +60,11 @@ "depends": "Zend\\Diactoros\\Uri" } }, + "4672a6ee-ad9e-4109-a5d1-b7d46f26c7a1": { + "_class": "Puli\\Discovery\\Binding\\ClassBinding", + "class": "Http\\Message\\MessageFactory\\SlimMessageFactory", + "type": "Http\\Message\\MessageFactory" + }, "6234e947-d3bd-43eb-97d5-7f9e22e6bb1b": { "_class": "Puli\\Discovery\\Binding\\ClassBinding", "class": "Http\\Message\\MessageFactory\\DiactorosMessageFactory", @@ -58,6 +73,16 @@ "depends": "Zend\\Diactoros\\Response" } }, + "6a9ad6ce-d82c-470f-8e30-60f21d9d95bf": { + "_class": "Puli\\Discovery\\Binding\\ClassBinding", + "class": "Http\\Message\\UriFactory\\SlimUriFactory", + "type": "Http\\Message\\UriFactory" + }, + "72c2afa0-ea56-4d03-adb6-a9f241a8a734": { + "_class": "Puli\\Discovery\\Binding\\ClassBinding", + "class": "Http\\Message\\StreamFactory\\SlimStreamFactory", + "type": "Http\\Message\\StreamFactory" + }, "95c1be8f-39fe-4abd-8351-92cb14379a75": { "_class": "Puli\\Discovery\\Binding\\ClassBinding", "class": "Http\\Message\\StreamFactory\\DiactorosStreamFactory", From b56fb794cdec17c090409095b867159a8d308eb6 Mon Sep 17 00:00:00 2001 From: sagikazarmark Date: Sat, 15 Oct 2016 13:42:42 +0000 Subject: [PATCH 013/132] Applied fixes from StyleCI --- src/Encoding/FilteredStream.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index 38d6258..c3a06fc 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -100,7 +100,7 @@ public function eof() protected function fill() { $readFilterCallback = $this->readFilterCallback; - $this->buffer .= $readFilterCallback($this->stream->read(self::BUFFER_SIZE)); + $this->buffer .= $readFilterCallback($this->stream->read(self::BUFFER_SIZE)); if ($this->stream->eof()) { $this->buffer .= $readFilterCallback(); From 4d58776e78abae084a4c48defe421ddd8cc6e295 Mon Sep 17 00:00:00 2001 From: Mika Tuupola Date: Sat, 15 Oct 2016 18:44:26 +0300 Subject: [PATCH 014/132] Relax minimum required version of Slim --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9dd876b..43dd894 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "henrikbjorn/phpspec-code-coverage" : "^1.0", "coduo/phpspec-data-provider-extension": "^1.0", "akeneo/phpspec-skip-example-extension": "^1.0", - "slim/slim": "^3.5" + "slim/slim": "^3.0" }, "suggest": { "zendframework/zend-diactoros": "Used with Diactoros Factories", From dddb02226a8c304f1dd23d925933f2a725c2854f Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 17 Oct 2016 10:39:43 +0200 Subject: [PATCH 015/132] Updated change log with cURLFormatter and BufferedStream --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99f4cce..c72c483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,12 @@ # Change Log -## Unreleased +## 1.4.0 - 2016-10-17 ### Added - Message, stream and URI factories for [Slim Framework](https://github.com/slimphp/Slim) +- BufferedStream that allow you to decorate a non-seekable stream with a seekable one. +- cUrlFormatter to be able to redo the request with a cURL command ## 1.3.1 - 2016-07-15 From 20ffbdc291a127e93f66007742693fbdf020d223 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 20 Oct 2016 08:59:05 +0200 Subject: [PATCH 016/132] Prepare for release (#63) * Prepare for release * Update CHANGELOG.md --- CHANGELOG.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c72c483..80b06f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## 1.4.0 - 2016-10-17 +## 1.4.0 - 2016-10-20 ### Added diff --git a/composer.json b/composer.json index 43dd894..5658119 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.5-dev" } } } From b9b8f1440b221dbe880042600b629f438e8f4e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20J=2E=20Garc=C3=ADa=20Lagar?= Date: Wed, 19 Oct 2016 17:55:06 +0200 Subject: [PATCH 017/132] Deprecate FilteredStream::getReadFilter and FilteredStream::getWriteFilter --- CHANGELOG.md | 7 +++++ src/Encoding/ChunkStream.php | 4 +-- src/Encoding/CompressStream.php | 4 +-- src/Encoding/DechunkStream.php | 4 +-- src/Encoding/DecompressStream.php | 4 +-- src/Encoding/DeflateStream.php | 4 +-- src/Encoding/FilteredStream.php | 49 +++++++++++++++++++++++++++---- src/Encoding/GzipDecodeStream.php | 4 +-- src/Encoding/GzipEncodeStream.php | 4 +-- src/Encoding/InflateStream.php | 4 +-- 10 files changed, 67 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80b06f1..5aaadd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## Unreleased + +### Deprecated + + - FilteredStream::getReadFilter The read filter is internal and should never be used by consuming code. + - FilteredStream::getWriteFilter We did not implement writing to the streams at all. And if we do, the filter is an internal information and should not be used by consuming code. + ## 1.4.0 - 2016-10-20 ### Added diff --git a/src/Encoding/ChunkStream.php b/src/Encoding/ChunkStream.php index 3e663b6..74c2fbd 100644 --- a/src/Encoding/ChunkStream.php +++ b/src/Encoding/ChunkStream.php @@ -12,7 +12,7 @@ class ChunkStream extends FilteredStream /** * {@inheritdoc} */ - public function getReadFilter() + protected function readFilter() { return 'chunk'; } @@ -20,7 +20,7 @@ public function getReadFilter() /** * {@inheritdoc} */ - public function getWriteFilter() + protected function writeFilter() { return 'dechunk'; } diff --git a/src/Encoding/CompressStream.php b/src/Encoding/CompressStream.php index 08ea554..d1013dc 100644 --- a/src/Encoding/CompressStream.php +++ b/src/Encoding/CompressStream.php @@ -27,7 +27,7 @@ public function __construct(StreamInterface $stream, $level = -1) /** * {@inheritdoc} */ - public function getReadFilter() + protected function readFilter() { return 'zlib.deflate'; } @@ -35,7 +35,7 @@ public function getReadFilter() /** * {@inheritdoc} */ - public function getWriteFilter() + protected function writeFilter() { return 'zlib.inflate'; } diff --git a/src/Encoding/DechunkStream.php b/src/Encoding/DechunkStream.php index 56d1208..4cade83 100644 --- a/src/Encoding/DechunkStream.php +++ b/src/Encoding/DechunkStream.php @@ -14,7 +14,7 @@ class DechunkStream extends FilteredStream /** * {@inheritdoc} */ - public function getReadFilter() + protected function readFilter() { return 'dechunk'; } @@ -22,7 +22,7 @@ public function getReadFilter() /** * {@inheritdoc} */ - public function getWriteFilter() + protected function writeFilter() { return 'chunk'; } diff --git a/src/Encoding/DecompressStream.php b/src/Encoding/DecompressStream.php index 42c2838..4e3a723 100644 --- a/src/Encoding/DecompressStream.php +++ b/src/Encoding/DecompressStream.php @@ -27,7 +27,7 @@ public function __construct(StreamInterface $stream, $level = -1) /** * {@inheritdoc} */ - public function getReadFilter() + protected function readFilter() { return 'zlib.inflate'; } @@ -35,7 +35,7 @@ public function getReadFilter() /** * {@inheritdoc} */ - public function getWriteFilter() + protected function writeFilter() { return 'zlib.deflate'; } diff --git a/src/Encoding/DeflateStream.php b/src/Encoding/DeflateStream.php index 1758d11..1d7344b 100644 --- a/src/Encoding/DeflateStream.php +++ b/src/Encoding/DeflateStream.php @@ -23,7 +23,7 @@ public function __construct(StreamInterface $stream, $level = -1) /** * {@inheritdoc} */ - public function getReadFilter() + protected function readFilter() { return 'zlib.deflate'; } @@ -31,7 +31,7 @@ public function getReadFilter() /** * {@inheritdoc} */ - public function getWriteFilter() + protected function writeFilter() { return 'zlib.inflate'; } diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index c3a06fc..67033ae 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -24,16 +24,22 @@ abstract class FilteredStream implements StreamInterface /** * @var resource + * + * @deprecated since version 1.5, will be removed in 2.0 */ protected $readFilter; /** * @var callable + * + * @deprecated since version 1.5, will be removed in 2.0 */ protected $writeFilterCallback; /** * @var resource + * + * @deprecated since version 1.5, will be removed in 2.0 */ protected $writeFilter; @@ -47,12 +53,17 @@ abstract class FilteredStream implements StreamInterface /** * @param StreamInterface $stream * @param mixed|null $readFilterOptions - * @param mixed|null $writeFilterOptions + * @param mixed|null $writeFilterOptions deprecated since 1.5, will be removed in 2.0 */ public function __construct(StreamInterface $stream, $readFilterOptions = null, $writeFilterOptions = null) { - $this->readFilterCallback = Filter\fun($this->getReadFilter(), $readFilterOptions); - $this->writeFilterCallback = Filter\fun($this->getWriteFilter(), $writeFilterOptions); + $this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions); + $this->writeFilterCallback = Filter\fun($this->writeFilter(), $writeFilterOptions); + + if (null !== $writeFilterOptions) { + @trigger_error('The $writeFilterOptions argument is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED); + } + $this->stream = $stream; } @@ -139,13 +150,41 @@ public function __toString() * Returns the read filter name. * * @return string + * + * @deprecated since version 1.5, will be removed in 2.0 + */ + public function getReadFilter() + { + @trigger_error('The '.__CLASS__.'::'.__METHOD__.' method is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED); + + return $this->readFilter(); + } + + /** + * Returns the write filter name. + * + * @return string */ - abstract public function getReadFilter(); + abstract protected function readFilter(); + + /** + * Returns the write filter name. + * + * @return string + * + * @deprecated since version 1.5, will be removed in 2.0 + */ + public function getWriteFilter() + { + @trigger_error('The '.__CLASS__.'::'.__METHOD__.' method is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED); + + return $this->writeFilter(); + } /** * Returns the write filter name. * * @return string */ - abstract public function getWriteFilter(); + abstract protected function writeFilter(); } diff --git a/src/Encoding/GzipDecodeStream.php b/src/Encoding/GzipDecodeStream.php index d87073c..4f958ed 100644 --- a/src/Encoding/GzipDecodeStream.php +++ b/src/Encoding/GzipDecodeStream.php @@ -27,7 +27,7 @@ public function __construct(StreamInterface $stream, $level = -1) /** * {@inheritdoc} */ - public function getReadFilter() + protected function readFilter() { return 'zlib.inflate'; } @@ -35,7 +35,7 @@ public function getReadFilter() /** * {@inheritdoc} */ - public function getWriteFilter() + protected function writeFilter() { return 'zlib.deflate'; } diff --git a/src/Encoding/GzipEncodeStream.php b/src/Encoding/GzipEncodeStream.php index 477f052..1066eec 100644 --- a/src/Encoding/GzipEncodeStream.php +++ b/src/Encoding/GzipEncodeStream.php @@ -27,7 +27,7 @@ public function __construct(StreamInterface $stream, $level = -1) /** * {@inheritdoc} */ - public function getReadFilter() + protected function readFilter() { return 'zlib.deflate'; } @@ -35,7 +35,7 @@ public function getReadFilter() /** * {@inheritdoc} */ - public function getWriteFilter() + protected function writeFilter() { return 'zlib.inflate'; } diff --git a/src/Encoding/InflateStream.php b/src/Encoding/InflateStream.php index e909db3..7070230 100644 --- a/src/Encoding/InflateStream.php +++ b/src/Encoding/InflateStream.php @@ -27,7 +27,7 @@ public function __construct(StreamInterface $stream, $level = -1) /** * {@inheritdoc} */ - public function getReadFilter() + protected function readFilter() { return 'zlib.inflate'; } @@ -35,7 +35,7 @@ public function getReadFilter() /** * {@inheritdoc} */ - public function getWriteFilter() + protected function writeFilter() { return 'zlib.deflate'; } From 71e1e0fa342cf1a0832688598ab4a9a0e46b8b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20J=2E=20Garc=C3=ADa=20Lagar?= Date: Wed, 19 Oct 2016 20:35:30 +0200 Subject: [PATCH 018/132] Fix FilteredStream::getSize returned value --- CHANGELOG.md | 4 ++++ spec/Encoding/ChunkStreamSpec.php | 8 ++++++++ spec/Encoding/CompressStreamSpec.php | 9 +++++++++ spec/Encoding/DechunkStreamSpec.php | 8 ++++++++ spec/Encoding/DecompressStreamSpec.php | 8 ++++++++ spec/Encoding/DeflateStreamSpec.php | 8 ++++++++ spec/Encoding/GzipDecodeStreamSpec.php | 8 ++++++++ spec/Encoding/GzipEncodeStreamSpec.php | 9 +++++++++ spec/Encoding/InflateStreamSpec.php | 8 ++++++++ src/Encoding/FilteredStream.php | 8 ++++++++ 10 files changed, 78 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aaadd4..c0c626b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +## Fixed + + - FilteredStream::getSize returns null because the contents size is unknown. + ### Deprecated - FilteredStream::getReadFilter The read filter is internal and should never be used by consuming code. diff --git a/spec/Encoding/ChunkStreamSpec.php b/spec/Encoding/ChunkStreamSpec.php index eff8a41..356795b 100644 --- a/spec/Encoding/ChunkStreamSpec.php +++ b/spec/Encoding/ChunkStreamSpec.php @@ -39,4 +39,12 @@ function it_chunks_in_multiple() $this->getContents()->shouldReturn("6\r\nThis i\r\n6\r\ns a st\r\n4\r\nream\r\n0\r\n\r\n"); } + + function it_does_not_know_the_content_size() + { + $stream = new MemoryStream('This is a stream'); + $this->beConstructedWith($stream, 6); + + $this->getSize()->shouldReturn(null); + } } diff --git a/spec/Encoding/CompressStreamSpec.php b/spec/Encoding/CompressStreamSpec.php index 4e96849..0a1bc22 100644 --- a/spec/Encoding/CompressStreamSpec.php +++ b/spec/Encoding/CompressStreamSpec.php @@ -41,4 +41,13 @@ function it_gets_content() $stream->rewind(); $this->getContents()->shouldReturn(gzcompress('This is a test stream')); } + + function it_does_not_know_the_content_size() + { + $stream = new MemoryStream('This is a test stream'); + $this->beConstructedWith($stream); + + $stream->rewind(); + $this->getSize()->shouldReturn(null); + } } diff --git a/spec/Encoding/DechunkStreamSpec.php b/spec/Encoding/DechunkStreamSpec.php index 715e33a..70608eb 100644 --- a/spec/Encoding/DechunkStreamSpec.php +++ b/spec/Encoding/DechunkStreamSpec.php @@ -40,4 +40,12 @@ function it_gets_content() $this->getContents()->shouldReturn('test'); } + + function it_does_not_know_the_content_size() + { + $stream = new MemoryStream("4\r\ntest\r\n4\r\ntest\r\n0\r\n\r\n\0"); + $this->beConstructedWith($stream); + + $this->getSize()->shouldReturn(null); + } } diff --git a/spec/Encoding/DecompressStreamSpec.php b/spec/Encoding/DecompressStreamSpec.php index d3295ff..12b7b21 100644 --- a/spec/Encoding/DecompressStreamSpec.php +++ b/spec/Encoding/DecompressStreamSpec.php @@ -41,4 +41,12 @@ function it_gets_content() $this->getContents()->shouldReturn('This is a test stream'); } + + function it_does_not_know_the_content_size() + { + $stream = new MemoryStream(gzcompress('This is a test stream')); + $this->beConstructedWith($stream); + + $this->getSize()->shouldReturn(null); + } } diff --git a/spec/Encoding/DeflateStreamSpec.php b/spec/Encoding/DeflateStreamSpec.php index 89c9406..ac6fa5a 100644 --- a/spec/Encoding/DeflateStreamSpec.php +++ b/spec/Encoding/DeflateStreamSpec.php @@ -36,4 +36,12 @@ function it_gets_content() $stream->rewind(); $this->getContents()->shouldReturn(gzdeflate('This is a test stream')); } + + function it_does_not_know_the_content_size() + { + $stream = new MemoryStream('This stream is a test stream'); + $this->beConstructedWith($stream); + + $this->getSize()->shouldReturn(null); + } } diff --git a/spec/Encoding/GzipDecodeStreamSpec.php b/spec/Encoding/GzipDecodeStreamSpec.php index 5243238..1e379b9 100644 --- a/spec/Encoding/GzipDecodeStreamSpec.php +++ b/spec/Encoding/GzipDecodeStreamSpec.php @@ -41,4 +41,12 @@ function it_gets_content() $this->getContents()->shouldReturn('This is a test stream'); } + + function it_does_not_know_the_content_size() + { + $stream = new MemoryStream(gzencode('This is a test stream')); + $this->beConstructedWith($stream); + + $this->getSize()->shouldReturn(null); + } } diff --git a/spec/Encoding/GzipEncodeStreamSpec.php b/spec/Encoding/GzipEncodeStreamSpec.php index b11d4c5..dd51b2b 100644 --- a/spec/Encoding/GzipEncodeStreamSpec.php +++ b/spec/Encoding/GzipEncodeStreamSpec.php @@ -41,4 +41,13 @@ function it_gets_content() $stream->rewind(); $this->getContents()->shouldReturn(gzencode('This is a test stream')); } + + function it_does_not_know_the_content_size() + { + $stream = new MemoryStream('This is a test stream'); + $this->beConstructedWith($stream); + + $stream->rewind(); + $this->getSize()->shouldReturn(null); + } } diff --git a/spec/Encoding/InflateStreamSpec.php b/spec/Encoding/InflateStreamSpec.php index 6dcd846..32e094e 100644 --- a/spec/Encoding/InflateStreamSpec.php +++ b/spec/Encoding/InflateStreamSpec.php @@ -36,4 +36,12 @@ function it_gets_content() $this->getContents()->shouldReturn('This is a test stream'); } + + function it_does_not_know_the_content_size() + { + $stream = new MemoryStream(gzdeflate('This stream is a test stream')); + $this->beConstructedWith($stream); + + $this->getSize()->shouldReturn(null); + } } diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index 67033ae..a32554b 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -138,6 +138,14 @@ public function getContents() return $buffer; } + /** + * {@inheritdoc} + */ + public function getSize() + { + return; + } + /** * {@inheritdoc} */ From 5fd6c761b994b16afaae4a236abb650e5a068b5a Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 16 Dec 2016 20:10:13 +0100 Subject: [PATCH 019/132] Fix cookie root path match for subdirectories. Refs #65 --- CHANGELOG.md | 8 ++++++++ spec/CookieSpec.php | 3 +++ src/Cookie.php | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80b06f1..5a3f7e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log + +## Unreleased + +### Fixed + +- Cookie::matchPath Cookie with root path (`/`) will not match sub path (e.g. `/cookie`). + + ## 1.4.0 - 2016-10-20 ### Added diff --git a/spec/CookieSpec.php b/spec/CookieSpec.php index 248968f..3c0c362 100644 --- a/spec/CookieSpec.php +++ b/spec/CookieSpec.php @@ -189,6 +189,7 @@ function it_matches_a_path() $this->beConstructedWith('name', 'value', null, null, '/path/to/somewhere'); $this->matchPath('/path/to/somewhere')->shouldReturn(true); + $this->matchPath('/path/to/somewhere/else')->shouldReturn(true); $this->matchPath('/path/to/somewhereelse')->shouldReturn(false); } @@ -197,6 +198,8 @@ function it_matches_the_root_path() $this->beConstructedWith('name', 'value', null, null, '/'); $this->matchPath('/')->shouldReturn(true); + $this->matchPath('/cookies')->shouldReturn(true); + $this->matchPath('/cookies/')->shouldReturn(true); } function it_is_secure() diff --git a/src/Cookie.php b/src/Cookie.php index 379089a..5022863 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -313,7 +313,7 @@ public function withPath($path) */ public function matchPath($path) { - return $this->path === $path || (strpos($path, $this->path.'/') === 0); + return $this->path === $path || (strpos($path, rtrim($this->path, '/').'/') === 0); } /** From bfd895a4e753bdde99bed64d75b999e0c9fa6147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Fri, 16 Dec 2016 22:09:21 +0100 Subject: [PATCH 020/132] Prepare release --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a3f7e3..227d4e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log -## Unreleased +## 1.4.1 - 2016-12-16 ### Fixed @@ -16,6 +16,7 @@ - BufferedStream that allow you to decorate a non-seekable stream with a seekable one. - cUrlFormatter to be able to redo the request with a cURL command + ## 1.3.1 - 2016-07-15 ### Fixed From 5265147265a13cbb201488130882c22d2597ec9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Wed, 4 Jan 2017 03:00:07 +0100 Subject: [PATCH 021/132] Add check for empty string to stream factories --- CHANGELOG.md | 4 ++++ src/StreamFactory/DiactorosStreamFactory.php | 2 +- src/StreamFactory/SlimStreamFactory.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60cf5a6..8749fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## Unreleased +## Added + +- Check for empty string in Stream factories + ## Fixed - FilteredStream::getSize returns null because the contents size is unknown. diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index 21690de..c1eb6fd 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -24,7 +24,7 @@ public function createStream($body = null) } else { $stream = new Stream('php://memory', 'rw'); - if (null !== $body) { + if (null !== $body || '' !== $body) { $stream->write((string) $body); } diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index e779f3b..167452b 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -28,7 +28,7 @@ public function createStream($body = null) $resource = fopen('php://memory', 'r+'); $stream = new Stream($resource); - if (null !== $body) { + if (null !== $body || '' !== $body) { $stream->write((string) $body); } } From e9c10414eb1b72314d98b34c4cb8709f8dce237d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Wed, 4 Jan 2017 19:26:08 +0100 Subject: [PATCH 022/132] Return stream when body is empty --- src/StreamFactory/DiactorosStreamFactory.php | 6 ++++-- src/StreamFactory/SlimStreamFactory.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index c1eb6fd..d3bed9d 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -24,10 +24,12 @@ public function createStream($body = null) } else { $stream = new Stream('php://memory', 'rw'); - if (null !== $body || '' !== $body) { - $stream->write((string) $body); + if (null === $body || '' === $body) { + return $stream; } + $stream->write((string) $body); + $body = $stream; } } diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index 167452b..32b9ac7 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -28,9 +28,11 @@ public function createStream($body = null) $resource = fopen('php://memory', 'r+'); $stream = new Stream($resource); - if (null !== $body || '' !== $body) { - $stream->write((string) $body); + if (null === $body || '' === $body) { + return $stream; } + + $stream->write((string) $body); } $stream->rewind(); From efe6a581187eb9e598343ac3310685cc2759b4d0 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 16 Jan 2017 12:23:43 +0100 Subject: [PATCH 023/132] Make sure we do not rewind a non-seekable stream --- spec/StreamFactory/DiactorosStreamFactorySpec.php | 8 ++++++++ spec/StreamFactory/GuzzleStreamFactorySpec.php | 8 ++++++++ spec/StreamFactory/SlimStreamFactorySpec.php | 8 ++++++++ src/StreamFactory/DiactorosStreamFactory.php | 4 +++- src/StreamFactory/SlimStreamFactory.php | 4 +++- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/spec/StreamFactory/DiactorosStreamFactorySpec.php b/spec/StreamFactory/DiactorosStreamFactorySpec.php index 372ef1b..c42428e 100644 --- a/spec/StreamFactory/DiactorosStreamFactorySpec.php +++ b/spec/StreamFactory/DiactorosStreamFactorySpec.php @@ -19,4 +19,12 @@ function it_creates_a_stream_from_stream() $this->createStream(new Stream('php://memory')) ->shouldHaveType('Psr\Http\Message\StreamInterface'); } + + function it_creates_a_stream_from_non_seekable_resource() + { + $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; + $resource = fopen($url, 'r'); + $this->createStream($resource) + ->shouldHaveType('Psr\Http\Message\StreamInterface'); + } } diff --git a/spec/StreamFactory/GuzzleStreamFactorySpec.php b/spec/StreamFactory/GuzzleStreamFactorySpec.php index 799a01d..cebffb5 100644 --- a/spec/StreamFactory/GuzzleStreamFactorySpec.php +++ b/spec/StreamFactory/GuzzleStreamFactorySpec.php @@ -19,4 +19,12 @@ public function it_creates_a_stream_from_stream() $this->createStream(new Stream(fopen('php://memory', 'rw'))) ->shouldHaveType('Psr\Http\Message\StreamInterface'); } + + function it_creates_a_stream_from_non_seekable_resource() + { + $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; + $resource = fopen($url, 'r'); + $this->createStream($resource) + ->shouldHaveType('Psr\Http\Message\StreamInterface'); + } } diff --git a/spec/StreamFactory/SlimStreamFactorySpec.php b/spec/StreamFactory/SlimStreamFactorySpec.php index c3bfef3..a3e8da0 100644 --- a/spec/StreamFactory/SlimStreamFactorySpec.php +++ b/spec/StreamFactory/SlimStreamFactorySpec.php @@ -23,4 +23,12 @@ function it_creates_a_stream_from_stream() $this->createStream(new Stream($resource)) ->shouldHaveType('Psr\Http\Message\StreamInterface'); } + + function it_creates_a_stream_from_non_seekable_resource() + { + $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; + $resource = fopen($url, 'r'); + $this->createStream($resource) + ->shouldHaveType('Psr\Http\Message\StreamInterface'); + } } diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index d3bed9d..a73abb0 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -34,7 +34,9 @@ public function createStream($body = null) } } - $body->rewind(); + if ($body->isSeekable()) { + $body->rewind(); + } return $body; } diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index 32b9ac7..ba0bb17 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -35,7 +35,9 @@ public function createStream($body = null) $stream->write((string) $body); } - $stream->rewind(); + if ($stream->isSeekable()) { + $stream->rewind(); + } return $stream; } From 4c297982853ef7d4d8c592db9c91231d93f125cd Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 16 Jan 2017 12:44:20 +0100 Subject: [PATCH 024/132] Put the test in the trait instead --- spec/StreamFactory/DiactorosStreamFactorySpec.php | 8 -------- spec/StreamFactory/GuzzleStreamFactorySpec.php | 8 -------- spec/StreamFactory/SlimStreamFactorySpec.php | 8 -------- spec/StreamFactory/StreamFactoryBehavior.php | 8 ++++++++ 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/spec/StreamFactory/DiactorosStreamFactorySpec.php b/spec/StreamFactory/DiactorosStreamFactorySpec.php index c42428e..372ef1b 100644 --- a/spec/StreamFactory/DiactorosStreamFactorySpec.php +++ b/spec/StreamFactory/DiactorosStreamFactorySpec.php @@ -19,12 +19,4 @@ function it_creates_a_stream_from_stream() $this->createStream(new Stream('php://memory')) ->shouldHaveType('Psr\Http\Message\StreamInterface'); } - - function it_creates_a_stream_from_non_seekable_resource() - { - $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; - $resource = fopen($url, 'r'); - $this->createStream($resource) - ->shouldHaveType('Psr\Http\Message\StreamInterface'); - } } diff --git a/spec/StreamFactory/GuzzleStreamFactorySpec.php b/spec/StreamFactory/GuzzleStreamFactorySpec.php index cebffb5..799a01d 100644 --- a/spec/StreamFactory/GuzzleStreamFactorySpec.php +++ b/spec/StreamFactory/GuzzleStreamFactorySpec.php @@ -19,12 +19,4 @@ public function it_creates_a_stream_from_stream() $this->createStream(new Stream(fopen('php://memory', 'rw'))) ->shouldHaveType('Psr\Http\Message\StreamInterface'); } - - function it_creates_a_stream_from_non_seekable_resource() - { - $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; - $resource = fopen($url, 'r'); - $this->createStream($resource) - ->shouldHaveType('Psr\Http\Message\StreamInterface'); - } } diff --git a/spec/StreamFactory/SlimStreamFactorySpec.php b/spec/StreamFactory/SlimStreamFactorySpec.php index a3e8da0..c3bfef3 100644 --- a/spec/StreamFactory/SlimStreamFactorySpec.php +++ b/spec/StreamFactory/SlimStreamFactorySpec.php @@ -23,12 +23,4 @@ function it_creates_a_stream_from_stream() $this->createStream(new Stream($resource)) ->shouldHaveType('Psr\Http\Message\StreamInterface'); } - - function it_creates_a_stream_from_non_seekable_resource() - { - $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; - $resource = fopen($url, 'r'); - $this->createStream($resource) - ->shouldHaveType('Psr\Http\Message\StreamInterface'); - } } diff --git a/spec/StreamFactory/StreamFactoryBehavior.php b/spec/StreamFactory/StreamFactoryBehavior.php index 88ab4f4..afc67ef 100644 --- a/spec/StreamFactory/StreamFactoryBehavior.php +++ b/spec/StreamFactory/StreamFactoryBehavior.php @@ -24,4 +24,12 @@ function it_creates_a_stream_from_null() { $this->createStream(null)->shouldHaveType('Psr\Http\Message\StreamInterface'); } + + function it_creates_a_stream_from_non_seekable_resource() + { + $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; + $resource = fopen($url, 'r'); + $this->createStream($resource) + ->shouldHaveType('Psr\Http\Message\StreamInterface'); + } } From 6ffe75accb46d5381379bb1d11de7819acb94d58 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 12 Feb 2017 09:03:19 +0100 Subject: [PATCH 025/132] Do not rewind streams (#72) * Test if we rewind existing stream/resource * Do not rewind any stream --- spec/StreamFactory/StreamFactoryBehavior.php | 32 ++++++++++++++++++++ src/StreamFactory/DiactorosStreamFactory.php | 25 ++++++--------- src/StreamFactory/SlimStreamFactory.php | 17 +++-------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/spec/StreamFactory/StreamFactoryBehavior.php b/spec/StreamFactory/StreamFactoryBehavior.php index afc67ef..f78a1c6 100644 --- a/spec/StreamFactory/StreamFactoryBehavior.php +++ b/spec/StreamFactory/StreamFactoryBehavior.php @@ -2,6 +2,9 @@ namespace spec\Http\Message\StreamFactory; +use GuzzleHttp\Psr7\Stream; +use Psr\Http\Message\StreamInterface; + trait StreamFactoryBehavior { function it_is_a_stream_factory() @@ -32,4 +35,33 @@ function it_creates_a_stream_from_non_seekable_resource() $this->createStream($resource) ->shouldHaveType('Psr\Http\Message\StreamInterface'); } + + function it_does_not_rewind_existing_stream() + { + $stream = new Stream(fopen('php://memory', 'rw')); + $stream->write('abcdef'); + $stream->seek(3); + + $this->createStream($stream) + ->shouldHaveContent('def'); + } + + function it_does_not_rewind_existing_resource() + { + $resource = fopen('php://memory', 'rw'); + fwrite($resource, 'abcdef'); + fseek($resource, 3); + + $this->createStream($resource) + ->shouldHaveContent('def'); + } + + public function getMatchers() + { + return [ + 'haveContent' => function (StreamInterface $subject, $key) { + return $subject->getContents() === $key; + }, + ]; + } } diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index a73abb0..a75ec98 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -18,26 +18,19 @@ final class DiactorosStreamFactory implements StreamFactory */ public function createStream($body = null) { - if (!$body instanceof StreamInterface) { - if (is_resource($body)) { - $body = new Stream($body); - } else { - $stream = new Stream('php://memory', 'rw'); - - if (null === $body || '' === $body) { - return $stream; - } - - $stream->write((string) $body); + if ($body instanceof StreamInterface) { + return $body; + } - $body = $stream; - } + if (is_resource($body)) { + return new Stream($body); } - if ($body->isSeekable()) { - $body->rewind(); + $stream = new Stream('php://memory', 'rw'); + if (null !== $body && '' !== $body) { + $stream->write((string) $body); } - return $body; + return $stream; } } diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index ba0bb17..efcadc4 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -23,20 +23,13 @@ public function createStream($body = null) } if (is_resource($body)) { - $stream = new Stream($body); - } else { - $resource = fopen('php://memory', 'r+'); - $stream = new Stream($resource); - - if (null === $body || '' === $body) { - return $stream; - } - - $stream->write((string) $body); + return new Stream($body); } - if ($stream->isSeekable()) { - $stream->rewind(); + $resource = fopen('php://memory', 'r+'); + $stream = new Stream($resource); + if (null !== $body && '' !== $body) { + $stream->write((string) $body); } return $stream; From 72d7e28cba51a81275153c4e7c5a15c536f2fc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20J=2E=20Garc=C3=ADa=20Lagar?= Date: Mon, 13 Feb 2017 16:11:53 +0100 Subject: [PATCH 026/132] Optional cookie validation (#68) * Specification for optional cookie validation * Adds Cookie::createWithoutValidation and Cookie::isValid Adds a named constructor to avoid cookie attributes validation during instantination, and a method to check if cookie attributes are valid. * Creates new cookie instance with dummy name to bypass constructor validation * Remove deprecation of attribute validation in Cookie::__construct * Adds docblock to Cookie::createWithoutValidation * Drop use of dataProvider in Cookie::createWithoutValidation spec --- CHANGELOG.md | 12 +++++++----- spec/CookieSpec.php | 26 ++++++++++++++++++++++++ src/Cookie.php | 48 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8749fd4..c178eb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,18 +3,20 @@ ## Unreleased -## Added +### Added - Check for empty string in Stream factories +- Cookie::createWithoutValidation Static constructor to create a cookie. Will not perform any attribute validation during instantiation. +- Cookie::isValid Method to check if cookie attributes are valid. -## Fixed +### Fixed - - FilteredStream::getSize returns null because the contents size is unknown. +- FilteredStream::getSize returns null because the contents size is unknown. ### Deprecated - - FilteredStream::getReadFilter The read filter is internal and should never be used by consuming code. - - FilteredStream::getWriteFilter We did not implement writing to the streams at all. And if we do, the filter is an internal information and should not be used by consuming code. +- FilteredStream::getReadFilter The read filter is internal and should never be used by consuming code. +- FilteredStream::getWriteFilter We did not implement writing to the streams at all. And if we do, the filter is an internal information and should not be used by consuming code. ## 1.4.1 - 2016-12-16 diff --git a/spec/CookieSpec.php b/spec/CookieSpec.php index 3c0c362..3de69f3 100644 --- a/spec/CookieSpec.php +++ b/spec/CookieSpec.php @@ -239,6 +239,32 @@ function it_matches_other_cookies() $this->match($notMatches)->shouldReturn(false); } + function it_validates_itself() + { + $this->isValid()->shouldReturn(true); + } + + function it_can_be_constructed_without_name_validation() + { + $this->beConstructedThrough('createWithoutValidation', ["\x20"]); + + $this->isValid()->shouldReturn(false); + } + + function it_can_be_constructed_without_value_validation() + { + $this->beConstructedThrough('createWithoutValidation', ['name', "\x20"]); + + $this->isValid()->shouldReturn(false); + } + + function it_can_be_constructed_without_max_age_validation() + { + $this->beConstructedThrough('createWithoutValidation', ['name', 'value', '-1']); + + $this->isValid()->shouldReturn(false); + } + /** * Provides examples for invalid characers in names and values. * diff --git a/src/Cookie.php b/src/Cookie.php index 5022863..5f61b90 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -89,6 +89,36 @@ public function __construct( $this->httpOnly = (bool) $httpOnly; } + /** + * Creates a new cookie without any attribute validation. + * + * @param string $name + * @param string|null $value + * @param int $maxAge + * @param string|null $domain + * @param string|null $path + * @param bool $secure + * @param bool $httpOnly + * @param \DateTime|null $expires Expires attribute is HTTP 1.0 only and should be avoided. + */ + public static function createWithoutValidation( + $name, + $value = null, + $maxAge = null, + $domain = null, + $path = null, + $secure = false, + $httpOnly = false, + \DateTime $expires = null + ) { + $cookie = new self('name', null, null, $domain, $path, $secure, $httpOnly, $expires); + $cookie->name = $name; + $cookie->value = $value; + $cookie->maxAge = $maxAge; + + return $cookie; + } + /** * Returns the name. * @@ -380,6 +410,24 @@ public function match(Cookie $cookie) return $this->name === $cookie->name && $this->domain === $cookie->domain and $this->path === $cookie->path; } + /** + * Validates cookie attributes. + * + * @return bool + */ + public function isValid() + { + try { + $this->validateName($this->name); + $this->validateValue($this->value); + $this->validateMaxAge($this->maxAge); + } catch (\InvalidArgumentException $e) { + return false; + } + + return true; + } + /** * Validates the name attribute. * From 13df8c48f40ca7925303aa336f19be4b80984f01 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 14 Feb 2017 09:58:37 +0100 Subject: [PATCH 027/132] Prepare for 1.5.0 (#74) --- CHANGELOG.md | 3 +++ composer.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c178eb9..4113311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## Unreleased +## 1.5.0 - 2017-02-14 + ### Added - Check for empty string in Stream factories @@ -12,6 +14,7 @@ ### Fixed - FilteredStream::getSize returns null because the contents size is unknown. +- Stream factories does not rewinds streams. The previous behavior was not coherent between factories and inputs. ### Deprecated diff --git a/composer.json b/composer.json index 5658119..2a0fa45 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.5-dev" + "dev-master": "1.6-dev" } } } From 9353cb2afe8c440f42b00ea200b29dc3819b9c21 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 14 Jun 2017 08:38:50 +0200 Subject: [PATCH 028/132] build hhvm on trusty box --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1d51b60..fc08ee1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,6 @@ php: - 5.6 - 7.0 - 7.1 - - hhvm env: global: @@ -27,6 +26,8 @@ matrix: include: - php: 5.4 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" + - php: hhvm + dist: trusty before_install: - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi From caa5344b22239cc39854b38805e9583a99c9c706 Mon Sep 17 00:00:00 2001 From: adev Date: Mon, 12 Jun 2017 22:03:49 +0200 Subject: [PATCH 029/132] Implements a cookie-date parsing utility @see https://github.com/php-http/client-common/pull/46 --- CHANGELOG.md | 4 ++ spec/CookieUtilSpec.php | 76 ++++++++++++++++++++++ src/CookieUtil.php | 53 +++++++++++++++ src/Exception.php | 10 +++ src/Exception/UnexpectedValueException.php | 9 +++ 5 files changed, 152 insertions(+) create mode 100644 spec/CookieUtilSpec.php create mode 100644 src/CookieUtil.php create mode 100644 src/Exception.php create mode 100644 src/Exception/UnexpectedValueException.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4113311..7511b80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## Unreleased +### Added + +- CookieUtil::parseDate to create a date from cookie date string + ## 1.5.0 - 2017-02-14 ### Added diff --git a/spec/CookieUtilSpec.php b/spec/CookieUtilSpec.php new file mode 100644 index 0000000..f2fac15 --- /dev/null +++ b/spec/CookieUtilSpec.php @@ -0,0 +1,76 @@ +beConstructedThrough('parseDate', [$cookieDateString]); + $this->shouldHaveType('\DateTime'); + $this->format('l, d-M-Y H:i:s O')->shouldReturn($expectedString); + } + + /** + * @dataProvider getInvalidCookieDateStrings + */ + function it_throws_an_exception_if_cookie_date_string_is_unparseable($cookieDateString) + { + $this->beConstructedThrough('parseDate', [$cookieDateString]); + $this->shouldThrow('Http\Message\Exception\UnexpectedValueException'); + } + + /** + * Provides examples for valid cookie date string. + * + * @return array + */ + public function getCookieStrings() + { + return [ + ['Friday, 31 Jul 20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], + ['Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], + ['Fri, 31-Jul-2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], + ['Fri, 31 Jul 2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], + ['Fri, 31-07-2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], + ['Fri, 31-07-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], + ['Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], + ['Fri Jul 31 08:49:37 2020', 'Friday, 31-Jul-2020 08:49:37 +0000'], + ['Friday July 31st 2020, 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + ['Wed, 09 Jun 2021 10:18:14 GMT', 'Wednesday, 09-Jun-2021 10:18:14 +0000'], + ['Wed, 09 Jun 2021 22:18:14 GMT', 'Wednesday, 09-Jun-2021 22:18:14 +0000'], + ['Tue, 18 Oct 2011 07:42:42.123 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'], + ['18 Oct 2011 07:42:42 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'], + ['8 Oct 2011 7:42:42 GMT', 'Saturday, 08-Oct-2011 07:42:42 +0000'], + ['8 Oct 2011 7:2:42 GMT', 'Saturday, 08-Oct-2011 07:02:42 +0000'], + ['Oct 18 2011 07:42:42 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'], + ['Tue Oct 18 2011 07:05:03 GMT+0000 (GMT)', 'Tuesday, 18-Oct-2011 07:05:03 +0000'], + ['09 Jun 2021 10:18:14 GMT', 'Wednesday, 09-Jun-2021 10:18:14 +0000'], + ['01 Jan 1970 00:00:00 GMT', 'Thursday, 01-Jan-1970 00:00:00 +0000'], + ['01 Jan 1601 00:00:00 GMT', 'Monday, 01-Jan-1601 00:00:00 +0000'], + ['10 Feb 81 13:00:00 GMT', 'Tuesday, 10-Feb-1981 13:00:00 +0000'], // implicit year + ['Thu, 17-Apr-2014 02:12:29 GMT', 'Thursday, 17-Apr-2014 02:12:29 +0000'], // dashes + ['Thu, 17-Apr-2014 02:12:29 UTC', 'Thursday, 17-Apr-2014 02:12:29 +0000'], // dashes and UTC + ]; + } + + /** + * Provides examples for invalid cookie date string. + * + * @return array + */ + public function getInvalidCookieDateStrings() + { + return [ + ['Flursday July 31st 2020, 08:49:37 GMT'], + ['99 Jix 3038 48:86:72 ZMT'], + ]; + } +} diff --git a/src/CookieUtil.php b/src/CookieUtil.php new file mode 100644 index 0000000..5c670d4 --- /dev/null +++ b/src/CookieUtil.php @@ -0,0 +1,53 @@ + Date: Fri, 23 Jun 2017 09:38:22 +0200 Subject: [PATCH 030/132] Prepare for 1.6 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7511b80..a92f950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log -## Unreleased +## 1.6.0 - 2017-06-23 ### Added From aa70fb84b992bed514ad3cf1bfd3df0eb8af3b21 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 23 Jun 2017 11:41:19 +0200 Subject: [PATCH 031/132] Added provide for php-http/message-factory-implementation, fixes #75 (#80) --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 2a0fa45..6fbc5db 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,9 @@ "php-http/message-factory": "^1.0.2", "clue/stream-filter": "^1.3" }, + "provide": { + "php-http/message-factory-implementation": "1.0" + }, "require-dev": { "zendframework/zend-diactoros": "^1.0", "guzzlehttp/psr7": "^1.0", From 05aea156caad2356bbd97231caaabc1531f35936 Mon Sep 17 00:00:00 2001 From: adev Date: Wed, 28 Jun 2017 22:58:24 +0200 Subject: [PATCH 032/132] Fix curl command of CurlFormatter when there is an user-agent header --- CHANGELOG.md | 4 ++++ spec/Formatter/CurlCommandFormatterSpec.php | 14 ++++++++++++++ src/Formatter/CurlCommandFormatter.php | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7511b80..65b054b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - CookieUtil::parseDate to create a date from cookie date string +### Fixed + +- Fix curl command of CurlFormatter when there is an user-agent header + ## 1.5.0 - 2017-02-14 ### Added diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php index 50fd374..4352827 100644 --- a/spec/Formatter/CurlCommandFormatterSpec.php +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -58,4 +58,18 @@ function it_does_nothing_for_response(ResponseInterface $response) { $this->formatResponse($response)->shouldReturn(''); } + + function it_formats_the_request_with_user_agent(RequestInterface $request, UriInterface $uri, StreamInterface $body) + { + $request->getUri()->willReturn($uri); + $request->getBody()->willReturn($body); + + $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); + $request->getMethod()->willReturn('GET'); + $request->getProtocolVersion()->willReturn('1.1'); + $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); + $request->getHeaders()->willReturn(['user-agent'=>['foobar-browser']]); + + $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' -A 'foobar-browser'"); + } } diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 5364ccc..a0fe7e5 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -68,7 +68,7 @@ private function getHeadersAsCommandOptions(RequestInterface $request) } if ('user-agent' === strtolower($name)) { - $command .= sprintf('-A %s', escapeshellarg($values[0])); + $command .= sprintf(' -A %s', escapeshellarg($values[0])); continue; } From 3a3e3406b80a82fd6bf6bc534f38829223f481e0 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 5 Jul 2017 08:28:32 +0200 Subject: [PATCH 033/132] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a92f950..ca35601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log -## 1.6.0 - 2017-06-23 +## 1.6.0 - 2017-07-05 ### Added From 0ee4bfb4b3a823405976e311df1596c8a2409e62 Mon Sep 17 00:00:00 2001 From: Christopher L Bray Date: Thu, 23 Nov 2017 09:27:46 +0000 Subject: [PATCH 034/132] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 338b415..f6f6e19 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ $ composer test Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html). -## Cretids +## Credits Thanks to [Cuzzle](https://github.com/namshi/cuzzle) for inpiration for the `CurlCommandFormatter`. From d38102398ae5cfa433cef56af926cbb86ebebb3e Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 23 Nov 2017 10:42:26 +0100 Subject: [PATCH 035/132] Require php-stream-filter 1.4 This will avoid some bugs in 1.3. This will fix #78 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6fbc5db..3769d2a 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php": ">=5.4", "psr/http-message": "^1.0", "php-http/message-factory": "^1.0.2", - "clue/stream-filter": "^1.3" + "clue/stream-filter": "^1.4" }, "provide": { "php-http/message-factory-implementation": "1.0" From f13200ba46c511282b16f16877631647ce72480e Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 23 Nov 2017 23:06:03 +0000 Subject: [PATCH 036/132] Apply fixes from StyleCI --- src/Builder/ResponseBuilder.php | 4 ++-- src/Cookie.php | 8 ++++---- src/Encoding/FilteredStream.php | 4 ++-- src/Formatter/CurlCommandFormatter.php | 5 +++-- src/Formatter/FullHttpMessageFormatter.php | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Builder/ResponseBuilder.php b/src/Builder/ResponseBuilder.php index e6933a0..de2e882 100644 --- a/src/Builder/ResponseBuilder.php +++ b/src/Builder/ResponseBuilder.php @@ -104,7 +104,7 @@ public function setHeadersFromString($headers) public function setStatus($statusLine) { $parts = explode(' ', $statusLine, 3); - if (count($parts) < 2 || strpos(strtolower($parts[0]), 'http/') !== 0) { + if (count($parts) < 2 || 0 !== strpos(strtolower($parts[0]), 'http/')) { throw new \InvalidArgumentException( sprintf('"%s" is not a valid HTTP status line', $statusLine) ); @@ -130,7 +130,7 @@ public function setStatus($statusLine) public function addHeader($headerLine) { $parts = explode(':', $headerLine, 2); - if (count($parts) !== 2) { + if (2 !== count($parts)) { throw new \InvalidArgumentException( sprintf('"%s" is not a valid HTTP header line', $headerLine) ); diff --git a/src/Cookie.php b/src/Cookie.php index 5f61b90..962ac72 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -295,7 +295,7 @@ public function withDomain($domain) public function matchDomain($domain) { // Domain is not set or exact match - if (!$this->hasDomain() || strcasecmp($domain, $this->domain) === 0) { + if (!$this->hasDomain() || 0 === strcasecmp($domain, $this->domain)) { return true; } @@ -343,7 +343,7 @@ public function withPath($path) */ public function matchPath($path) { - return $this->path === $path || (strpos($path, rtrim($this->path, '/').'/') === 0); + return $this->path === $path || (0 === strpos($path, rtrim($this->path, '/').'/')); } /** @@ -405,7 +405,7 @@ public function withHttpOnly($httpOnly) * * @return bool */ - public function match(Cookie $cookie) + public function match(self $cookie) { return $this->name === $cookie->name && $this->domain === $cookie->domain and $this->path === $cookie->path; } @@ -517,7 +517,7 @@ private function normalizePath($path) { $path = rtrim($path, '/'); - if (empty($path) or substr($path, 0, 1) !== '/') { + if (empty($path) or '/' !== substr($path, 0, 1)) { $path = '/'; } diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index a32554b..4b296ed 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -98,7 +98,7 @@ public function read($length) */ public function eof() { - return $this->stream->eof() && $this->buffer === ''; + return $this->stream->eof() && '' === $this->buffer; } /** @@ -128,7 +128,7 @@ public function getContents() while (!$this->eof()) { $buf = $this->read(self::BUFFER_SIZE); // Using a loose equality here to match on '' and false. - if ($buf == null) { + if (null == $buf) { break; } diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index a0fe7e5..f0375fd 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -19,9 +19,9 @@ class CurlCommandFormatter implements Formatter public function formatRequest(RequestInterface $request) { $command = sprintf('curl %s', escapeshellarg((string) $request->getUri()->withFragment(''))); - if ($request->getProtocolVersion() === '1.0') { + if ('1.0' === $request->getProtocolVersion()) { $command .= ' --http1.0'; - } elseif ($request->getProtocolVersion() === '2.0') { + } elseif ('2.0' === $request->getProtocolVersion()) { $command .= ' --http2'; } @@ -69,6 +69,7 @@ private function getHeadersAsCommandOptions(RequestInterface $request) if ('user-agent' === strtolower($name)) { $command .= sprintf(' -A %s', escapeshellarg($values[0])); + continue; } diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index 3fa1029..1918c59 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -78,7 +78,7 @@ public function formatResponse(ResponseInterface $response) private function addBody(MessageInterface $request, $message) { $stream = $request->getBody(); - if (!$stream->isSeekable() || $this->maxBodyLength === 0) { + if (!$stream->isSeekable() || 0 === $this->maxBodyLength) { // Do not read the stream $message .= "\n"; } else { From 2cbeffcff4f5159499bd625ebc6c34ed3e0013c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Luke=C5=A1?= Date: Fri, 24 Nov 2017 21:01:45 +0100 Subject: [PATCH 037/132] Cookie.php fixed invalid PHPDoc parameter $maxAge is nullable and its PHPDoc should reflect that --- src/Cookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cookie.php b/src/Cookie.php index 962ac72..98ac57c 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -56,7 +56,7 @@ final class Cookie /** * @param string $name * @param string|null $value - * @param int $maxAge + * @param int|null $maxAge * @param string|null $domain * @param string|null $path * @param bool $secure From 3b410c569110b30be693d0ce480c1197456b79f7 Mon Sep 17 00:00:00 2001 From: z38 Date: Mon, 22 Jan 2018 15:36:58 +0100 Subject: [PATCH 038/132] Improve formatting of requests with binary streams --- CHANGELOG.md | 7 ++++ spec/Formatter/CurlCommandFormatterSpec.php | 36 +++++++++++++++++++++ src/Formatter/CurlCommandFormatter.php | 13 +++++--- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7676349..1cf58e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log +## Unreleased + +### Fixed + +- Fix CurlCommandFormatter for binary request payloads + + ## 1.6.0 - 2017-07-05 ### Added diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php index 4352827..5340b62 100644 --- a/spec/Formatter/CurlCommandFormatterSpec.php +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -72,4 +72,40 @@ function it_formats_the_request_with_user_agent(RequestInterface $request, UriIn $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' -A 'foobar-browser'"); } + + function it_formats_requests_with_null_bytes(RequestInterface $request, UriInterface $uri, StreamInterface $body) + { + $request->getUri()->willReturn($uri); + $request->getBody()->willReturn($body); + + $body->__toString()->willReturn("\0"); + $body->getSize()->willReturn(1); + $body->isSeekable()->willReturn(true); + $body->rewind()->willReturn(true); + + $uri->withFragment('')->willReturn('http://foo.com/bar'); + $request->getMethod()->willReturn('POST'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([]); + + $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[binary stream omitted]'"); + } + + function it_formats_requests_with_nonseekable_body(RequestInterface $request, UriInterface $uri, StreamInterface $body) + { + $request->getUri()->willReturn($uri); + $request->getBody()->willReturn($body); + + $body->getSize()->willReturn(1); + $body->isSeekable()->willReturn(false); + $body->__toString()->shouldNotBeCalled(); + $body->rewind()->shouldNotBeCalled(); + + $uri->withFragment('')->willReturn('http://foo.com/bar'); + $request->getMethod()->willReturn('POST'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([]); + + $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[non-seekable stream omitted]'"); + } } diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index f0375fd..5cdd427 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -36,11 +36,16 @@ public function formatRequest(RequestInterface $request) $body = $request->getBody(); if ($body->getSize() > 0) { - if (!$body->isSeekable()) { - return 'Cant format Request as cUrl command if body stream is not seekable.'; + if ($body->isSeekable()) { + $data = $body->__toString(); + $body->rewind(); + if (preg_match('/[\x00-\x1F\x7F]/', $data)) { + $data = '[binary stream omitted]'; + } + } else { + $data = '[non-seekable stream omitted]'; } - $command .= sprintf(' --data %s', escapeshellarg($body->__toString())); - $body->rewind(); + $command .= sprintf(' --data %s', escapeshellarg($data)); } return $command; From d11c28621d19a2f8c85b847ece39c1f865febe75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Mon, 7 May 2018 02:33:55 +0200 Subject: [PATCH 039/132] Force proper arg separator to avoid assembling broken URLs --- CHANGELOG.md | 1 + src/Authentication/QueryParam.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cf58e1..cb05a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixed - Fix CurlCommandFormatter for binary request payloads +- Fix QueryParam authentication to assemble proper URL regardless of PHP `arg_separator.output` directive ## 1.6.0 - 2017-07-05 diff --git a/src/Authentication/QueryParam.php b/src/Authentication/QueryParam.php index 14b58ff..650cac7 100644 --- a/src/Authentication/QueryParam.php +++ b/src/Authentication/QueryParam.php @@ -41,7 +41,7 @@ public function authenticate(RequestInterface $request) $params = array_merge($params, $this->params); - $query = http_build_query($params); + $query = http_build_query($params, null, '&'); $uri = $uri->withQuery($query); From 4d14e9e4cc720319c2aa2153f13995d48078a76e Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 8 May 2018 14:24:19 +0200 Subject: [PATCH 040/132] drop hhvm support as its no longer working --- .travis.yml | 2 -- composer.json | 2 +- spec/Encoding/ChunkStreamSpec.php | 4 ---- spec/Encoding/CompressStreamSpec.php | 4 ---- spec/Encoding/DechunkStreamSpec.php | 4 ---- spec/Encoding/DecompressStreamSpec.php | 4 ---- spec/Encoding/GzipDecodeStreamSpec.php | 4 ---- spec/Encoding/GzipEncodeStreamSpec.php | 4 ---- 8 files changed, 1 insertion(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index fc08ee1..21b2f27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,6 @@ matrix: include: - php: 5.4 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" - - php: hhvm - dist: trusty before_install: - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi diff --git a/composer.json b/composer.json index 3769d2a..3a9b3ed 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=5.4", + "php": "^5.4 || ^7.0", "psr/http-message": "^1.0", "php-http/message-factory": "^1.0.2", "clue/stream-filter": "^1.4" diff --git a/spec/Encoding/ChunkStreamSpec.php b/spec/Encoding/ChunkStreamSpec.php index 356795b..68a078e 100644 --- a/spec/Encoding/ChunkStreamSpec.php +++ b/spec/Encoding/ChunkStreamSpec.php @@ -12,10 +12,6 @@ class ChunkStreamSpec extends ObjectBehavior function let(StreamInterface $stream) { - if (defined('HHVM_VERSION')) { - throw new SkippingException('Skipping test as there is no dechunk filter on hhvm'); - } - $this->beConstructedWith($stream); } diff --git a/spec/Encoding/CompressStreamSpec.php b/spec/Encoding/CompressStreamSpec.php index 0a1bc22..04efda6 100644 --- a/spec/Encoding/CompressStreamSpec.php +++ b/spec/Encoding/CompressStreamSpec.php @@ -12,10 +12,6 @@ class CompressStreamSpec extends ObjectBehavior function let(StreamInterface $stream) { - if (defined('HHVM_VERSION')) { - throw new SkippingException('Skipping test as zlib is not working on hhvm'); - } - $this->beConstructedWith($stream); } diff --git a/spec/Encoding/DechunkStreamSpec.php b/spec/Encoding/DechunkStreamSpec.php index 70608eb..3616d1b 100644 --- a/spec/Encoding/DechunkStreamSpec.php +++ b/spec/Encoding/DechunkStreamSpec.php @@ -12,10 +12,6 @@ class DechunkStreamSpec extends ObjectBehavior function let(StreamInterface $stream) { - if (defined('HHVM_VERSION')) { - throw new SkippingException('Skipping test as there is no dechunk filter on hhvm'); - } - $this->beConstructedWith($stream); } diff --git a/spec/Encoding/DecompressStreamSpec.php b/spec/Encoding/DecompressStreamSpec.php index 12b7b21..baafad0 100644 --- a/spec/Encoding/DecompressStreamSpec.php +++ b/spec/Encoding/DecompressStreamSpec.php @@ -12,10 +12,6 @@ class DecompressStreamSpec extends ObjectBehavior function let(StreamInterface $stream) { - if (defined('HHVM_VERSION')) { - throw new SkippingException('Skipping test as zlib is not working on hhvm'); - } - $this->beConstructedWith($stream); } diff --git a/spec/Encoding/GzipDecodeStreamSpec.php b/spec/Encoding/GzipDecodeStreamSpec.php index 1e379b9..17b8dea 100644 --- a/spec/Encoding/GzipDecodeStreamSpec.php +++ b/spec/Encoding/GzipDecodeStreamSpec.php @@ -12,10 +12,6 @@ class GzipDecodeStreamSpec extends ObjectBehavior function let(StreamInterface $stream) { - if (defined('HHVM_VERSION')) { - throw new SkippingException('Skipping test as zlib is not working on hhvm'); - } - $this->beConstructedWith($stream); } diff --git a/spec/Encoding/GzipEncodeStreamSpec.php b/spec/Encoding/GzipEncodeStreamSpec.php index dd51b2b..2037be5 100644 --- a/spec/Encoding/GzipEncodeStreamSpec.php +++ b/spec/Encoding/GzipEncodeStreamSpec.php @@ -12,10 +12,6 @@ class GzipEncodeStreamSpec extends ObjectBehavior function let(StreamInterface $stream) { - if (defined('HHVM_VERSION')) { - throw new SkippingException('Skipping test as zlib is not working on hhvm'); - } - $this->beConstructedWith($stream); } From a64944c1ffb24608a31adcf9d696cd1dd570c7f4 Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Mon, 9 Jul 2018 11:50:13 +0200 Subject: [PATCH 041/132] Filtered Stream is not seekable --- src/Encoding/FilteredStream.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index 4b296ed..ffe76d7 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -154,6 +154,30 @@ public function __toString() return $this->getContents(); } + /** + * {@inheritdoc} + */ + public function isSeekable() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function rewind() + { + throw new \RuntimeException('Cannot rewind a filtered stream'); + } + + /** + * {@inheritdoc} + */ + public function seek($offset, $whence = SEEK_SET) + { + throw new \RuntimeException('Cannot seek a filtered stream'); + } + /** * Returns the read filter name. * From 3583ac0dda7012541afc79ee1f0f4ef20c2a17ae Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Mon, 9 Jul 2018 11:57:11 +0200 Subject: [PATCH 042/132] Remove internal deprecation notice --- src/Encoding/CompressStream.php | 6 +++++- src/Encoding/DecompressStream.php | 6 +++++- src/Encoding/DeflateStream.php | 6 +++++- src/Encoding/GzipDecodeStream.php | 6 +++++- src/Encoding/GzipEncodeStream.php | 6 +++++- src/Encoding/InflateStream.php | 6 +++++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Encoding/CompressStream.php b/src/Encoding/CompressStream.php index d1013dc..eeec6e0 100644 --- a/src/Encoding/CompressStream.php +++ b/src/Encoding/CompressStream.php @@ -2,6 +2,7 @@ namespace Http\Message\Encoding; +use Clue\StreamFilter as Filter; use Psr\Http\Message\StreamInterface; /** @@ -21,7 +22,10 @@ public function __construct(StreamInterface $stream, $level = -1) throw new \RuntimeException('The zlib extension must be enabled to use this stream'); } - parent::__construct($stream, ['window' => 15, 'level' => $level], ['window' => 15]); + parent::__construct($stream, ['window' => 15, 'level' => $level]); + + // @deprecated will be removed in 2.0 + $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 15]); } /** diff --git a/src/Encoding/DecompressStream.php b/src/Encoding/DecompressStream.php index 4e3a723..9a950ea 100644 --- a/src/Encoding/DecompressStream.php +++ b/src/Encoding/DecompressStream.php @@ -2,6 +2,7 @@ namespace Http\Message\Encoding; +use Clue\StreamFilter as Filter; use Psr\Http\Message\StreamInterface; /** @@ -21,7 +22,10 @@ public function __construct(StreamInterface $stream, $level = -1) throw new \RuntimeException('The zlib extension must be enabled to use this stream'); } - parent::__construct($stream, ['window' => 15], ['window' => 15, 'level' => $level]); + parent::__construct($stream, ['window' => 15]); + + // @deprecated will be removed in 2.0 + $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 15, 'level' => $level]); } /** diff --git a/src/Encoding/DeflateStream.php b/src/Encoding/DeflateStream.php index 1d7344b..f7ce8e2 100644 --- a/src/Encoding/DeflateStream.php +++ b/src/Encoding/DeflateStream.php @@ -2,6 +2,7 @@ namespace Http\Message\Encoding; +use Clue\StreamFilter as Filter; use Psr\Http\Message\StreamInterface; /** @@ -17,7 +18,10 @@ class DeflateStream extends FilteredStream */ public function __construct(StreamInterface $stream, $level = -1) { - parent::__construct($stream, ['window' => -15, 'level' => $level], ['window' => -15]); + parent::__construct($stream, ['window' => -15, 'level' => $level]); + + // @deprecated will be removed in 2.0 + $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => -15]); } /** diff --git a/src/Encoding/GzipDecodeStream.php b/src/Encoding/GzipDecodeStream.php index 4f958ed..19a2b8f 100644 --- a/src/Encoding/GzipDecodeStream.php +++ b/src/Encoding/GzipDecodeStream.php @@ -2,6 +2,7 @@ namespace Http\Message\Encoding; +use Clue\StreamFilter as Filter; use Psr\Http\Message\StreamInterface; /** @@ -21,7 +22,10 @@ public function __construct(StreamInterface $stream, $level = -1) throw new \RuntimeException('The zlib extension must be enabled to use this stream'); } - parent::__construct($stream, ['window' => 31], ['window' => 31, 'level' => $level]); + parent::__construct($stream, ['window' => 31]); + + // @deprecated will be removed in 2.0 + $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 31, 'level' => $level]); } /** diff --git a/src/Encoding/GzipEncodeStream.php b/src/Encoding/GzipEncodeStream.php index 1066eec..8555d4a 100644 --- a/src/Encoding/GzipEncodeStream.php +++ b/src/Encoding/GzipEncodeStream.php @@ -2,6 +2,7 @@ namespace Http\Message\Encoding; +use Clue\StreamFilter as Filter; use Psr\Http\Message\StreamInterface; /** @@ -21,7 +22,10 @@ public function __construct(StreamInterface $stream, $level = -1) throw new \RuntimeException('The zlib extension must be enabled to use this stream'); } - parent::__construct($stream, ['window' => 31, 'level' => $level], ['window' => 31]); + parent::__construct($stream, ['window' => 31, 'level' => $level]); + + // @deprecated will be removed in 2.0 + $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 31]); } /** diff --git a/src/Encoding/InflateStream.php b/src/Encoding/InflateStream.php index 7070230..863b73d 100644 --- a/src/Encoding/InflateStream.php +++ b/src/Encoding/InflateStream.php @@ -2,6 +2,7 @@ namespace Http\Message\Encoding; +use Clue\StreamFilter as Filter; use Psr\Http\Message\StreamInterface; /** @@ -21,7 +22,10 @@ public function __construct(StreamInterface $stream, $level = -1) throw new \RuntimeException('The zlib extension must be enabled to use this stream'); } - parent::__construct($stream, ['window' => -15], ['window' => -15, 'level' => $level]); + parent::__construct($stream, ['window' => -15]); + + // @deprecated will be removed in 2.0 + $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => -15, 'level' => $level]); } /** From c9206f0282bf14e0eb1ff24bbbbc8f264b6ab7d3 Mon Sep 17 00:00:00 2001 From: lakie <11071665+llaakkkk@users.noreply.github.com> Date: Mon, 9 Jul 2018 12:24:51 +0200 Subject: [PATCH 043/132] Bug/curl fromater fails (#94) * Added check escapeshellarg with data * Added check escapeshellarg with data * Fixed uses * Fixed code format * Fixed code format * Fixed code format * Added die when escapeshallarg failed * Fixed code format * Fixed silently suppress error * Fixed silently suppress error code readable * Fixed formatting * Fixed foramting --- src/Formatter/CurlCommandFormatter.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 5cdd427..8060250 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -45,7 +45,12 @@ public function formatRequest(RequestInterface $request) } else { $data = '[non-seekable stream omitted]'; } - $command .= sprintf(' --data %s', escapeshellarg($data)); + $escapedData = @escapeshellarg($data); + if (empty($escapedData)) { + $escapedData = 'We couldn\'t not escape the data properly'; + } + + $command .= sprintf(' --data %s', $escapedData); } return $command; From 5e187c0a6072c0b5afb833ecfdf0b0269adfef29 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Mon, 9 Jul 2018 12:28:18 +0200 Subject: [PATCH 044/132] Do not pass arguments using default values to the Filter\fun function (#89) * Do not use the arguments that were not specified intentionally by the user for the read/write filters * Do not rely on the number of arguments passed to the FilteredStream class to initialize the stream filter * Add unit tests --- spec/Encoding/FilteredStreamStubSpec.php | 69 ++++++++++++++++++++++++ src/Encoding/FilteredStream.php | 11 +++- 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 spec/Encoding/FilteredStreamStubSpec.php diff --git a/spec/Encoding/FilteredStreamStubSpec.php b/spec/Encoding/FilteredStreamStubSpec.php new file mode 100644 index 0000000..6e6692e --- /dev/null +++ b/spec/Encoding/FilteredStreamStubSpec.php @@ -0,0 +1,69 @@ +beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); + $this->beConstructedWith($stream, 'foo'); + $this->shouldThrow('RuntimeException')->duringInstantiation(); + } + + function it_throws_during_instantiation_with_invalid_write_filter_options(StreamInterface $stream) + { + $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); + $this->beConstructedWith($stream, null, 'foo'); + $this->shouldThrow('RuntimeException')->duringInstantiation(); + } + + function let(StreamInterface $stream) + { + $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); + $this->beConstructedWith($stream); + } + + function it_reads() + { + // "This is a test stream" | base64_encode + $stream = new MemoryStream('This is a test stream'); + $this->beConstructedWith($stream); + + $this->read(4)->shouldReturn('VGhp'); + } + + function it_gets_content() + { + // "This is a test stream" | base64_encode + $stream = new MemoryStream('This is a test stream'); + $this->beConstructedWith($stream); + + $this->getContents()->shouldReturn('VGhpcyBpcyBhIHRlc3Qgc3RyZWFt'); + } + + function it_does_not_know_the_content_size() + { + $stream = new MemoryStream(gzencode('This is a test stream')); + $this->beConstructedWith($stream); + + $this->getSize()->shouldBeNull(); + } +} + +class FilteredStreamStub extends FilteredStream +{ + protected function readFilter() + { + return 'convert.base64-encode'; + } + + protected function writeFilter() + { + return 'convert.base64-encode'; + } +} diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index 4b296ed..d9b0fa8 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -57,11 +57,18 @@ abstract class FilteredStream implements StreamInterface */ public function __construct(StreamInterface $stream, $readFilterOptions = null, $writeFilterOptions = null) { - $this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions); - $this->writeFilterCallback = Filter\fun($this->writeFilter(), $writeFilterOptions); + if (null !== $readFilterOptions) { + $this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions); + } else { + $this->readFilterCallback = Filter\fun($this->readFilter()); + } if (null !== $writeFilterOptions) { + $this->writeFilterCallback = Filter\fun($this->writeFilter(), $writeFilterOptions); + @trigger_error('The $writeFilterOptions argument is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED); + } else { + $this->writeFilterCallback = Filter\fun($this->writeFilter()); } $this->stream = $stream; From 9a4c75169b1a974c5da5efd08f3b19d8e09a6621 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 14 Aug 2018 18:27:49 +0200 Subject: [PATCH 045/132] Added changelog for 1.7 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb05a23..fb6ee57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,17 @@ ## Unreleased +## 1.7.0 - 2018-08-15 + ### Fixed - Fix CurlCommandFormatter for binary request payloads - Fix QueryParam authentication to assemble proper URL regardless of PHP `arg_separator.output` directive +- Do not pass `null` parameters to `Clue\StreamFilter\fun` + +### Changed +- Dropped tests on HHVM ## 1.6.0 - 2017-07-05 From a296f8bca76071711fe10e5f2a3350bd2295dbba Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 29 Oct 2018 12:56:34 +0100 Subject: [PATCH 046/132] Prepare release --- CHANGELOG.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb6ee57..a62f907 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ ## Unreleased + +## 1.7.1 - 2018-10-29 + +### Fixed + +- FilteredStream is not actually seekable + + ## 1.7.0 - 2018-08-15 ### Fixed @@ -15,6 +23,7 @@ - Dropped tests on HHVM + ## 1.6.0 - 2017-07-05 ### Added @@ -23,7 +32,8 @@ ### Fixed -- Fix curl command of CurlFormatter when there is an user-agent header +- Fix curl command of CurlFormatter when there is an user-agent header + ## 1.5.0 - 2017-02-14 @@ -36,7 +46,7 @@ ### Fixed - FilteredStream::getSize returns null because the contents size is unknown. -- Stream factories does not rewinds streams. The previous behavior was not coherent between factories and inputs. +- Stream factories does not rewinds streams. The previous behavior was not coherent between factories and inputs. ### Deprecated From 044735dba1a0ae1fcbb56ce4f10974319324c173 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 29 Oct 2018 13:06:12 +0100 Subject: [PATCH 047/132] Update changelog --- CHANGELOG.md | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a62f907..6a4fa70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,23 @@ # Change Log +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + + ## Unreleased -## 1.7.1 - 2018-10-29 +## [1.7.1] - 2018-10-29 ### Fixed - FilteredStream is not actually seekable -## 1.7.0 - 2018-08-15 +## [1.7.0] - 2018-08-15 ### Fixed @@ -24,7 +30,7 @@ - Dropped tests on HHVM -## 1.6.0 - 2017-07-05 +## [1.6.0] - 2017-07-05 ### Added @@ -35,7 +41,7 @@ - Fix curl command of CurlFormatter when there is an user-agent header -## 1.5.0 - 2017-02-14 +## [1.5.0] - 2017-02-14 ### Added @@ -54,14 +60,14 @@ - FilteredStream::getWriteFilter We did not implement writing to the streams at all. And if we do, the filter is an internal information and should not be used by consuming code. -## 1.4.1 - 2016-12-16 +## [1.4.1] - 2016-12-16 ### Fixed - Cookie::matchPath Cookie with root path (`/`) will not match sub path (e.g. `/cookie`). -## 1.4.0 - 2016-10-20 +## [1.4.0] - 2016-10-20 ### Added @@ -70,7 +76,7 @@ - cUrlFormatter to be able to redo the request with a cURL command -## 1.3.1 - 2016-07-15 +## [1.3.1] - 2016-07-15 ### Fixed @@ -79,7 +85,7 @@ - FullHttpMessageFormatter rewinds streams after they are read -## 1.3.0 - 2016-07-14 +## [1.3.0] - 2016-07-14 ### Added @@ -90,7 +96,7 @@ - #41: Response builder broke header value -## 1.2.0 - 2016-03-29 +## [1.2.0] - 2016-03-29 ### Added @@ -110,7 +116,7 @@ - Matching authenitcation method, use RequestConditional instead -## 1.1.0 - 2016-02-25 +## [1.1.0] - 2016-02-25 ### Added @@ -123,10 +129,10 @@ - Fix casting string on a FilteredStream not filtering the output -## 1.0.0 - 2016-01-27 +## [1.0.0] - 2016-01-27 -## 0.2.0 - 2015-12-29 +## [0.2.0] - 2015-12-29 ### Added @@ -135,7 +141,7 @@ - [Apigen](http://www.apigen.org/) configuration -## 0.1.2 - 2015-12-26 +## [0.1.2] - 2015-12-26 ### Added @@ -146,7 +152,7 @@ - Chunk filter namespace in Dechunk stream -## 0.1.1 - 2015-12-25 +## [0.1.1] - 2015-12-25 ### Added @@ -161,3 +167,20 @@ - Encoding - Message decorator - Message factory (Guzzle, Diactoros) + + +[Unreleased]: https://github.com/php-http/message/compare/v1.7.1...HEAD +[1.7.1]: https://github.com/php-http/message/compare/1.7.0...v1.7.1 +[1.7.0]: https://github.com/php-http/message/compare/1.6.0...1.7.0 +[1.6.0]: https://github.com/php-http/message/compare/1.5.0...1.6.0 +[1.5.0]: https://github.com/php-http/message/compare/v1.4.1...1.5.0 +[1.4.1]: https://github.com/php-http/message/compare/v1.4.0...v1.4.1 +[1.4.0]: https://github.com/php-http/message/compare/v1.3.1...v1.4.0 +[1.3.1]: https://github.com/php-http/message/compare/v1.3.0...v1.3.1 +[1.3.0]: https://github.com/php-http/message/compare/v1.2.0...v1.3.0 +[1.2.0]: https://github.com/php-http/message/compare/v1.1.0...v1.2.0 +[1.1.0]: https://github.com/php-http/message/compare/v1.0.0...v1.1.0 +[1.0.0]: https://github.com/php-http/message/compare/0.2.0...v1.0.0 +[0.2.0]: https://github.com/php-http/message/compare/v0.1.2...0.2.0 +[0.1.2]: https://github.com/php-http/message/compare/v0.1.1...v0.1.2 +[0.1.1]: https://github.com/php-http/message/compare/v0.1.0...v0.1.1 From 8c225d2a54d7525523cab34c8ae3d75a151fab4a Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 30 Oct 2018 08:36:52 +0100 Subject: [PATCH 048/132] trigger_error instead of exceptions --- CHANGELOG.md | 8 ++++++++ src/Encoding/FilteredStream.php | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a4fa70..48319fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +## [1.7.2] - 2018-10-30 + +### Fixed + +- FilteredStream uses `@trigger_error` instead of throwing exceptions to not + break careless users. You still need to fix your stream code to respect + `isSeekable`. Seeking does not work as expected, and we will add exceptions + in version 2. ## [1.7.1] - 2018-10-29 diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index 26c40ff..7e5713e 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -15,7 +15,10 @@ abstract class FilteredStream implements StreamInterface { const BUFFER_SIZE = 8192; - use StreamDecorator; + use StreamDecorator { + rewind as private doRewind; + seek as private doSeek; + } /** * @var callable @@ -146,11 +149,11 @@ public function getContents() } /** - * {@inheritdoc} + * Always returns null because we can't tell the size of a stream when we filter. */ public function getSize() { - return; + return null; } /** @@ -162,7 +165,9 @@ public function __toString() } /** - * {@inheritdoc} + * Filtered streams are not seekable. + * + * We would need to buffer and process everything to allow seeking. */ public function isSeekable() { @@ -174,7 +179,8 @@ public function isSeekable() */ public function rewind() { - throw new \RuntimeException('Cannot rewind a filtered stream'); + @trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version', E_USER_DEPRECATED); + $this->doRewind(); } /** @@ -182,7 +188,8 @@ public function rewind() */ public function seek($offset, $whence = SEEK_SET) { - throw new \RuntimeException('Cannot seek a filtered stream'); + @trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version', E_USER_DEPRECATED); + $this->doSeek($offset, $whence); } /** From 817d4d121a600ce9fb8f0fdf774cde08fc445192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Thu, 1 Nov 2018 11:17:32 +0100 Subject: [PATCH 049/132] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48319fd..1f29d07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -177,7 +177,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Message factory (Guzzle, Diactoros) -[Unreleased]: https://github.com/php-http/message/compare/v1.7.1...HEAD +[Unreleased]: https://github.com/php-http/message/compare/1.7.2...HEAD +[1.7.2]: https://github.com/php-http/message/compare/v1.7.1...1.7.2 [1.7.1]: https://github.com/php-http/message/compare/1.7.0...v1.7.1 [1.7.0]: https://github.com/php-http/message/compare/1.6.0...1.7.0 [1.6.0]: https://github.com/php-http/message/compare/1.5.0...1.6.0 From 447b625ca58e3276e27bc5b24d4f2964ce97f511 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 26 Dec 2018 10:06:41 +0100 Subject: [PATCH 050/132] Test on php 7.3 --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 21b2f27..5aacf2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ php: - 5.6 - 7.0 - 7.1 + - 7.2 + - 7.3 env: global: @@ -30,10 +32,9 @@ matrix: before_install: - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi - if [[ "${TRAVIS_PHP_VERSION}" == "5.4" ]]; then composer remove slim/slim --dev --no-update; fi - - travis_retry composer self-update install: - - travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction + - composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction script: - $TEST_COMMAND From dce46525fe6be41e2ec69418d76971c57e27d54e Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 26 Dec 2018 10:07:45 +0100 Subject: [PATCH 051/132] minor --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5aacf2a..7d8468c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,6 @@ env: global: - TEST_COMMAND="composer test" -branches: - except: - - /^analysis-.*$/ - matrix: fast_finish: true include: From 958414dd49a393e2c103c4e537e91d313c34e472 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 8 Jan 2019 08:57:22 +0100 Subject: [PATCH 052/132] more verbose documentation on authentication --- src/Authentication.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Authentication.php b/src/Authentication.php index b50366f..0fe0cb3 100644 --- a/src/Authentication.php +++ b/src/Authentication.php @@ -5,18 +5,21 @@ use Psr\Http\Message\RequestInterface; /** - * Authenticate a PSR-7 Request. + * Add authentication information to a PSR-7 Request. * * @author Márk Sági-Kazár */ interface Authentication { /** - * Authenticates a request. + * Alter the request to add the authentication credentials. * - * @param RequestInterface $request + * To do that, the implementation might use pre-stored credentials or do + * separate HTTP requests to obtain a valid token. * - * @return RequestInterface + * @param RequestInterface $request The request without authentication information + * + * @return RequestInterface The request with added authentication information */ public function authenticate(RequestInterface $request); } From 6bb4fe9cba5e83ed7b957bc5f5ff7ea11d0e15be Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Sun, 17 Feb 2019 21:44:19 +0100 Subject: [PATCH 053/132] Always read size of chunksize if in MemoryStream --- spec/Encoding/MemoryStream.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/Encoding/MemoryStream.php b/spec/Encoding/MemoryStream.php index 4403536..afedd2b 100644 --- a/spec/Encoding/MemoryStream.php +++ b/spec/Encoding/MemoryStream.php @@ -10,7 +10,9 @@ class MemoryStream implements StreamInterface private $size = 0; - public function __construct($body = "", $chunkSize = null) + private $chunkSize; + + public function __construct($body = "", $chunkSize = 8192) { $this->size = strlen($body); $this->resource = fopen('php://memory', 'rw+'); @@ -22,6 +24,8 @@ public function __construct($body = "", $chunkSize = null) fwrite($this->resource, $body); fseek($this->resource, 0); + + $this->chunkSize = $chunkSize; } public function __toString() @@ -89,7 +93,7 @@ public function isReadable() public function read($length) { - return fread($this->resource, $length); + return fread($this->resource, min($this->chunkSize, $length)); } public function getContents() From 06dd957c83d034acdc04da8a9fe7f06248607880 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 6 Mar 2019 07:56:19 +0100 Subject: [PATCH 054/132] cleanup code with early return --- src/Formatter/FullHttpMessageFormatter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index 1918c59..c163a2d 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -80,12 +80,12 @@ private function addBody(MessageInterface $request, $message) $stream = $request->getBody(); if (!$stream->isSeekable() || 0 === $this->maxBodyLength) { // Do not read the stream - $message .= "\n"; - } else { - $message .= "\n".mb_substr($stream->__toString(), 0, $this->maxBodyLength); - $stream->rewind(); + return $message."\n"; } + $message .= "\n".mb_substr($stream->__toString(), 0, $this->maxBodyLength); + $stream->rewind(); + return $message; } } From 34f67eebf9bd202fdf176ee239de83e0a42ab362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Fri, 8 Mar 2019 07:20:02 +0100 Subject: [PATCH 055/132] Handle null explicitly for max body length of FullHttpMessageFormatter --- .../FullHttpMessageFormatterSpec.php | 230 ++++++++++++++++++ src/Formatter/FullHttpMessageFormatter.php | 11 +- 2 files changed, 238 insertions(+), 3 deletions(-) create mode 100644 spec/Formatter/FullHttpMessageFormatterSpec.php diff --git a/spec/Formatter/FullHttpMessageFormatterSpec.php b/spec/Formatter/FullHttpMessageFormatterSpec.php new file mode 100644 index 0000000..a1c4588 --- /dev/null +++ b/spec/Formatter/FullHttpMessageFormatterSpec.php @@ -0,0 +1,230 @@ +beConstructedWith($maxBodyLength); + } + + function it_is_initializable() + { + $this->shouldHaveType('Http\Message\Formatter\FullHttpMessageFormatter'); + } + + function it_is_a_formatter() + { + $this->shouldImplement('Http\Message\Formatter'); + } + + function it_formats_the_request_with_size_limit(RequestInterface $request, StreamInterface $stream) + { + $this->beConstructedWith(18); + + $stream->isSeekable()->willReturn(true); + $stream->rewind()->shouldBeCalled(); + $stream->__toString()->willReturn('This is an HTML stream request content.'); + $request->getBody()->willReturn($stream); + $request->getMethod()->willReturn('GET'); + $request->getRequestTarget()->willReturn('/foo'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([ + 'X-Param-Foo' => ['foo'], + 'X-Param-Bar' => ['bar'], + ]); + + $expectedMessage = <<formatRequest($request)->shouldReturn($expectedMessage); + } + + function it_formats_the_request_without_size_limit(RequestInterface $request, StreamInterface $stream) + { + $this->beConstructedWith(null); + + $stream->isSeekable()->willReturn(true); + $stream->rewind()->shouldBeCalled(); + $stream->__toString()->willReturn('This is an HTML stream request content.'); + $request->getBody()->willReturn($stream); + $request->getMethod()->willReturn('GET'); + $request->getRequestTarget()->willReturn('/foo'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([ + 'X-Param-Foo' => ['foo'], + 'X-Param-Bar' => ['bar'], + ]); + + $expectedMessage = <<formatRequest($request)->shouldReturn($expectedMessage); + } + + function it_does_not_format_the_request(RequestInterface $request, StreamInterface $stream) + { + $this->beConstructedWith(0); + + $stream->isSeekable()->willReturn(true); + $stream->__toString()->willReturn('This is an HTML stream request content.'); + $request->getBody()->willReturn($stream); + $request->getMethod()->willReturn('GET'); + $request->getRequestTarget()->willReturn('/foo'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([ + 'X-Param-Foo' => ['foo'], + 'X-Param-Bar' => ['bar'], + ]); + + $expectedMessage = <<formatRequest($request)->shouldReturn($expectedMessage); + } + + function it_does_not_format_no_seekable_request(RequestInterface $request, StreamInterface $stream) + { + $this->beConstructedWith(1000); + + $stream->isSeekable()->willReturn(false); + $stream->__toString()->willReturn('This is an HTML stream request content.'); + $request->getBody()->willReturn($stream); + $request->getMethod()->willReturn('GET'); + $request->getRequestTarget()->willReturn('/foo'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([ + 'X-Param-Foo' => ['foo'], + 'X-Param-Bar' => ['bar'], + ]); + + $expectedMessage = <<formatRequest($request)->shouldReturn($expectedMessage); + } + + function it_formats_the_response_with_size_limit(ResponseInterface $response, StreamInterface $stream) + { + $this->beConstructedWith(18); + + $stream->isSeekable()->willReturn(true); + $stream->rewind()->shouldBeCalled(); + $stream->__toString()->willReturn('This is an HTML stream response content.'); + $response->getBody()->willReturn($stream); + $response->getProtocolVersion()->willReturn('1.1'); + $response->getStatusCode()->willReturn(200); + $response->getReasonPhrase()->willReturn('OK'); + $response->getHeaders()->willReturn([ + 'X-Param-Foo' => ['foo'], + 'X-Param-Bar' => ['bar'], + ]); + + $expectedMessage = <<formatResponse($response)->shouldReturn($expectedMessage); + } + + function it_formats_the_response_without_size_limit(ResponseInterface $response, StreamInterface $stream) + { + $this->beConstructedWith(null); + + $stream->isSeekable()->willReturn(true); + $stream->rewind()->shouldBeCalled(); + $stream->__toString()->willReturn('This is an HTML stream response content.'); + $response->getBody()->willReturn($stream); + $response->getProtocolVersion()->willReturn('1.1'); + $response->getStatusCode()->willReturn(200); + $response->getReasonPhrase()->willReturn('OK'); + $response->getHeaders()->willReturn([ + 'X-Param-Foo' => ['foo'], + 'X-Param-Bar' => ['bar'], + ]); + + $expectedMessage = <<formatResponse($response)->shouldReturn($expectedMessage); + } + + function it_does_not_format_the_response(ResponseInterface $response, StreamInterface $stream) + { + $this->beConstructedWith(0); + + $stream->isSeekable()->willReturn(true); + $stream->__toString()->willReturn('This is an HTML stream response content.'); + $response->getBody()->willReturn($stream); + $response->getProtocolVersion()->willReturn('1.1'); + $response->getStatusCode()->willReturn(200); + $response->getReasonPhrase()->willReturn('OK'); + $response->getHeaders()->willReturn([ + 'X-Param-Foo' => ['foo'], + 'X-Param-Bar' => ['bar'], + ]); + + $expectedMessage = <<formatResponse($response)->shouldReturn($expectedMessage); + } + + function it_does_not_format_no_seekable_response(ResponseInterface $response, StreamInterface $stream) + { + $this->beConstructedWith(1000); + + $stream->isSeekable()->willReturn(false); + $stream->__toString()->willReturn('This is an HTML stream response content.'); + $response->getBody()->willReturn($stream); + $response->getProtocolVersion()->willReturn('1.1'); + $response->getStatusCode()->willReturn(200); + $response->getReasonPhrase()->willReturn('OK'); + $response->getHeaders()->willReturn([ + 'X-Param-Foo' => ['foo'], + 'X-Param-Bar' => ['bar'], + ]); + + $expectedMessage = <<formatResponse($response)->shouldReturn($expectedMessage); + } +} diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index c163a2d..d065f0e 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -17,12 +17,12 @@ class FullHttpMessageFormatter implements Formatter /** * The maximum length of the body. * - * @var int + * @var int|null */ private $maxBodyLength; /** - * @param int $maxBodyLength + * @param int|null $maxBodyLength */ public function __construct($maxBodyLength = 1000) { @@ -83,7 +83,12 @@ private function addBody(MessageInterface $request, $message) return $message."\n"; } - $message .= "\n".mb_substr($stream->__toString(), 0, $this->maxBodyLength); + if (null === $this->maxBodyLength) { + $message .= "\n".$stream->__toString(); + } else { + $message .= "\n".mb_substr($stream->__toString(), 0, $this->maxBodyLength); + } + $stream->rewind(); return $message; From 02f5f34b50dbfebaa09f5e68fa1ad8f609eeb202 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 5 Jun 2019 10:24:33 +0200 Subject: [PATCH 056/132] short array notation in spec --- spec/MessageFactory/MessageFactoryBehavior.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/MessageFactory/MessageFactoryBehavior.php b/spec/MessageFactory/MessageFactoryBehavior.php index 29a7eab..1c7a50d 100644 --- a/spec/MessageFactory/MessageFactoryBehavior.php +++ b/spec/MessageFactory/MessageFactoryBehavior.php @@ -11,7 +11,7 @@ function it_is_a_message_factory() function it_creates_a_request() { - $request = $this->createRequest('GET', '/', array('X-hello' => 'world'), 'lorem'); + $request = $this->createRequest('GET', '/', ['X-hello' => 'world'], 'lorem'); $request->shouldHaveType('Psr\Http\Message\RequestInterface'); $request->getMethod()->shouldReturn('GET'); From ea0e1c86ac8c917c12583340ecef81cc801f12fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Thu, 1 Aug 2019 18:00:44 +0200 Subject: [PATCH 057/132] Enhancement: Keep packages sorted in composer.json --- composer.json | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 3a9b3ed..2b5b45e 100644 --- a/composer.json +++ b/composer.json @@ -12,22 +12,22 @@ ], "require": { "php": "^5.4 || ^7.0", - "psr/http-message": "^1.0", + "clue/stream-filter": "^1.4", "php-http/message-factory": "^1.0.2", - "clue/stream-filter": "^1.4" + "psr/http-message": "^1.0" }, "provide": { "php-http/message-factory-implementation": "1.0" }, "require-dev": { - "zendframework/zend-diactoros": "^1.0", - "guzzlehttp/psr7": "^1.0", "ext-zlib": "*", - "phpspec/phpspec": "^2.4", - "henrikbjorn/phpspec-code-coverage" : "^1.0", - "coduo/phpspec-data-provider-extension": "^1.0", "akeneo/phpspec-skip-example-extension": "^1.0", - "slim/slim": "^3.0" + "coduo/phpspec-data-provider-extension": "^1.0", + "guzzlehttp/psr7": "^1.0", + "henrikbjorn/phpspec-code-coverage" : "^1.0", + "phpspec/phpspec": "^2.4", + "slim/slim": "^3.0", + "zendframework/zend-diactoros": "^1.0" }, "suggest": { "zendframework/zend-diactoros": "Used with Diactoros Factories", @@ -56,5 +56,8 @@ "branch-alias": { "dev-master": "1.6-dev" } + }, + "config": { + "sort-packages": true } } From ea75704360aec4d6327cd52362b9519c32f6a6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 2 Aug 2019 09:47:13 +0200 Subject: [PATCH 058/132] Fix: Drop support for unsupported PHP versions --- .travis.yml | 7 +------ composer.json | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7d8468c..7a303b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,6 @@ cache: - $HOME/.composer/cache/files php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - 7.1 - 7.2 - 7.3 @@ -22,12 +18,11 @@ env: matrix: fast_finish: true include: - - php: 5.4 + - php: 7.1 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" before_install: - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi - - if [[ "${TRAVIS_PHP_VERSION}" == "5.4" ]]; then composer remove slim/slim --dev --no-update; fi install: - composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction diff --git a/composer.json b/composer.json index 2b5b45e..a2541c3 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^5.4 || ^7.0", + "php": "^7.1", "clue/stream-filter": "^1.4", "php-http/message-factory": "^1.0.2", "psr/http-message": "^1.0" From 8002faeb5b8a15368fae837fc5bf2e0485d6a2a6 Mon Sep 17 00:00:00 2001 From: Gary PEGEOT Date: Sun, 4 Aug 2019 11:29:00 +0200 Subject: [PATCH 059/132] Fix fatal error for long bodies (#116) * Fix fatal error for long bodies * Set body size limit to 8192 * Phrasing --- CHANGELOG.md | 4 ++++ spec/Formatter/CurlCommandFormatterSpec.php | 18 ++++++++++++++++++ src/Formatter/CurlCommandFormatter.php | 5 ++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f29d07..fde1022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Fixed + +- Fixed Fatal error on `CurlCommandFormatter` when body is larger than `escapeshellarg` allowed length. + ## [1.7.2] - 2018-10-30 ### Fixed diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php index 5340b62..f68d7e2 100644 --- a/spec/Formatter/CurlCommandFormatterSpec.php +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -108,4 +108,22 @@ function it_formats_requests_with_nonseekable_body(RequestInterface $request, Ur $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[non-seekable stream omitted]'"); } + + function it_formats_requests_with_long_body(RequestInterface $request, UriInterface $uri, StreamInterface $body) + { + $request->getUri()->willReturn($uri); + $request->getBody()->willReturn($body); + + $body->__toString()->willReturn('a very long body'); + $body->getSize()->willReturn(2097153); + $body->isSeekable()->willReturn(true); + $body->rewind()->willReturn(true); + + $uri->withFragment('')->willReturn('http://foo.com/bar'); + $request->getMethod()->willReturn('POST'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([]); + + $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[too long stream omitted]'"); + } } diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 8060250..2ddb149 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -36,7 +36,10 @@ public function formatRequest(RequestInterface $request) $body = $request->getBody(); if ($body->getSize() > 0) { - if ($body->isSeekable()) { + // escapeshellarg argument max length on Windows, but longer body in curl command would be impractical anyways + if ($body->getSize() > 8192) { + $data = '[too long stream omitted]'; + } elseif ($body->isSeekable()) { $data = $body->__toString(); $body->rewind(); if (preg_match('/[\x00-\x1F\x7F]/', $data)) { From ce8f43ac1e294b54aabf5808515c3554a19c1e1c Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 5 Aug 2019 08:55:08 +0200 Subject: [PATCH 060/132] prepare release --- CHANGELOG.md | 9 ++++++++- composer.json | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fde1022..93427cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +## [1.8.0] - 2019-08-05 + +### Changed + +- Raised minimum PHP version to 7.1 + ### Fixed -- Fixed Fatal error on `CurlCommandFormatter` when body is larger than `escapeshellarg` allowed length. +- Fatal error on `CurlCommandFormatter` when body is larger than `escapeshellarg` allowed length. +- Do not read stream in message formatter if stream is not seekable. ## [1.7.2] - 2018-10-30 diff --git a/composer.json b/composer.json index a2541c3..00361f4 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "config": { From 5bf2807d0fb5cdd0bc12388760d5ff917bed5fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 18 Aug 2019 22:49:01 +0200 Subject: [PATCH 061/132] Enhancement: Require localheinz/composer-normalize as development dependency --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 00361f4..95f6c87 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "akeneo/phpspec-skip-example-extension": "^1.0", "coduo/phpspec-data-provider-extension": "^1.0", "guzzlehttp/psr7": "^1.0", - "henrikbjorn/phpspec-code-coverage" : "^1.0", + "henrikbjorn/phpspec-code-coverage": "^1.0", + "localheinz/composer-normalize": "^1.2.0", "phpspec/phpspec": "^2.4", "slim/slim": "^3.0", "zendframework/zend-diactoros": "^1.0" From 9b4a50b506dcbf7aeeac97acdcbd20d6e69f31ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 3 Aug 2019 19:58:09 +0200 Subject: [PATCH 062/132] Enhancement: Run composer validate and composer normalize --dry run on Travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7a303b8..5586e11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,8 @@ install: - composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction script: + - composer validate + - composer normalize --dry-run - $TEST_COMMAND after_success: From 5a9a99e17871f447f5c65b6a0df680b1edcdf338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 18 Aug 2019 22:49:44 +0200 Subject: [PATCH 063/132] Fix: Run 'composer normalize' --- composer.json | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 95f6c87..3e94bae 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,13 @@ { "name": "php-http/message", "description": "HTTP Message related tools", - "license": "MIT", - "keywords": ["message", "http", "psr-7"], + "keywords": [ + "message", + "http", + "psr-7" + ], "homepage": "http://php-http.org", + "license": "MIT", "authors": [ { "name": "Márk Sági-Kazár", @@ -31,10 +35,18 @@ "zendframework/zend-diactoros": "^1.0" }, "suggest": { - "zendframework/zend-diactoros": "Used with Diactoros Factories", + "ext-zlib": "Used with compressor/decompressor streams", "guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories", "slim/slim": "Used with Slim Framework PSR-7 implementation", - "ext-zlib": "Used with compressor/decompressor streams" + "zendframework/zend-diactoros": "Used with Diactoros Factories" + }, + "config": { + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "1.8-dev" + } }, "autoload": { "psr-4": { @@ -52,13 +64,5 @@ "scripts": { "test": "vendor/bin/phpspec run", "test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml" - }, - "extra": { - "branch-alias": { - "dev-master": "1.8-dev" - } - }, - "config": { - "sort-packages": true } } From 144d13ba024d0c597830636907144bc7c23f50dd Mon Sep 17 00:00:00 2001 From: Fabien Bourigault Date: Mon, 16 Sep 2019 18:06:47 +0200 Subject: [PATCH 064/132] add Header authentication method (#118) --- CHANGELOG.md | 4 ++++ spec/Authentication/HeaderSpec.php | 31 ++++++++++++++++++++++++++++ src/Authentication/Header.php | 33 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 spec/Authentication/HeaderSpec.php create mode 100644 src/Authentication/Header.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 93427cb..6a29df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Added + +- New Header authentication method for arbitrary header authentication. + ## [1.8.0] - 2019-08-05 ### Changed diff --git a/spec/Authentication/HeaderSpec.php b/spec/Authentication/HeaderSpec.php new file mode 100644 index 0000000..b6ee348 --- /dev/null +++ b/spec/Authentication/HeaderSpec.php @@ -0,0 +1,31 @@ +beConstructedWith('X-AUTH-TOKEN', 'REAL'); + } + + function it_is_initializable() + { + $this->shouldHaveType('Http\Message\Authentication\Header'); + } + + function it_is_an_authentication() + { + $this->shouldImplement('Http\Message\Authentication'); + } + + function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) + { + $request->withHeader('X-AUTH-TOKEN', 'REAL')->willReturn($newRequest); + + $this->authenticate($request)->shouldReturn($newRequest); + } +} diff --git a/src/Authentication/Header.php b/src/Authentication/Header.php new file mode 100644 index 0000000..97a04dd --- /dev/null +++ b/src/Authentication/Header.php @@ -0,0 +1,33 @@ +name = $name; + $this->value = $value; + } + + /** + * {@inheritdoc} + */ + public function authenticate(RequestInterface $request) + { + return $request->withHeader($this->name, $this->value); + } +} From e133330c144335ce1887f32a7985608777d91b8a Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 26 Dec 2018 09:57:53 +0100 Subject: [PATCH 065/132] Added deprecation notification on our factories --- src/MessageFactory/DiactorosMessageFactory.php | 1 + src/MessageFactory/GuzzleMessageFactory.php | 1 + src/MessageFactory/SlimMessageFactory.php | 1 + src/StreamFactory/DiactorosStreamFactory.php | 1 + src/StreamFactory/GuzzleStreamFactory.php | 1 + src/StreamFactory/SlimStreamFactory.php | 1 + src/UriFactory/DiactorosUriFactory.php | 1 + src/UriFactory/GuzzleUriFactory.php | 1 + src/UriFactory/SlimUriFactory.php | 1 + 9 files changed, 9 insertions(+) diff --git a/src/MessageFactory/DiactorosMessageFactory.php b/src/MessageFactory/DiactorosMessageFactory.php index 53f08ae..7f4c1ae 100644 --- a/src/MessageFactory/DiactorosMessageFactory.php +++ b/src/MessageFactory/DiactorosMessageFactory.php @@ -11,6 +11,7 @@ * Creates Diactoros messages. * * @author GeLo + * @deprecated This will be removed in 2.0. Consider using the official Diactoros PSR-17 factory */ final class DiactorosMessageFactory implements MessageFactory { diff --git a/src/MessageFactory/GuzzleMessageFactory.php b/src/MessageFactory/GuzzleMessageFactory.php index 59eb655..236e30d 100644 --- a/src/MessageFactory/GuzzleMessageFactory.php +++ b/src/MessageFactory/GuzzleMessageFactory.php @@ -10,6 +10,7 @@ * Creates Guzzle messages. * * @author Márk Sági-Kazár + * @deprecated This will be removed in 2.0. Consider using the official Guzzle PSR-17 factory */ final class GuzzleMessageFactory implements MessageFactory { diff --git a/src/MessageFactory/SlimMessageFactory.php b/src/MessageFactory/SlimMessageFactory.php index cdad2ec..e21748e 100644 --- a/src/MessageFactory/SlimMessageFactory.php +++ b/src/MessageFactory/SlimMessageFactory.php @@ -13,6 +13,7 @@ * Creates Slim 3 messages. * * @author Mika Tuupola + * @deprecated This will be removed in 2.0. Consider using the official Slim PSR-17 factory */ final class SlimMessageFactory implements MessageFactory { diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index a75ec98..608c8ae 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -10,6 +10,7 @@ * Creates Diactoros streams. * * @author Михаил Красильников + * @deprecated This will be removed in 2.0. Consider using the official Diactoros PSR-17 factory */ final class DiactorosStreamFactory implements StreamFactory { diff --git a/src/StreamFactory/GuzzleStreamFactory.php b/src/StreamFactory/GuzzleStreamFactory.php index 10f4d3f..f2a39dc 100644 --- a/src/StreamFactory/GuzzleStreamFactory.php +++ b/src/StreamFactory/GuzzleStreamFactory.php @@ -8,6 +8,7 @@ * Creates Guzzle streams. * * @author Михаил Красильников + * @deprecated This will be removed in 2.0. Consider using the official Guzzle PSR-17 factory */ final class GuzzleStreamFactory implements StreamFactory { diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index efcadc4..1e75fb5 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -10,6 +10,7 @@ * Creates Slim 3 streams. * * @author Mika Tuupola + * @deprecated This will be removed in 2.0. Consider using the official Slim PSR-17 factory */ final class SlimStreamFactory implements StreamFactory { diff --git a/src/UriFactory/DiactorosUriFactory.php b/src/UriFactory/DiactorosUriFactory.php index 268c361..18c5645 100644 --- a/src/UriFactory/DiactorosUriFactory.php +++ b/src/UriFactory/DiactorosUriFactory.php @@ -10,6 +10,7 @@ * Creates Diactoros URI. * * @author David de Boer + * @deprecated This will be removed in 2.0. Consider using the official Diactoros PSR-17 factory */ final class DiactorosUriFactory implements UriFactory { diff --git a/src/UriFactory/GuzzleUriFactory.php b/src/UriFactory/GuzzleUriFactory.php index 4c1c286..42c8cd2 100644 --- a/src/UriFactory/GuzzleUriFactory.php +++ b/src/UriFactory/GuzzleUriFactory.php @@ -9,6 +9,7 @@ * Creates Guzzle URI. * * @author David de Boer + * @deprecated This will be removed in 2.0. Consider using the official Guzzle PSR-17 factory */ final class GuzzleUriFactory implements UriFactory { diff --git a/src/UriFactory/SlimUriFactory.php b/src/UriFactory/SlimUriFactory.php index c013d54..2c00586 100644 --- a/src/UriFactory/SlimUriFactory.php +++ b/src/UriFactory/SlimUriFactory.php @@ -10,6 +10,7 @@ * Creates Slim 3 URI. * * @author Mika Tuupola + * @deprecated This will be removed in 2.0. Consider using the official Slim PSR-17 factory */ final class SlimUriFactory implements UriFactory { From 15c469b03b67b98d3d17bb04811ac2e8e75c0738 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 27 Dec 2018 15:44:54 +0100 Subject: [PATCH 066/132] cs --- src/MessageFactory/DiactorosMessageFactory.php | 1 + src/MessageFactory/GuzzleMessageFactory.php | 1 + src/MessageFactory/SlimMessageFactory.php | 1 + src/StreamFactory/DiactorosStreamFactory.php | 1 + src/StreamFactory/GuzzleStreamFactory.php | 1 + src/StreamFactory/SlimStreamFactory.php | 1 + src/UriFactory/DiactorosUriFactory.php | 1 + src/UriFactory/GuzzleUriFactory.php | 1 + src/UriFactory/SlimUriFactory.php | 1 + 9 files changed, 9 insertions(+) diff --git a/src/MessageFactory/DiactorosMessageFactory.php b/src/MessageFactory/DiactorosMessageFactory.php index 7f4c1ae..ce5af36 100644 --- a/src/MessageFactory/DiactorosMessageFactory.php +++ b/src/MessageFactory/DiactorosMessageFactory.php @@ -11,6 +11,7 @@ * Creates Diactoros messages. * * @author GeLo + * * @deprecated This will be removed in 2.0. Consider using the official Diactoros PSR-17 factory */ final class DiactorosMessageFactory implements MessageFactory diff --git a/src/MessageFactory/GuzzleMessageFactory.php b/src/MessageFactory/GuzzleMessageFactory.php index 236e30d..b61823d 100644 --- a/src/MessageFactory/GuzzleMessageFactory.php +++ b/src/MessageFactory/GuzzleMessageFactory.php @@ -10,6 +10,7 @@ * Creates Guzzle messages. * * @author Márk Sági-Kazár + * * @deprecated This will be removed in 2.0. Consider using the official Guzzle PSR-17 factory */ final class GuzzleMessageFactory implements MessageFactory diff --git a/src/MessageFactory/SlimMessageFactory.php b/src/MessageFactory/SlimMessageFactory.php index e21748e..f5cfe71 100644 --- a/src/MessageFactory/SlimMessageFactory.php +++ b/src/MessageFactory/SlimMessageFactory.php @@ -13,6 +13,7 @@ * Creates Slim 3 messages. * * @author Mika Tuupola + * * @deprecated This will be removed in 2.0. Consider using the official Slim PSR-17 factory */ final class SlimMessageFactory implements MessageFactory diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index 608c8ae..5e97ca9 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -10,6 +10,7 @@ * Creates Diactoros streams. * * @author Михаил Красильников + * * @deprecated This will be removed in 2.0. Consider using the official Diactoros PSR-17 factory */ final class DiactorosStreamFactory implements StreamFactory diff --git a/src/StreamFactory/GuzzleStreamFactory.php b/src/StreamFactory/GuzzleStreamFactory.php index f2a39dc..ef44e25 100644 --- a/src/StreamFactory/GuzzleStreamFactory.php +++ b/src/StreamFactory/GuzzleStreamFactory.php @@ -8,6 +8,7 @@ * Creates Guzzle streams. * * @author Михаил Красильников + * * @deprecated This will be removed in 2.0. Consider using the official Guzzle PSR-17 factory */ final class GuzzleStreamFactory implements StreamFactory diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index 1e75fb5..dda4633 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -10,6 +10,7 @@ * Creates Slim 3 streams. * * @author Mika Tuupola + * * @deprecated This will be removed in 2.0. Consider using the official Slim PSR-17 factory */ final class SlimStreamFactory implements StreamFactory diff --git a/src/UriFactory/DiactorosUriFactory.php b/src/UriFactory/DiactorosUriFactory.php index 18c5645..9a06de3 100644 --- a/src/UriFactory/DiactorosUriFactory.php +++ b/src/UriFactory/DiactorosUriFactory.php @@ -10,6 +10,7 @@ * Creates Diactoros URI. * * @author David de Boer + * * @deprecated This will be removed in 2.0. Consider using the official Diactoros PSR-17 factory */ final class DiactorosUriFactory implements UriFactory diff --git a/src/UriFactory/GuzzleUriFactory.php b/src/UriFactory/GuzzleUriFactory.php index 42c8cd2..b5db1cd 100644 --- a/src/UriFactory/GuzzleUriFactory.php +++ b/src/UriFactory/GuzzleUriFactory.php @@ -9,6 +9,7 @@ * Creates Guzzle URI. * * @author David de Boer + * * @deprecated This will be removed in 2.0. Consider using the official Guzzle PSR-17 factory */ final class GuzzleUriFactory implements UriFactory diff --git a/src/UriFactory/SlimUriFactory.php b/src/UriFactory/SlimUriFactory.php index 2c00586..b288f6d 100644 --- a/src/UriFactory/SlimUriFactory.php +++ b/src/UriFactory/SlimUriFactory.php @@ -10,6 +10,7 @@ * Creates Slim 3 URI. * * @author Mika Tuupola + * * @deprecated This will be removed in 2.0. Consider using the official Slim PSR-17 factory */ final class SlimUriFactory implements UriFactory From af747abec085b285e4975f3859547b3fec4ff9cc Mon Sep 17 00:00:00 2001 From: Nyholm Date: Mon, 16 Dec 2019 22:17:31 +0100 Subject: [PATCH 067/132] updated message --- src/MessageFactory/DiactorosMessageFactory.php | 2 +- src/MessageFactory/GuzzleMessageFactory.php | 2 +- src/MessageFactory/SlimMessageFactory.php | 2 +- src/StreamFactory/DiactorosStreamFactory.php | 2 +- src/StreamFactory/GuzzleStreamFactory.php | 2 +- src/StreamFactory/SlimStreamFactory.php | 2 +- src/UriFactory/DiactorosUriFactory.php | 2 +- src/UriFactory/GuzzleUriFactory.php | 2 +- src/UriFactory/SlimUriFactory.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/MessageFactory/DiactorosMessageFactory.php b/src/MessageFactory/DiactorosMessageFactory.php index ce5af36..10a49f2 100644 --- a/src/MessageFactory/DiactorosMessageFactory.php +++ b/src/MessageFactory/DiactorosMessageFactory.php @@ -12,7 +12,7 @@ * * @author GeLo * - * @deprecated This will be removed in 2.0. Consider using the official Diactoros PSR-17 factory + * @deprecated This will be removed in php-http/message2.0. Consider using the official Diactoros PSR-17 factory */ final class DiactorosMessageFactory implements MessageFactory { diff --git a/src/MessageFactory/GuzzleMessageFactory.php b/src/MessageFactory/GuzzleMessageFactory.php index b61823d..02989d9 100644 --- a/src/MessageFactory/GuzzleMessageFactory.php +++ b/src/MessageFactory/GuzzleMessageFactory.php @@ -11,7 +11,7 @@ * * @author Márk Sági-Kazár * - * @deprecated This will be removed in 2.0. Consider using the official Guzzle PSR-17 factory + * @deprecated This will be removed in php-http/message2.0. Consider using the official Guzzle PSR-17 factory */ final class GuzzleMessageFactory implements MessageFactory { diff --git a/src/MessageFactory/SlimMessageFactory.php b/src/MessageFactory/SlimMessageFactory.php index f5cfe71..869cf77 100644 --- a/src/MessageFactory/SlimMessageFactory.php +++ b/src/MessageFactory/SlimMessageFactory.php @@ -14,7 +14,7 @@ * * @author Mika Tuupola * - * @deprecated This will be removed in 2.0. Consider using the official Slim PSR-17 factory + * @deprecated This will be removed in php-http/message2.0. Consider using the official Slim PSR-17 factory */ final class SlimMessageFactory implements MessageFactory { diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index 5e97ca9..95bf0ca 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -11,7 +11,7 @@ * * @author Михаил Красильников * - * @deprecated This will be removed in 2.0. Consider using the official Diactoros PSR-17 factory + * @deprecated This will be removed in php-http/message2.0. Consider using the official Diactoros PSR-17 factory */ final class DiactorosStreamFactory implements StreamFactory { diff --git a/src/StreamFactory/GuzzleStreamFactory.php b/src/StreamFactory/GuzzleStreamFactory.php index ef44e25..9adeeb5 100644 --- a/src/StreamFactory/GuzzleStreamFactory.php +++ b/src/StreamFactory/GuzzleStreamFactory.php @@ -9,7 +9,7 @@ * * @author Михаил Красильников * - * @deprecated This will be removed in 2.0. Consider using the official Guzzle PSR-17 factory + * @deprecated This will be removed in php-http/message2.0. Consider using the official Guzzle PSR-17 factory */ final class GuzzleStreamFactory implements StreamFactory { diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index dda4633..9274aae 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -11,7 +11,7 @@ * * @author Mika Tuupola * - * @deprecated This will be removed in 2.0. Consider using the official Slim PSR-17 factory + * @deprecated This will be removed in php-http/message2.0. Consider using the official Slim PSR-17 factory */ final class SlimStreamFactory implements StreamFactory { diff --git a/src/UriFactory/DiactorosUriFactory.php b/src/UriFactory/DiactorosUriFactory.php index 9a06de3..f3b73d0 100644 --- a/src/UriFactory/DiactorosUriFactory.php +++ b/src/UriFactory/DiactorosUriFactory.php @@ -11,7 +11,7 @@ * * @author David de Boer * - * @deprecated This will be removed in 2.0. Consider using the official Diactoros PSR-17 factory + * @deprecated This will be removed in php-http/message2.0. Consider using the official Diactoros PSR-17 factory */ final class DiactorosUriFactory implements UriFactory { diff --git a/src/UriFactory/GuzzleUriFactory.php b/src/UriFactory/GuzzleUriFactory.php index b5db1cd..b16ca52 100644 --- a/src/UriFactory/GuzzleUriFactory.php +++ b/src/UriFactory/GuzzleUriFactory.php @@ -10,7 +10,7 @@ * * @author David de Boer * - * @deprecated This will be removed in 2.0. Consider using the official Guzzle PSR-17 factory + * @deprecated This will be removed in php-http/message2.0. Consider using the official Guzzle PSR-17 factory */ final class GuzzleUriFactory implements UriFactory { diff --git a/src/UriFactory/SlimUriFactory.php b/src/UriFactory/SlimUriFactory.php index b288f6d..e5bef03 100644 --- a/src/UriFactory/SlimUriFactory.php +++ b/src/UriFactory/SlimUriFactory.php @@ -11,7 +11,7 @@ * * @author Mika Tuupola * - * @deprecated This will be removed in 2.0. Consider using the official Slim PSR-17 factory + * @deprecated This will be removed in php-http/message2.0. Consider using the official Slim PSR-17 factory */ final class SlimUriFactory implements UriFactory { From 57ed51e071f41ab8ddf938fe3dab3f1d539eb098 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 20 Dec 2019 10:43:46 +0000 Subject: [PATCH 068/132] Test on PHP 7.4 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5586e11..8095e84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: php -sudo: false - cache: directories: - $HOME/.composer/cache/files @@ -10,6 +8,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4 env: global: From f910da169b56679ce55aa8f2368d9a93ea383321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 27 Dec 2019 16:40:53 +0100 Subject: [PATCH 069/132] Enhancement: Use ergebnis/composer-normalize instead of localheinz/composer-normalize --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3e94bae..b5b2cdd 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,9 @@ "ext-zlib": "*", "akeneo/phpspec-skip-example-extension": "^1.0", "coduo/phpspec-data-provider-extension": "^1.0", + "ergebnis/composer-normalize": "^2.1.1", "guzzlehttp/psr7": "^1.0", "henrikbjorn/phpspec-code-coverage": "^1.0", - "localheinz/composer-normalize": "^1.2.0", "phpspec/phpspec": "^2.4", "slim/slim": "^3.0", "zendframework/zend-diactoros": "^1.0" From 74924cbcdf704b9824bcb4f3424cb9ba8cfae8f1 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 14:57:48 +0100 Subject: [PATCH 070/132] Remove community health files --- .github/CONTRIBUTING.md | 3 --- .github/ISSUE_TEMPLATE.md | 27 -------------------- .github/PULL_REQUEST_TEMPLATE.md | 43 -------------------------------- README.md | 8 ------ 4 files changed, 81 deletions(-) delete mode 100644 .github/CONTRIBUTING.md delete mode 100644 .github/ISSUE_TEMPLATE.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md deleted file mode 100644 index fb288d9..0000000 --- a/.github/CONTRIBUTING.md +++ /dev/null @@ -1,3 +0,0 @@ -# Contributing - -Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html). diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index d4ecf20..0000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,27 +0,0 @@ -| Q | A -| ------------ | --- -| Bug? | no|yes -| New Feature? | no|yes -| Version | Specific version or SHA of a commit - - -#### Actual Behavior - -What is the actual behavior? - - -#### Expected Behavior - -What is the behavior you expect? - - -#### Steps to Reproduce - -What are the steps to reproduce this bug? Please add code examples, -screenshots or links to GitHub repositories that reproduce the problem. - - -#### Possible Solutions - -If you have already ideas how to solve the issue, add them here. -(remove this section if not needed) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 323987b..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,43 +0,0 @@ -| Q | A -| --------------- | --- -| Bug fix? | no|yes -| New feature? | no|yes -| BC breaks? | no|yes -| Deprecations? | no|yes -| Related tickets | fixes #X, partially #Y, mentioned in #Z -| Documentation | if this is a new feature, link to pull request in https://github.com/php-http/documentation that adds relevant documentation -| License | MIT - - -#### What's in this PR? - -Explain what the changes in this PR do. - - -#### Why? - -Which problem does the PR fix? (remove this section if you linked an issue above) - - -#### Example Usage - -``` php -// If you added new features, show examples of how to use them here -// (remove this section if not a new feature) - -$foo = new Foo(); - -// Now we can do -$foo->doSomething(); -``` - - -#### Checklist - -- [ ] Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix -- [ ] Documentation pull request created (if not simply a bugfix) - - -#### To Do - -- [ ] If the PR is not complete but you want to discuss the approach, list what remains to be done here diff --git a/README.md b/README.md index f6f6e19..d55a823 100644 --- a/README.md +++ b/README.md @@ -43,18 +43,10 @@ $ composer test ``` -## Contributing - -Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html). - ## Credits Thanks to [Cuzzle](https://github.com/namshi/cuzzle) for inpiration for the `CurlCommandFormatter`. -## Security - -If you discover any security related issues, please contact us at [security@php-http.org](mailto:security@php-http.org). - ## License From 47e4384cb18a2ddd7a88bf09cf4630091ec1b8e1 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 15:00:07 +0100 Subject: [PATCH 071/132] Add composer normalize --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b5b2cdd..c161768 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "ext-zlib": "*", "akeneo/phpspec-skip-example-extension": "^1.0", "coduo/phpspec-data-provider-extension": "^1.0", - "ergebnis/composer-normalize": "^2.1.1", + "ergebnis/composer-normalize": "^2.1", "guzzlehttp/psr7": "^1.0", "henrikbjorn/phpspec-code-coverage": "^1.0", "phpspec/phpspec": "^2.4", From 9a23e29ada1eca7485a5ff042d07f1d0202f960d Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 15:03:40 +0100 Subject: [PATCH 072/132] Improve php cs fixer --- .gitattributes | 6 ++---- .gitignore | 3 ++- .php_cs | 13 ------------- .php_cs.dist | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 18 deletions(-) delete mode 100644 .php_cs create mode 100644 .php_cs.dist diff --git a/.gitattributes b/.gitattributes index c47225a..254f94a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,11 @@ -.editorconfig export-ignore +.editorconfig export-ignore .gitattributes export-ignore /.github/ export-ignore .gitignore export-ignore -/.php_cs export-ignore +/.php_cs.dist export-ignore /.scrutinizer.yml export-ignore /.styleci.yml export-ignore /.travis.yml export-ignore -/behat.yml.dist export-ignore -/features/ export-ignore /phpspec.ci.yml export-ignore /phpspec.yml.dist export-ignore /phpunit.xml.dist export-ignore diff --git a/.gitignore b/.gitignore index 16b4a20..1029e28 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -/behat.yml +.php_cs +.php_cs.cache /build/ /composer.lock /phpspec.yml diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 23ba165..0000000 --- a/.php_cs +++ /dev/null @@ -1,13 +0,0 @@ -setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + 'single_line_throw' => false, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__.'/src') + ->name('*.php') + ) +; + +return $config; From a8538848b98ffe07f32a0e315129a482ce99d935 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 15:03:58 +0100 Subject: [PATCH 073/132] Run php cs fixer --- src/Authentication/Matching.php | 7 +------ src/Authentication/QueryParam.php | 3 --- src/Authentication/RequestConditional.php | 4 ---- src/Builder/ResponseBuilder.php | 20 +++++++++---------- src/Cookie.php | 10 ++++------ src/CookieJar.php | 10 ---------- src/CookieUtil.php | 2 +- src/Decorator/RequestDecorator.php | 2 -- src/Decorator/ResponseDecorator.php | 2 -- src/Encoding/CompressStream.php | 3 +-- src/Encoding/DecompressStream.php | 3 +-- src/Encoding/DeflateStream.php | 3 +-- src/Encoding/FilteredStream.php | 5 ++--- src/Encoding/GzipDecodeStream.php | 3 +-- src/Encoding/GzipEncodeStream.php | 3 +-- src/Encoding/InflateStream.php | 3 +-- src/Formatter.php | 4 ---- src/Formatter/CurlCommandFormatter.php | 2 -- src/Formatter/FullHttpMessageFormatter.php | 3 +-- .../DiactorosMessageFactory.php | 2 +- src/MessageFactory/SlimMessageFactory.php | 4 ++-- src/RequestMatcher/CallbackRequestMatcher.php | 3 --- 22 files changed, 27 insertions(+), 74 deletions(-) diff --git a/src/Authentication/Matching.php b/src/Authentication/Matching.php index 4b89b50..7a5c247 100644 --- a/src/Authentication/Matching.php +++ b/src/Authentication/Matching.php @@ -27,10 +27,6 @@ final class Matching implements Authentication */ private $matcher; - /** - * @param Authentication $authentication - * @param callable|null $matcher - */ public function __construct(Authentication $authentication, callable $matcher = null) { if (is_null($matcher)) { @@ -58,8 +54,7 @@ public function authenticate(RequestInterface $request) /** * Creates a matching authentication for an URL. * - * @param Authentication $authentication - * @param string $url + * @param string $url * * @return self */ diff --git a/src/Authentication/QueryParam.php b/src/Authentication/QueryParam.php index 650cac7..7f95d44 100644 --- a/src/Authentication/QueryParam.php +++ b/src/Authentication/QueryParam.php @@ -20,9 +20,6 @@ final class QueryParam implements Authentication */ private $params = []; - /** - * @param array $params - */ public function __construct(array $params) { $this->params = $params; diff --git a/src/Authentication/RequestConditional.php b/src/Authentication/RequestConditional.php index 5477440..01062cf 100644 --- a/src/Authentication/RequestConditional.php +++ b/src/Authentication/RequestConditional.php @@ -23,10 +23,6 @@ final class RequestConditional implements Authentication */ private $authentication; - /** - * @param RequestMatcher $requestMatcher - * @param Authentication $authentication - */ public function __construct(RequestMatcher $requestMatcher, Authentication $authentication) { $this->requestMatcher = $requestMatcher; diff --git a/src/Builder/ResponseBuilder.php b/src/Builder/ResponseBuilder.php index de2e882..4c3ecfc 100644 --- a/src/Builder/ResponseBuilder.php +++ b/src/Builder/ResponseBuilder.php @@ -18,8 +18,6 @@ class ResponseBuilder /** * Create builder for the given response. - * - * @param ResponseInterface $response */ public function __construct(ResponseInterface $response) { @@ -39,12 +37,12 @@ public function getResponse() /** * Add headers represented by an array of header lines. * - * @param string[] $headers Response headers as array of header lines. + * @param string[] $headers response headers as array of header lines * * @return $this * - * @throws \UnexpectedValueException For invalid header values. - * @throws \InvalidArgumentException For invalid status code arguments. + * @throws \UnexpectedValueException for invalid header values + * @throws \InvalidArgumentException for invalid status code arguments */ public function setHeadersFromArray(array $headers) { @@ -66,12 +64,12 @@ public function setHeadersFromArray(array $headers) /** * Add headers represented by a single string. * - * @param string $headers Response headers as single string. + * @param string $headers response headers as single string * * @return $this * * @throws \InvalidArgumentException if $headers is not a string on object with __toString() - * @throws \UnexpectedValueException For invalid header values. + * @throws \UnexpectedValueException for invalid header values */ public function setHeadersFromString($headers) { @@ -95,11 +93,11 @@ public function setHeadersFromString($headers) /** * Set response status from a status string. * - * @param string $statusLine Response status as a string. + * @param string $statusLine response status as a string * * @return $this * - * @throws \InvalidArgumentException For invalid status line. + * @throws \InvalidArgumentException for invalid status line */ public function setStatus($statusLine) { @@ -121,11 +119,11 @@ public function setStatus($statusLine) /** * Add header represented by a string. * - * @param string $headerLine Response header as a string. + * @param string $headerLine response header as a string * * @return $this * - * @throws \InvalidArgumentException For invalid header names or values. + * @throws \InvalidArgumentException for invalid header names or values */ public function addHeader($headerLine) { diff --git a/src/Cookie.php b/src/Cookie.php index 98ac57c..0cc2d43 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -63,7 +63,7 @@ final class Cookie * @param bool $httpOnly * @param \DateTime|null $expires Expires attribute is HTTP 1.0 only and should be avoided. * - * @throws \InvalidArgumentException If name, value or max age is not valid. + * @throws \InvalidArgumentException if name, value or max age is not valid */ public function __construct( $name, @@ -226,8 +226,6 @@ public function hasExpires() /** * Sets the expires. * - * @param \DateTime|null $expires - * * @return Cookie */ public function withExpires(\DateTime $expires = null) @@ -435,7 +433,7 @@ public function isValid() * * @param string $name * - * @throws \InvalidArgumentException If the name is empty or contains invalid characters. + * @throws \InvalidArgumentException if the name is empty or contains invalid characters */ private function validateName($name) { @@ -456,7 +454,7 @@ private function validateName($name) * * @param string|null $value * - * @throws \InvalidArgumentException If the value contains invalid characters. + * @throws \InvalidArgumentException if the value contains invalid characters */ private function validateValue($value) { @@ -472,7 +470,7 @@ private function validateValue($value) * * @param int|null $maxAge * - * @throws \InvalidArgumentException If the Max-Age is not an empty or integer value. + * @throws \InvalidArgumentException if the Max-Age is not an empty or integer value */ private function validateMaxAge($maxAge) { diff --git a/src/CookieJar.php b/src/CookieJar.php index ab267d3..6d60ec2 100644 --- a/src/CookieJar.php +++ b/src/CookieJar.php @@ -22,8 +22,6 @@ public function __construct() /** * Checks if there is a cookie. * - * @param Cookie $cookie - * * @return bool */ public function hasCookie(Cookie $cookie) @@ -33,8 +31,6 @@ public function hasCookie(Cookie $cookie) /** * Adds a cookie. - * - * @param Cookie $cookie */ public function addCookie(Cookie $cookie) { @@ -57,8 +53,6 @@ public function addCookie(Cookie $cookie) /** * Removes a cookie. - * - * @param Cookie $cookie */ public function removeCookie(Cookie $cookie) { @@ -82,8 +76,6 @@ public function getCookies() /** * Returns all matching cookies. * - * @param Cookie $cookie - * * @return Cookie[] */ public function getMatchingCookies(Cookie $cookie) @@ -98,8 +90,6 @@ public function getMatchingCookies(Cookie $cookie) /** * Finds matching cookies based on a callable. * - * @param callable $match - * * @return Cookie[] */ protected function findMatchingCookies(callable $match) diff --git a/src/CookieUtil.php b/src/CookieUtil.php index 5c670d4..44c5314 100644 --- a/src/CookieUtil.php +++ b/src/CookieUtil.php @@ -30,7 +30,7 @@ final class CookieUtil * * @return \DateTime * - * @throws UnexpectedValueException if we cannot parse the cookie date string. + * @throws UnexpectedValueException if we cannot parse the cookie date string */ public static function parseDate($dateValue) { diff --git a/src/Decorator/RequestDecorator.php b/src/Decorator/RequestDecorator.php index 7c50e58..bd254a8 100644 --- a/src/Decorator/RequestDecorator.php +++ b/src/Decorator/RequestDecorator.php @@ -17,8 +17,6 @@ trait RequestDecorator /** * Exchanges the underlying request with another. * - * @param RequestInterface $request - * * @return self */ public function withRequest(RequestInterface $request) diff --git a/src/Decorator/ResponseDecorator.php b/src/Decorator/ResponseDecorator.php index 82d9ae0..20319ed 100644 --- a/src/Decorator/ResponseDecorator.php +++ b/src/Decorator/ResponseDecorator.php @@ -16,8 +16,6 @@ trait ResponseDecorator /** * Exchanges the underlying response with another. * - * @param ResponseInterface $response - * * @return self */ public function withResponse(ResponseInterface $response) diff --git a/src/Encoding/CompressStream.php b/src/Encoding/CompressStream.php index eeec6e0..bdb740a 100644 --- a/src/Encoding/CompressStream.php +++ b/src/Encoding/CompressStream.php @@ -13,8 +13,7 @@ class CompressStream extends FilteredStream { /** - * @param StreamInterface $stream - * @param int $level + * @param int $level */ public function __construct(StreamInterface $stream, $level = -1) { diff --git a/src/Encoding/DecompressStream.php b/src/Encoding/DecompressStream.php index 9a950ea..ab3a345 100644 --- a/src/Encoding/DecompressStream.php +++ b/src/Encoding/DecompressStream.php @@ -13,8 +13,7 @@ class DecompressStream extends FilteredStream { /** - * @param StreamInterface $stream - * @param int $level + * @param int $level */ public function __construct(StreamInterface $stream, $level = -1) { diff --git a/src/Encoding/DeflateStream.php b/src/Encoding/DeflateStream.php index f7ce8e2..2ab3e00 100644 --- a/src/Encoding/DeflateStream.php +++ b/src/Encoding/DeflateStream.php @@ -13,8 +13,7 @@ class DeflateStream extends FilteredStream { /** - * @param StreamInterface $stream - * @param int $level + * @param int $level */ public function __construct(StreamInterface $stream, $level = -1) { diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index 7e5713e..65f40de 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -54,9 +54,8 @@ abstract class FilteredStream implements StreamInterface protected $buffer = ''; /** - * @param StreamInterface $stream - * @param mixed|null $readFilterOptions - * @param mixed|null $writeFilterOptions deprecated since 1.5, will be removed in 2.0 + * @param mixed|null $readFilterOptions + * @param mixed|null $writeFilterOptions deprecated since 1.5, will be removed in 2.0 */ public function __construct(StreamInterface $stream, $readFilterOptions = null, $writeFilterOptions = null) { diff --git a/src/Encoding/GzipDecodeStream.php b/src/Encoding/GzipDecodeStream.php index 19a2b8f..92b5dad 100644 --- a/src/Encoding/GzipDecodeStream.php +++ b/src/Encoding/GzipDecodeStream.php @@ -13,8 +13,7 @@ class GzipDecodeStream extends FilteredStream { /** - * @param StreamInterface $stream - * @param int $level + * @param int $level */ public function __construct(StreamInterface $stream, $level = -1) { diff --git a/src/Encoding/GzipEncodeStream.php b/src/Encoding/GzipEncodeStream.php index 8555d4a..13f097a 100644 --- a/src/Encoding/GzipEncodeStream.php +++ b/src/Encoding/GzipEncodeStream.php @@ -13,8 +13,7 @@ class GzipEncodeStream extends FilteredStream { /** - * @param StreamInterface $stream - * @param int $level + * @param int $level */ public function __construct(StreamInterface $stream, $level = -1) { diff --git a/src/Encoding/InflateStream.php b/src/Encoding/InflateStream.php index 863b73d..06c5187 100644 --- a/src/Encoding/InflateStream.php +++ b/src/Encoding/InflateStream.php @@ -13,8 +13,7 @@ class InflateStream extends FilteredStream { /** - * @param StreamInterface $stream - * @param int $level + * @param int $level */ public function __construct(StreamInterface $stream, $level = -1) { diff --git a/src/Formatter.php b/src/Formatter.php index d04d2c3..d6cd21b 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -15,8 +15,6 @@ interface Formatter /** * Formats a request. * - * @param RequestInterface $request - * * @return string */ public function formatRequest(RequestInterface $request); @@ -24,8 +22,6 @@ public function formatRequest(RequestInterface $request); /** * Formats a response. * - * @param ResponseInterface $response - * * @return string */ public function formatResponse(ResponseInterface $response); diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 2ddb149..6554fc1 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -68,8 +68,6 @@ public function formatResponse(ResponseInterface $response) } /** - * @param RequestInterface $request - * * @return string */ private function getHeadersAsCommandOptions(RequestInterface $request) diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index d065f0e..0495802 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -70,8 +70,7 @@ public function formatResponse(ResponseInterface $response) /** * Add the message body if the stream is seekable. * - * @param MessageInterface $request - * @param string $message + * @param string $message * * @return string */ diff --git a/src/MessageFactory/DiactorosMessageFactory.php b/src/MessageFactory/DiactorosMessageFactory.php index 10a49f2..94b9ad2 100644 --- a/src/MessageFactory/DiactorosMessageFactory.php +++ b/src/MessageFactory/DiactorosMessageFactory.php @@ -2,8 +2,8 @@ namespace Http\Message\MessageFactory; -use Http\Message\StreamFactory\DiactorosStreamFactory; use Http\Message\MessageFactory; +use Http\Message\StreamFactory\DiactorosStreamFactory; use Zend\Diactoros\Request; use Zend\Diactoros\Response; diff --git a/src/MessageFactory/SlimMessageFactory.php b/src/MessageFactory/SlimMessageFactory.php index 869cf77..bee9322 100644 --- a/src/MessageFactory/SlimMessageFactory.php +++ b/src/MessageFactory/SlimMessageFactory.php @@ -2,12 +2,12 @@ namespace Http\Message\MessageFactory; +use Http\Message\MessageFactory; use Http\Message\StreamFactory\SlimStreamFactory; use Http\Message\UriFactory\SlimUriFactory; -use Http\Message\MessageFactory; +use Slim\Http\Headers; use Slim\Http\Request; use Slim\Http\Response; -use Slim\Http\Headers; /** * Creates Slim 3 messages. diff --git a/src/RequestMatcher/CallbackRequestMatcher.php b/src/RequestMatcher/CallbackRequestMatcher.php index 4d45e32..1197dd9 100644 --- a/src/RequestMatcher/CallbackRequestMatcher.php +++ b/src/RequestMatcher/CallbackRequestMatcher.php @@ -17,9 +17,6 @@ final class CallbackRequestMatcher implements RequestMatcher */ private $callback; - /** - * @param callable $callback - */ public function __construct(callable $callback) { $this->callback = $callback; From 03ea4f1b73cd33aade62dd722bfb3ee6505f83af Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 15:06:27 +0100 Subject: [PATCH 074/132] Add phpstan config --- .gitattributes | 28 ++-- .gitignore | 1 + phpstan-baseline.neon | 337 ++++++++++++++++++++++++++++++++++++++++++ phpstan.neon.dist | 7 + 4 files changed, 360 insertions(+), 13 deletions(-) create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon.dist diff --git a/.gitattributes b/.gitattributes index 254f94a..60aab89 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,15 @@ -.editorconfig export-ignore -.gitattributes export-ignore -/.github/ export-ignore -.gitignore export-ignore -/.php_cs.dist export-ignore -/.scrutinizer.yml export-ignore -/.styleci.yml export-ignore -/.travis.yml export-ignore -/phpspec.ci.yml export-ignore -/phpspec.yml.dist export-ignore -/phpunit.xml.dist export-ignore -/spec/ export-ignore -/tests/ export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +/.github/ export-ignore +.gitignore export-ignore +/.php_cs.dist export-ignore +/.scrutinizer.yml export-ignore +/.styleci.yml export-ignore +/.travis.yml export-ignore +/phpspec.ci.yml export-ignore +/phpspec.yml.dist export-ignore +/phpstan-baseline.neon export-ignore +/phpstan.neon.dist export-ignore +/phpunit.xml.dist export-ignore +/spec/ export-ignore +/tests/ export-ignore diff --git a/.gitignore b/.gitignore index 1029e28..9771070 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ /build/ /composer.lock /phpspec.yml +/phpstan.neon /phpunit.xml /vendor/ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..c5e0ce2 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,337 @@ +parameters: + ignoreErrors: + - + message: "#^Property Http\\\\Message\\\\Authentication\\\\Header\\:\\:\\$value type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/Authentication/Header.php + + - + message: "#^Method Http\\\\Message\\\\Authentication\\\\Header\\:\\:__construct\\(\\) has parameter \\$value with no typehint specified\\.$#" + count: 1 + path: src/Authentication/Header.php + + - + message: "#^Property Http\\\\Message\\\\Authentication\\\\QueryParam\\:\\:\\$params type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/Authentication/QueryParam.php + + - + message: "#^Method Http\\\\Message\\\\Authentication\\\\QueryParam\\:\\:__construct\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Authentication/QueryParam.php + + - + message: "#^Parameter \\#2 \\$prefix of function http_build_query expects string, null given\\.$#" + count: 1 + path: src/Authentication/QueryParam.php + + - + message: "#^Parameter \\#1 \\$statusLine of method Http\\\\Message\\\\Builder\\\\ResponseBuilder\\:\\:setStatus\\(\\) expects string, string\\|null given\\.$#" + count: 1 + path: src/Builder/ResponseBuilder.php + + - + message: "#^Result of \\|\\| is always true\\.$#" + count: 1 + path: src/Builder/ResponseBuilder.php + + - + message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" + count: 1 + path: src/Builder/ResponseBuilder.php + + - + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:createWithoutValidation\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Cookie.php + + - + message: "#^Parameter \\#2 \\$str2 of function strcasecmp expects string, string\\|null given\\.$#" + count: 1 + path: src/Cookie.php + + - + message: "#^Parameter \\#1 \\$str of function preg_quote expects string, string\\|null given\\.$#" + count: 1 + path: src/Cookie.php + + - + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateName\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Cookie.php + + - + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateValue\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Cookie.php + + - + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateMaxAge\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Cookie.php + + - + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:normalizeDomain\\(\\) should return string but returns string\\|null\\.$#" + count: 1 + path: src/Cookie.php + + - + message: "#^Parameter \\#1 \\$str of function rtrim expects string, string\\|null given\\.$#" + count: 1 + path: src/Cookie.php + + - + message: "#^Class Http\\\\Message\\\\CookieJar implements generic interface IteratorAggregate but does not specify its types\\: TKey, TValue$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookie\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookie\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:findMatchingCookies\\(\\) should return array\\ but returns array\\\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:setCookies\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookies\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookies\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeMatchingCookies\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Left side of && is always true\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:clear\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:count\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:getIterator\\(\\) return type has no value type specified in iterable type Traversable\\\\.$#" + count: 1 + path: src/CookieJar.php + + - + message: "#^Property Http\\\\Message\\\\CookieUtil\\:\\:\\$dateFormats type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/CookieUtil.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:getSize\\(\\) has no return typehint specified\\.$#" + count: 2 + path: src/Encoding/FilteredStream.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:isSeekable\\(\\) has no return typehint specified\\.$#" + count: 2 + path: src/Encoding/FilteredStream.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return typehint specified\\.$#" + count: 2 + path: src/Encoding/FilteredStream.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return typehint specified\\.$#" + count: 2 + path: src/Encoding/FilteredStream.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Encoding/FilteredStream.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\ChunkStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Encoding/ChunkStream.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Encoding/Filter/Chunk.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$closing with no typehint specified\\.$#" + count: 1 + path: src/Encoding/Filter/Chunk.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$consumed with no typehint specified\\.$#" + count: 1 + path: src/Encoding/Filter/Chunk.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$in with no typehint specified\\.$#" + count: 1 + path: src/Encoding/Filter/Chunk.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$out with no typehint specified\\.$#" + count: 1 + path: src/Encoding/Filter/Chunk.php + + - + message: "#^Access to an undefined property Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:\\$stream\\.$#" + count: 2 + path: src/Encoding/Filter/Chunk.php + + - + message: "#^Access to an undefined property object\\:\\:\\$datalen\\.$#" + count: 2 + path: src/Encoding/Filter/Chunk.php + + - + message: "#^Parameter \\#2 \\$bucket of function stream_bucket_append expects object, resource given\\.$#" + count: 2 + path: src/Encoding/Filter/Chunk.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: src/Encoding/Filter/Chunk.php + + - + message: "#^Method Http\\\\Message\\\\MessageFactory\\\\DiactorosMessageFactory\\:\\:createRequest\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#" + count: 1 + path: src/MessageFactory/DiactorosMessageFactory.php + + - + message: "#^Method Http\\\\Message\\\\MessageFactory\\\\DiactorosMessageFactory\\:\\:createResponse\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#" + count: 1 + path: src/MessageFactory/DiactorosMessageFactory.php + + - + message: "#^Method Http\\\\Message\\\\MessageFactory\\\\GuzzleMessageFactory\\:\\:createRequest\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#" + count: 1 + path: src/MessageFactory/GuzzleMessageFactory.php + + - + message: "#^Method Http\\\\Message\\\\MessageFactory\\\\GuzzleMessageFactory\\:\\:createResponse\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#" + count: 1 + path: src/MessageFactory/GuzzleMessageFactory.php + + - + message: "#^Method Http\\\\Message\\\\MessageFactory\\\\SlimMessageFactory\\:\\:createRequest\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#" + count: 1 + path: src/MessageFactory/SlimMessageFactory.php + + - + message: "#^Method Http\\\\Message\\\\MessageFactory\\\\SlimMessageFactory\\:\\:createResponse\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#" + count: 1 + path: src/MessageFactory/SlimMessageFactory.php + + - + message: "#^Property Http\\\\Message\\\\RequestMatcher\\\\RequestMatcher\\:\\:\\$methods type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/RequestMatcher/RequestMatcher.php + + - + message: "#^Property Http\\\\Message\\\\RequestMatcher\\\\RequestMatcher\\:\\:\\$path \\(string\\) does not accept string\\|null\\.$#" + count: 1 + path: src/RequestMatcher/RequestMatcher.php + + - + message: "#^Property Http\\\\Message\\\\RequestMatcher\\\\RequestMatcher\\:\\:\\$host \\(string\\) does not accept string\\|null\\.$#" + count: 1 + path: src/RequestMatcher/RequestMatcher.php + + - + message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$size \\(int\\) does not accept int\\|null\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$resource \\(resource\\) does not accept resource\\|false\\.$#" + count: 2 + path: src/Stream/BufferedStream.php + + - + message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:detach\\(\\) should return resource\\|null but empty return statement found\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$stream \\(Psr\\\\Http\\\\Message\\\\StreamInterface\\) does not accept null\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$resource \\(resource\\) does not accept null\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:getSize\\(\\) should return int\\|null but empty return statement found\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:tell\\(\\) should return int but returns int\\|false\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:seek\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:rewind\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Parameter \\#1 \\$string of function strlen expects string, string\\|false given\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:read\\(\\) should return string but returns string\\|false\\.$#" + count: 1 + path: src/Stream/BufferedStream.php + + - + message: "#^Parameter \\#1 \\$stream of class Slim\\\\Http\\\\Stream constructor expects resource, resource\\|false given\\.$#" + count: 1 + path: src/StreamFactory/SlimStreamFactory.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: src/UriFactory/SlimUriFactory.php + diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..6f8227f --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,7 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: max + paths: + - src From 1fd5c2c78755b340bf8cd87c145b0a230aab1759 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 15:06:49 +0100 Subject: [PATCH 075/132] Add github actions --- .github/workflows/.editorconfig | 2 ++ .github/workflows/checks.yml | 37 +++++++++++++++++++++ .github/workflows/ci.yml | 59 +++++++++++++++++++++++++++++++++ .github/workflows/static.yml | 34 +++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 .github/workflows/.editorconfig create mode 100644 .github/workflows/checks.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/static.yml diff --git a/.github/workflows/.editorconfig b/.github/workflows/.editorconfig new file mode 100644 index 0000000..7bd3346 --- /dev/null +++ b/.github/workflows/.editorconfig @@ -0,0 +1,2 @@ +[*.yml] +indent_size = 2 diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..48ffa14 --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,37 @@ +name: Checks + +on: + push: + branches: + - master + pull_request: + +jobs: + composer-normalize: + name: Composer Normalize + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v1 + + - name: Install + uses: docker://composer + with: + args: install + + - name: Normalize + uses: docker://composer + with: + args: composer normalize --dry-run + + roave-bc-check: + name: Roave BC Check + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v1 + + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c2070ac --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + build-lowest-version: + name: Build lowest version + runs-on: ubuntu-latest + + steps: + - name: Set up PHP + uses: shivammathur/setup-php@1.6.2 + with: + php-version: '7.1' + coverage: xdebug + extensions: mbstring + + - name: Setup Problem Matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Checkout code + uses: actions/checkout@v1 + + - name: Download dependencies + run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --no-suggest --prefer-lowest + + - name: Run tests + run: composer test-ci + + build: + name: Build + runs-on: ubuntu-latest + strategy: + max-parallel: 10 + matrix: + php: ['7.1', '7.2', '7.3', '7.4'] + + steps: + - name: Set up PHP + uses: shivammathur/setup-php@1.6.2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring + + - name: Setup Problem Matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Checkout code + uses: actions/checkout@v1 + + - name: Download dependencies + run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --no-suggest + + - name: Run tests + run: composer test diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..9d15468 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,34 @@ +name: Static analysis + +on: + push: + branches: + - master + pull_request: + +jobs: + phpstan: + name: PHPStan + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v1 + + - name: PHPStan + uses: docker://oskarstark/phpstan-ga + with: + args: analyze --no-progress + + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v1 + + - name: PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --dry-run --diff-format udiff From cfa22caae5dbbd4f1cb524aa74140fb4ebc884a1 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 15:20:47 +0100 Subject: [PATCH 076/132] Remove license badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index d55a823..5facafc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # HTTP Message [![Latest Version](https://img.shields.io/github/release/php-http/message.svg?style=flat-square)](https://github.com/php-http/message/releases) -[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) [![Build Status](https://img.shields.io/travis/php-http/message.svg?style=flat-square)](https://travis-ci.org/php-http/message) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/message.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/message) [![Quality Score](https://img.shields.io/scrutinizer/g/php-http/message.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/message) From cca684f13eaf586200fe15ac241dec3c4ac780f0 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 15:23:22 +0100 Subject: [PATCH 077/132] Drop travis --- .gitattributes | 1 - .travis.yml | 36 ------------------------------------ README.md | 2 +- 3 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes index 60aab89..4007b2d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,7 +5,6 @@ /.php_cs.dist export-ignore /.scrutinizer.yml export-ignore /.styleci.yml export-ignore -/.travis.yml export-ignore /phpspec.ci.yml export-ignore /phpspec.yml.dist export-ignore /phpstan-baseline.neon export-ignore diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8095e84..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: php - -cache: - directories: - - $HOME/.composer/cache/files - -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -env: - global: - - TEST_COMMAND="composer test" - -matrix: - fast_finish: true - include: - - php: 7.1 - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" - -before_install: - - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi - -install: - - composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction - -script: - - composer validate - - composer normalize --dry-run - - $TEST_COMMAND - -after_success: - - if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi diff --git a/README.md b/README.md index 5facafc..dbdc80c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # HTTP Message [![Latest Version](https://img.shields.io/github/release/php-http/message.svg?style=flat-square)](https://github.com/php-http/message/releases) -[![Build Status](https://img.shields.io/travis/php-http/message.svg?style=flat-square)](https://travis-ci.org/php-http/message) +![GitHub Workflow Status](https://img.shields.io/github/workflow/status/php-http/message/CI?style=flat-square) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/message.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/message) [![Quality Score](https://img.shields.io/scrutinizer/g/php-http/message.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/message) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/message.svg?style=flat-square)](https://packagist.org/packages/php-http/message) From 257e65cd0fcacc21c49f403c5823a20f48b138dd Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 15:34:09 +0100 Subject: [PATCH 078/132] Drop styleci --- .gitattributes | 1 - .styleci.yml | 14 -------------- 2 files changed, 15 deletions(-) delete mode 100644 .styleci.yml diff --git a/.gitattributes b/.gitattributes index 4007b2d..2efe1cd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,7 +4,6 @@ .gitignore export-ignore /.php_cs.dist export-ignore /.scrutinizer.yml export-ignore -/.styleci.yml export-ignore /phpspec.ci.yml export-ignore /phpspec.yml.dist export-ignore /phpstan-baseline.neon export-ignore diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 5328b61..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,14 +0,0 @@ -preset: symfony - -finder: - exclude: - - "spec" - path: - - "src" - - "tests" - -enabled: - - short_array_syntax - -disabled: - - phpdoc_annotation_without_dot # This is still buggy: https://github.com/symfony/symfony/pull/19198 From 209c48611dde8c65ec911b745347b315bfd83a84 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 30 Dec 2019 15:36:07 +0100 Subject: [PATCH 079/132] Drop scrutinizer --- .gitattributes | 1 - .scrutinizer.yml | 8 -------- README.md | 2 -- 3 files changed, 11 deletions(-) delete mode 100644 .scrutinizer.yml diff --git a/.gitattributes b/.gitattributes index 2efe1cd..0a004a9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,7 +3,6 @@ /.github/ export-ignore .gitignore export-ignore /.php_cs.dist export-ignore -/.scrutinizer.yml export-ignore /phpspec.ci.yml export-ignore /phpspec.yml.dist export-ignore /phpstan-baseline.neon export-ignore diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 46a7560..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,8 +0,0 @@ -filter: - paths: [src/*] -checks: - php: - code_rating: true - duplication: true -tools: - external_code_coverage: true diff --git a/README.md b/README.md index dbdc80c..52abe2b 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ [![Latest Version](https://img.shields.io/github/release/php-http/message.svg?style=flat-square)](https://github.com/php-http/message/releases) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/php-http/message/CI?style=flat-square) -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/message.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/message) -[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/message.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/message) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/message.svg?style=flat-square)](https://packagist.org/packages/php-http/message) **HTTP Message related tools.** From 5d660cac53c6d43aadf97516cbd6e5332b943b4e Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Fri, 3 Jan 2020 16:09:37 +0100 Subject: [PATCH 080/132] Upgrade GitHub actions --- .github/workflows/checks.yml | 4 ++-- .github/workflows/ci.yml | 10 ++++++---- .github/workflows/static.yml | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 48ffa14..35695a6 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Install uses: docker://composer @@ -31,7 +31,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Roave BC Check uses: docker://nyholm/roave-bc-check-ga diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2070ac..a77b98d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,17 +13,18 @@ jobs: steps: - name: Set up PHP - uses: shivammathur/setup-php@1.6.2 + uses: shivammathur/setup-php@1.7.0 with: php-version: '7.1' coverage: xdebug extensions: mbstring + tools: prestissimo - name: Setup Problem Matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Checkout code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Download dependencies run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --no-suggest --prefer-lowest @@ -41,16 +42,17 @@ jobs: steps: - name: Set up PHP - uses: shivammathur/setup-php@1.6.2 + uses: shivammathur/setup-php@1.7.0 with: php-version: ${{ matrix.php }} extensions: mbstring + tools: prestissimo - name: Setup Problem Matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Checkout code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Download dependencies run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --no-suggest diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 9d15468..aa264e1 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -10,10 +10,10 @@ jobs: phpstan: name: PHPStan runs-on: ubuntu-latest - + steps: - name: Checkout code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: PHPStan uses: docker://oskarstark/phpstan-ga @@ -26,7 +26,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga From 88200d43678cba363add985b563267f903afd16b Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Fri, 3 Jan 2020 16:26:53 +0100 Subject: [PATCH 081/132] Disable Roave BC check for now See https://github.com/Roave/BackwardCompatibilityCheck/issues/37 --- .github/workflows/checks.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 35695a6..e2753b5 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -25,13 +25,14 @@ jobs: with: args: composer normalize --dry-run - roave-bc-check: - name: Roave BC Check - runs-on: ubuntu-latest + # Disabled until https://github.com/Roave/BackwardCompatibilityCheck/issues/37 is resolved + # roave-bc-check: + # name: Roave BC Check + # runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 + # steps: + # - name: Checkout code + # uses: actions/checkout@v2 - - name: Roave BC Check - uses: docker://nyholm/roave-bc-check-ga + # - name: Roave BC Check + # uses: docker://nyholm/roave-bc-check-ga From f48e96f3deb35d4b4387a0711083ad7f917eaf13 Mon Sep 17 00:00:00 2001 From: "M. Tuhin" Date: Wed, 13 May 2020 17:15:34 +0600 Subject: [PATCH 082/132] Fix: composer.json - clue/stream-filter version * clue/stream-filter version should update to 1.4.1. *Problem:* if you use "php-http/message" several time on a package it will call "clue/stream-filter" several time. On their previous version before 1.4.1 they didn't have the duplicate function checking. So, it will create same namespace several time. *Real Life Example:* "php-http/message" has been used in - (infusionsoft/php-sdk)[https://github.com/infusionsoft/infusionsoft-php] if you create several wordpress plugins with - infusionsoft/php-sdk and install all the plugins in same website then "php-http/message" will be called several time so the "clue/stream-filter". Which create error for using same namespace. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c161768..013cfe7 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ ], "require": { "php": "^7.1", - "clue/stream-filter": "^1.4", + "clue/stream-filter": "^1.4.1", "php-http/message-factory": "^1.0.2", "psr/http-message": "^1.0" }, From 8baa5e15c0862049757c8baa5bf9daba5eb793dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Wed, 13 May 2020 23:50:40 +0200 Subject: [PATCH 083/132] Omit binary body in FullHttpMessageFormatter Goes in line with CurlCommandFormatter. Makes this formatter safer to use --- CHANGELOG.md | 2 ++ .../FullHttpMessageFormatterSpec.php | 21 +++++++++++++++++++ src/Formatter/FullHttpMessageFormatter.php | 18 +++++++++------- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a29df8..246ff76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +- Omitted binary body in FullHttpMessageFormatter. `[binary stream omitted]` will be shown instead. + ### Added - New Header authentication method for arbitrary header authentication. diff --git a/spec/Formatter/FullHttpMessageFormatterSpec.php b/spec/Formatter/FullHttpMessageFormatterSpec.php index a1c4588..af45c7f 100644 --- a/spec/Formatter/FullHttpMessageFormatterSpec.php +++ b/spec/Formatter/FullHttpMessageFormatterSpec.php @@ -227,4 +227,25 @@ function it_does_not_format_no_seekable_response(ResponseInterface $response, St STR; $this->formatResponse($response)->shouldReturn($expectedMessage); } + + function it_omits_body_with_null_bytes(RequestInterface $request, StreamInterface $stream) + { + $this->beConstructedWith(1); + + $stream->isSeekable()->willReturn(true); + $stream->rewind()->shouldBeCalled(); + $stream->__toString()->willReturn("\0"); + $request->getBody()->willReturn($stream); + $request->getMethod()->willReturn('GET'); + $request->getRequestTarget()->willReturn('/foo'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([]); + + $expectedMessage = <<formatRequest($request)->shouldReturn($expectedMessage); + } } diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index 0495802..d252d64 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -76,20 +76,24 @@ public function formatResponse(ResponseInterface $response) */ private function addBody(MessageInterface $request, $message) { + $message .= "\n"; $stream = $request->getBody(); if (!$stream->isSeekable() || 0 === $this->maxBodyLength) { // Do not read the stream - return $message."\n"; + return $message; } - if (null === $this->maxBodyLength) { - $message .= "\n".$stream->__toString(); - } else { - $message .= "\n".mb_substr($stream->__toString(), 0, $this->maxBodyLength); + $data = $stream->__toString(); + $stream->rewind(); + + if (preg_match('/[\x00-\x1F\x7F]/', $data)) { + return $message.'[binary stream omitted]'; } - $stream->rewind(); + if (null === $this->maxBodyLength) { + return $message.$data; + } - return $message; + return $message.mb_substr($data, 0, $this->maxBodyLength); } } From 2c7256e3c1aba0bfca70f099810f1c7712e00945 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 17 Aug 2020 08:33:14 +0200 Subject: [PATCH 084/132] prepare release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 246ff76..e34eb6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## Unreleased +## [1.9.0] - 2020-08-17 - Omitted binary body in FullHttpMessageFormatter. `[binary stream omitted]` will be shown instead. From b2afb6bb486b42664ba2a81ab470602ea8da0227 Mon Sep 17 00:00:00 2001 From: Dennis Riehle Date: Mon, 12 Oct 2020 12:01:33 +0200 Subject: [PATCH 085/132] fixed detection of binary strings (#132) --- spec/Formatter/CurlCommandFormatterSpec.php | 18 +++++++++++++++ .../FullHttpMessageFormatterSpec.php | 22 +++++++++++++++++++ src/Formatter/CurlCommandFormatter.php | 3 ++- src/Formatter/FullHttpMessageFormatter.php | 3 ++- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php index f68d7e2..f847a6b 100644 --- a/spec/Formatter/CurlCommandFormatterSpec.php +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -91,6 +91,24 @@ function it_formats_requests_with_null_bytes(RequestInterface $request, UriInter $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[binary stream omitted]'"); } + function it_formats_requests_with_line_break(RequestInterface $request, UriInterface $uri, StreamInterface $body) + { + $request->getUri()->willReturn($uri); + $request->getBody()->willReturn($body); + + $body->__toString()->willReturn("foo\nbar"); + $body->getSize()->willReturn(1); + $body->isSeekable()->willReturn(true); + $body->rewind()->willReturn(true); + + $uri->withFragment('')->willReturn('http://foo.com/bar'); + $request->getMethod()->willReturn('POST'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([]); + + $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data 'foo\nbar'"); + } + function it_formats_requests_with_nonseekable_body(RequestInterface $request, UriInterface $uri, StreamInterface $body) { $request->getUri()->willReturn($uri); diff --git a/spec/Formatter/FullHttpMessageFormatterSpec.php b/spec/Formatter/FullHttpMessageFormatterSpec.php index af45c7f..5d2e6bf 100644 --- a/spec/Formatter/FullHttpMessageFormatterSpec.php +++ b/spec/Formatter/FullHttpMessageFormatterSpec.php @@ -245,6 +245,28 @@ function it_omits_body_with_null_bytes(RequestInterface $request, StreamInterfac GET /foo HTTP/1.1 [binary stream omitted] +STR; + $this->formatRequest($request)->shouldReturn($expectedMessage); + } + + function it_omits_body_with_line_break(RequestInterface $request, StreamInterface $stream) + { + $this->beConstructedWith(7); + + $stream->isSeekable()->willReturn(true); + $stream->rewind()->shouldBeCalled(); + $stream->__toString()->willReturn("foo\nbar"); + $request->getBody()->willReturn($stream); + $request->getMethod()->willReturn('GET'); + $request->getRequestTarget()->willReturn('/foo'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([]); + + $expectedMessage = <<formatRequest($request)->shouldReturn($expectedMessage); } diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 6554fc1..78b1d55 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -42,7 +42,8 @@ public function formatRequest(RequestInterface $request) } elseif ($body->isSeekable()) { $data = $body->__toString(); $body->rewind(); - if (preg_match('/[\x00-\x1F\x7F]/', $data)) { + // all non-printable ASCII characters and except for \t, \r, \n + if (preg_match('/([\x00-\x09\x0C\x0E-\x1F\x7F])/', $data)) { $data = '[binary stream omitted]'; } } else { diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index d252d64..64ce3ce 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -86,7 +86,8 @@ private function addBody(MessageInterface $request, $message) $data = $stream->__toString(); $stream->rewind(); - if (preg_match('/[\x00-\x1F\x7F]/', $data)) { + // all non-printable ASCII characters and except for \t, \r, \n + if (preg_match('/([\x00-\x09\x0C\x0E-\x1F\x7F])/', $data)) { return $message.'[binary stream omitted]'; } From 09f3f13af3a1a4273ecbf8e6b27248c002a3db29 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 13 Oct 2020 08:21:08 +0200 Subject: [PATCH 086/132] prepare release --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e34eb6d..5c31778 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.9.1] - 2020-10-13 + +- Improved detection of binary stream to not consider newlines, carriage return or tabs as binary. ## [1.9.0] - 2020-08-17 -- Omitted binary body in FullHttpMessageFormatter. `[binary stream omitted]` will be shown instead. +- Omitted binary body in FullHttpMessageFormatter and CurlCommandFormatter. + `[binary stream omitted]` will be shown instead. ### Added From 075b945c7018f65004cdccf1dd8755e3d79af971 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 10 Nov 2020 19:35:46 +0000 Subject: [PATCH 087/132] Support PHP 8 --- .gitattributes | 2 +- .github/workflows/checks.yml | 28 +-- .github/workflows/ci.yml | 82 +++++--- .github/workflows/static.yml | 2 + composer.json | 11 +- phpspec.ci.yml | 5 +- phpspec.yml.dist | 4 +- phpstan-baseline.neon | 65 ++---- spec/CookieJarSpec.php | 2 +- spec/CookieSpec.php | 59 +++--- spec/CookieUtilSpec.php | 197 +++++++++++++------ spec/Decorator/MessageDecoratorSpec.php | 2 +- spec/Decorator/RequestDecoratorSpec.php | 2 +- spec/Decorator/ResponseDecoratorSpec.php | 2 +- spec/Decorator/StreamDecoratorSpec.php | 2 +- spec/Encoding/ChunkStreamSpec.php | 1 - spec/Encoding/CompressStreamSpec.php | 1 - spec/Encoding/DechunkStreamSpec.php | 1 - spec/Encoding/DecompressStreamSpec.php | 1 - spec/Encoding/FilteredStreamStubSpec.php | 12 +- spec/Encoding/GzipDecodeStreamSpec.php | 1 - spec/Encoding/GzipEncodeStreamSpec.php | 1 - spec/Encoding/ZlibStreamBehavior.php | 3 - spec/StreamFactory/StreamFactoryBehavior.php | 2 +- 24 files changed, 270 insertions(+), 218 deletions(-) diff --git a/.gitattributes b/.gitattributes index 0a004a9..1fd8ce1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -.editorconfig export-ignore +.editorconfig export-ignore .gitattributes export-ignore /.github/ export-ignore .gitignore export-ignore diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index e2753b5..3a3dfee 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -15,24 +15,16 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Install - uses: docker://composer - with: - args: install + - name: Composer normalize + uses: docker://ergebnis/composer-normalize-action - - name: Normalize - uses: docker://composer - with: - args: composer normalize --dry-run - - # Disabled until https://github.com/Roave/BackwardCompatibilityCheck/issues/37 is resolved - # roave-bc-check: - # name: Roave BC Check - # runs-on: ubuntu-latest + roave-bc-check: + name: Roave BC Check + runs-on: ubuntu-latest - # steps: - # - name: Checkout code - # uses: actions/checkout@v2 + steps: + - name: Checkout code + uses: actions/checkout@v2 - # - name: Roave BC Check - # uses: docker://nyholm/roave-bc-check-ga + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a77b98d..08a1fbb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,60 +2,78 @@ name: CI on: push: - branches: - - master pull_request: jobs: - build-lowest-version: - name: Build lowest version + latest: + name: PHP ${{ matrix.php }} Latest runs-on: ubuntu-latest + strategy: + matrix: + php: ['7.1', '7.2', '7.3', '7.4', '8.0'] steps: - - name: Set up PHP - uses: shivammathur/setup-php@1.7.0 - with: - php-version: '7.1' - coverage: xdebug - extensions: mbstring - tools: prestissimo - - - name: Setup Problem Matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Checkout code uses: actions/checkout@v2 - - name: Download dependencies - run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --no-suggest --prefer-lowest + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer + coverage: none - - name: Run tests - run: composer test-ci + - name: Install dependencies + run: composer update --prefer-dist --no-interaction --no-progress - build: - name: Build + - name: Execute tests + run: composer test + + lowest: + name: PHP ${{ matrix.php }} Lowest runs-on: ubuntu-latest strategy: - max-parallel: 10 matrix: php: ['7.1', '7.2', '7.3', '7.4'] steps: - - name: Set up PHP - uses: shivammathur/setup-php@1.7.0 + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: mbstring - tools: prestissimo + tools: composer + coverage: none + + - name: Install dependencies + run: | + composer require "sebastian/comparator:^3.0.2" --no-interaction --no-update + composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress - - name: Setup Problem Matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Execute tests + run: composer test + + coverage: + name: Code Coverage + runs-on: ubuntu-latest + steps: - name: Checkout code uses: actions/checkout@v2 - - name: Download dependencies - run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --no-suggest + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + tools: composer + coverage: xdebug + + - name: Install dependencies + run: | + composer require "friends-of-phpspec/phpspec-code-coverage:^4.3.2" --no-interaction --no-update + composer update --prefer-dist --no-interaction --no-progress - - name: Run tests - run: composer test + - name: Execute tests + run: composer test-ci diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index aa264e1..b2f69cf 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -17,6 +17,8 @@ jobs: - name: PHPStan uses: docker://oskarstark/phpstan-ga + env: + REQUIRE_DEV: true with: args: analyze --no-progress diff --git a/composer.json b/composer.json index 013cfe7..9a60d8f 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ } ], "require": { - "php": "^7.1", - "clue/stream-filter": "^1.4.1", + "php": "^7.1 || ^8.0", + "clue/stream-filter": "^1.5", "php-http/message-factory": "^1.0.2", "psr/http-message": "^1.0" }, @@ -25,12 +25,9 @@ }, "require-dev": { "ext-zlib": "*", - "akeneo/phpspec-skip-example-extension": "^1.0", - "coduo/phpspec-data-provider-extension": "^1.0", - "ergebnis/composer-normalize": "^2.1", + "ergebnis/composer-normalize": "^2.6", "guzzlehttp/psr7": "^1.0", - "henrikbjorn/phpspec-code-coverage": "^1.0", - "phpspec/phpspec": "^2.4", + "phpspec/phpspec": "^5.1 || ^6.3", "slim/slim": "^3.0", "zendframework/zend-diactoros": "^1.0" }, diff --git a/phpspec.ci.yml b/phpspec.ci.yml index a4a288f..5f8a626 100644 --- a/phpspec.ci.yml +++ b/phpspec.ci.yml @@ -4,9 +4,8 @@ suites: psr4_prefix: Http\Message formatter.name: pretty extensions: - - PhpSpec\Extension\CodeCoverageExtension - - Coduo\PhpSpec\DataProvider\DataProviderExtension - - Akeneo\SkipExampleExtension + FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension: ~ code_coverage: format: clover output: build/coverage.xml +runner.maintainers.errors.level: 16383 diff --git a/phpspec.yml.dist b/phpspec.yml.dist index 56d3c89..785cf0e 100644 --- a/phpspec.yml.dist +++ b/phpspec.yml.dist @@ -3,6 +3,4 @@ suites: namespace: Http\Message psr4_prefix: Http\Message formatter.name: pretty -extensions: - - Coduo\PhpSpec\DataProvider\DataProviderExtension - - Akeneo\SkipExampleExtension +runner.maintainers.errors.level: 16383 diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c5e0ce2..9c95e48 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -130,11 +130,6 @@ parameters: count: 1 path: src/CookieJar.php - - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:count\\(\\) has no return typehint specified\\.$#" - count: 1 - path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:getIterator\\(\\) return type has no value type specified in iterable type Traversable\\\\.$#" count: 1 @@ -145,61 +140,16 @@ parameters: count: 1 path: src/CookieUtil.php - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:getSize\\(\\) has no return typehint specified\\.$#" - count: 2 - path: src/Encoding/FilteredStream.php - - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:isSeekable\\(\\) has no return typehint specified\\.$#" - count: 2 - path: src/Encoding/FilteredStream.php - - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return typehint specified\\.$#" - count: 2 - path: src/Encoding/FilteredStream.php - - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return typehint specified\\.$#" - count: 2 - path: src/Encoding/FilteredStream.php - - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" - count: 1 - path: src/Encoding/FilteredStream.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\ChunkStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" count: 1 path: src/Encoding/ChunkStream.php - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has no return typehint specified\\.$#" - count: 1 - path: src/Encoding/Filter/Chunk.php - - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$closing with no typehint specified\\.$#" - count: 1 - path: src/Encoding/Filter/Chunk.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$consumed with no typehint specified\\.$#" count: 1 path: src/Encoding/Filter/Chunk.php - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$in with no typehint specified\\.$#" - count: 1 - path: src/Encoding/Filter/Chunk.php - - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$out with no typehint specified\\.$#" - count: 1 - path: src/Encoding/Filter/Chunk.php - - message: "#^Access to an undefined property Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:\\$stream\\.$#" count: 2 @@ -220,6 +170,21 @@ parameters: count: 1 path: src/Encoding/Filter/Chunk.php + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Encoding/FilteredStream.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Encoding/FilteredStream.php + + - + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return typehint specified\\.$#" + count: 1 + path: src/Encoding/FilteredStream.php + - message: "#^Method Http\\\\Message\\\\MessageFactory\\\\DiactorosMessageFactory\\:\\:createRequest\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#" count: 1 diff --git a/spec/CookieJarSpec.php b/spec/CookieJarSpec.php index 29afee4..f528395 100644 --- a/spec/CookieJarSpec.php +++ b/spec/CookieJarSpec.php @@ -161,7 +161,7 @@ function it_clears_cookies() $this->count()->shouldReturn(0); } - public function getMatchers() + public function getMatchers(): array { return [ 'beAnArrayOfInstance' => function ($subject, $instance) { diff --git a/spec/CookieSpec.php b/spec/CookieSpec.php index 3de69f3..c4e0c01 100644 --- a/spec/CookieSpec.php +++ b/spec/CookieSpec.php @@ -25,17 +25,20 @@ function it_has_a_name() /** * @dataProvider invalidCharacterExamples */ - function it_throws_an_exception_when_the_name_contains_invalid_character($name, $shouldThrow) + function it_throws_an_exception_when_the_name_contains_invalid_character() { - $this->beConstructedWith($name); + foreach (self::invalidCharacterExamples() as $example) { + $this->beConstructedWith($example[0]); - if ($shouldThrow) { - $expectation = $this->shouldThrow('InvalidArgumentException'); - } else { - $expectation = $this->shouldNotThrow('InvalidArgumentException'); + if ($example[1]) { + $expectation = $this->shouldThrow('InvalidArgumentException'); + } else { + $expectation = $this->shouldNotThrow('InvalidArgumentException'); + } + + $expectation->duringInstantiation(); } - $expectation->duringInstantiation(); } function it_throws_an_expection_when_name_is_empty() @@ -51,20 +54,19 @@ function it_has_a_value() $this->hasValue()->shouldReturn(true); } - /** - * @dataProvider invalidCharacterExamples - */ - function it_throws_an_exception_when_the_value_contains_invalid_character($value, $shouldThrow) + function it_throws_an_exception_when_the_value_contains_invalid_character() { - $this->beConstructedWith('name', $value); + foreach (self::invalidCharacterExamples() as $example) { + $this->beConstructedWith('name', $example[0]); - if ($shouldThrow) { - $expectation = $this->shouldThrow('InvalidArgumentException'); - } else { - $expectation = $this->shouldNotThrow('InvalidArgumentException'); - } + if ($example[1]) { + $expectation = $this->shouldThrow('InvalidArgumentException'); + } else { + $expectation = $this->shouldNotThrow('InvalidArgumentException'); + } - $expectation->duringInstantiation(); + $expectation->duringInstantiation(); + } } function it_accepts_a_value() @@ -75,18 +77,17 @@ function it_accepts_a_value() $cookie->getValue()->shouldReturn('value2'); } - /** - * @dataProvider invalidCharacterExamples - */ - function it_throws_an_exception_when_the_new_value_contains_invalid_character($value, $shouldThrow) + function it_throws_an_exception_when_the_new_value_contains_invalid_character() { - if ($shouldThrow) { - $expectation = $this->shouldThrow('InvalidArgumentException'); - } else { - $expectation = $this->shouldNotThrow('InvalidArgumentException'); - } + foreach (self::invalidCharacterExamples() as $example) { + if ($example[1]) { + $expectation = $this->shouldThrow('InvalidArgumentException'); + } else { + $expectation = $this->shouldNotThrow('InvalidArgumentException'); + } - $expectation->duringWithValue($value); + $expectation->duringWithValue($example[0]); + } } function it_has_a_max_age_time() @@ -270,7 +271,7 @@ function it_can_be_constructed_without_max_age_validation() * * @return array */ - public function invalidCharacterExamples() + private static function invalidCharacterExamples() { return [ ['a', false], diff --git a/spec/CookieUtilSpec.php b/spec/CookieUtilSpec.php index f2fac15..6c831c1 100644 --- a/spec/CookieUtilSpec.php +++ b/spec/CookieUtilSpec.php @@ -7,70 +7,151 @@ class CookieUtilSpec extends ObjectBehavior { - /** - * @dataProvider getCookieStrings - */ - function it_parses_cookie_date_string($cookieDateString, $expectedString) + function it_parses_cookie_date_string_1() { - $this->beConstructedThrough('parseDate', [$cookieDateString]); - $this->shouldHaveType('\DateTime'); - $this->format('l, d-M-Y H:i:s O')->shouldReturn($expectedString); + $this->testCookieParse('Friday, 31 Jul 20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); + } + + function it_parses_cookie_date_string_2() + { + $this->testCookieParse('Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); + } + + function it_parses_cookie_date_string_3() + { + $this->testCookieParse('Fri, 31-Jul-2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); + } + + function it_parses_cookie_date_string_4() + { + $this->testCookieParse('Fri, 31 Jul 2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); + } + + function it_parses_cookie_date_string_5() + { + $this->testCookieParse('Fri, 31-07-2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); + } + + function it_parses_cookie_date_string_6() + { + $this->testCookieParse('Fri, 31-07-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); + } + + function it_parses_cookie_date_string_7() + { + $this->testCookieParse('Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); + } + + function it_parses_cookie_date_string_8() + { + $this->testCookieParse('Fri Jul 31 08:49:37 2020', 'Friday, 31-Jul-2020 08:49:37 +0000'); + } + + function it_parses_cookie_date_string_9() + { + $this->testCookieParse('Friday July 31st 2020, 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); + } + + function it_parses_cookie_date_string_10() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('Wed, 09 Jun 2021 10:18:14 GMT', 'Wednesday, 09-Jun-2021 10:18:14 +0000'); + } + + function it_parses_cookie_date_string_11() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('Wed, 09 Jun 2021 22:18:14 GMT', 'Wednesday, 09-Jun-2021 22:18:14 +0000'); + } + + function it_parses_cookie_date_string_12() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('Tue, 18 Oct 2011 07:42:42.123 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'); + } + + function it_parses_cookie_date_string_13() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('18 Oct 2011 07:42:42 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'); } - /** - * @dataProvider getInvalidCookieDateStrings - */ - function it_throws_an_exception_if_cookie_date_string_is_unparseable($cookieDateString) + function it_parses_cookie_date_string_14() { - $this->beConstructedThrough('parseDate', [$cookieDateString]); + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('8 Oct 2011 7:42:42 GMT', 'Saturday, 08-Oct-2011 07:42:42 +0000'); + } + + function it_parses_cookie_date_string_15() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('8 Oct 2011 7:2:42 GMT', 'Saturday, 08-Oct-2011 07:02:42 +0000'); + } + + function it_parses_cookie_date_string_16() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('Oct 18 2011 07:42:42 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'); + } + + function it_parses_cookie_date_string_17() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('Tue Oct 18 2011 07:05:03 GMT+0000 (GMT)', 'Tuesday, 18-Oct-2011 07:05:03 +0000'); + } + + function it_parses_cookie_date_string_18() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('09 Jun 2021 10:18:14 GMT', 'Wednesday, 09-Jun-2021 10:18:14 +0000'); + } + + function it_parses_cookie_date_string_19() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('01 Jan 1970 00:00:00 GMT', 'Thursday, 01-Jan-1970 00:00:00 +0000'); + } + + function it_parses_cookie_date_string_20() + { + // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 + $this->testCookieParse('01 Jan 1601 00:00:00 GMT', 'Monday, 01-Jan-1601 00:00:00 +0000'); + } + + function it_parses_cookie_date_string_21() + { + // implicit year + $this->testCookieParse('10 Feb 81 13:00:00 GMT', 'Tuesday, 10-Feb-1981 13:00:00 +0000'); + } + + function it_parses_cookie_date_string_22() + { + // dashes + $this->testCookieParse('Thu, 17-Apr-2014 02:12:29 GMT', 'Thursday, 17-Apr-2014 02:12:29 +0000'); + } + + function it_parses_cookie_date_string_23() + { + // dashes and UTC + $this->testCookieParse('Thu, 17-Apr-2014 02:12:29 UTC', 'Thursday, 17-Apr-2014 02:12:29 +0000'); + } + + function it_throws_an_exception_if_cookie_date_string_is_unparseable_1() + { + $this->beConstructedThrough('parseDate', ['Flursday July 31st 2020, 08:49:37 GMT']); $this->shouldThrow('Http\Message\Exception\UnexpectedValueException'); } - /** - * Provides examples for valid cookie date string. - * - * @return array - */ - public function getCookieStrings() - { - return [ - ['Friday, 31 Jul 20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], - ['Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], - ['Fri, 31-Jul-2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], - ['Fri, 31 Jul 2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], - ['Fri, 31-07-2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], - ['Fri, 31-07-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], - ['Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], - ['Fri Jul 31 08:49:37 2020', 'Friday, 31-Jul-2020 08:49:37 +0000'], - ['Friday July 31st 2020, 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'], - // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 - ['Wed, 09 Jun 2021 10:18:14 GMT', 'Wednesday, 09-Jun-2021 10:18:14 +0000'], - ['Wed, 09 Jun 2021 22:18:14 GMT', 'Wednesday, 09-Jun-2021 22:18:14 +0000'], - ['Tue, 18 Oct 2011 07:42:42.123 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'], - ['18 Oct 2011 07:42:42 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'], - ['8 Oct 2011 7:42:42 GMT', 'Saturday, 08-Oct-2011 07:42:42 +0000'], - ['8 Oct 2011 7:2:42 GMT', 'Saturday, 08-Oct-2011 07:02:42 +0000'], - ['Oct 18 2011 07:42:42 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'], - ['Tue Oct 18 2011 07:05:03 GMT+0000 (GMT)', 'Tuesday, 18-Oct-2011 07:05:03 +0000'], - ['09 Jun 2021 10:18:14 GMT', 'Wednesday, 09-Jun-2021 10:18:14 +0000'], - ['01 Jan 1970 00:00:00 GMT', 'Thursday, 01-Jan-1970 00:00:00 +0000'], - ['01 Jan 1601 00:00:00 GMT', 'Monday, 01-Jan-1601 00:00:00 +0000'], - ['10 Feb 81 13:00:00 GMT', 'Tuesday, 10-Feb-1981 13:00:00 +0000'], // implicit year - ['Thu, 17-Apr-2014 02:12:29 GMT', 'Thursday, 17-Apr-2014 02:12:29 +0000'], // dashes - ['Thu, 17-Apr-2014 02:12:29 UTC', 'Thursday, 17-Apr-2014 02:12:29 +0000'], // dashes and UTC - ]; - } - - /** - * Provides examples for invalid cookie date string. - * - * @return array - */ - public function getInvalidCookieDateStrings() - { - return [ - ['Flursday July 31st 2020, 08:49:37 GMT'], - ['99 Jix 3038 48:86:72 ZMT'], - ]; + function it_throws_an_exception_if_cookie_date_string_is_unparseable_2() + { + $this->beConstructedThrough('parseDate', ['99 Jix 3038 48:86:72 ZMT']); + $this->shouldThrow('Http\Message\Exception\UnexpectedValueException'); + } + + private function testCookieParse(string $input, string $output) + { + $this->beConstructedThrough('parseDate', [$input]); + $this->shouldHaveType('\DateTime'); + $this->format('l, d-M-Y H:i:s O')->shouldReturn($output); } } diff --git a/spec/Decorator/MessageDecoratorSpec.php b/spec/Decorator/MessageDecoratorSpec.php index 53f79ec..e9d0fe9 100644 --- a/spec/Decorator/MessageDecoratorSpec.php +++ b/spec/Decorator/MessageDecoratorSpec.php @@ -121,7 +121,7 @@ function it_accepts_a_body(MessageInterface $message, MessageInterface $newMessa $new->getMessage()->shouldReturn($newMessage); } - function getMatchers() + function getMatchers(): array { return [ 'useTrait' => function ($subject, $trait) { diff --git a/spec/Decorator/RequestDecoratorSpec.php b/spec/Decorator/RequestDecoratorSpec.php index 776cb94..efe4648 100644 --- a/spec/Decorator/RequestDecoratorSpec.php +++ b/spec/Decorator/RequestDecoratorSpec.php @@ -87,7 +87,7 @@ function it_accepts_an_uri(RequestInterface $request, RequestInterface $newReque $new->getMessage()->shouldReturn($newRequest); } - function getMatchers() + function getMatchers(): array { return [ 'useTrait' => function ($subject, $trait) { diff --git a/spec/Decorator/ResponseDecoratorSpec.php b/spec/Decorator/ResponseDecoratorSpec.php index 7fdd61c..587a86a 100644 --- a/spec/Decorator/ResponseDecoratorSpec.php +++ b/spec/Decorator/ResponseDecoratorSpec.php @@ -63,7 +63,7 @@ function it_has_a_reason_phrase(ResponseInterface $response) $this->getReasonPhrase()->shouldReturn('OK'); } - function getMatchers() + function getMatchers(): array { return [ 'useTrait' => function ($subject, $trait) { diff --git a/spec/Decorator/StreamDecoratorSpec.php b/spec/Decorator/StreamDecoratorSpec.php index 055e385..7dbcaf5 100644 --- a/spec/Decorator/StreamDecoratorSpec.php +++ b/spec/Decorator/StreamDecoratorSpec.php @@ -133,7 +133,7 @@ function it_returns_metadata_of_the_stream(StreamInterface $stream) $this->getMetadata('key2')->shouldReturn(null); } - function getMatchers() + function getMatchers(): array { return [ 'useTrait' => function ($subject, $trait) { diff --git a/spec/Encoding/ChunkStreamSpec.php b/spec/Encoding/ChunkStreamSpec.php index 68a078e..35b68a7 100644 --- a/spec/Encoding/ChunkStreamSpec.php +++ b/spec/Encoding/ChunkStreamSpec.php @@ -3,7 +3,6 @@ namespace spec\Http\Message\Encoding; use Psr\Http\Message\StreamInterface; -use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; class ChunkStreamSpec extends ObjectBehavior diff --git a/spec/Encoding/CompressStreamSpec.php b/spec/Encoding/CompressStreamSpec.php index 04efda6..ad58b1f 100644 --- a/spec/Encoding/CompressStreamSpec.php +++ b/spec/Encoding/CompressStreamSpec.php @@ -3,7 +3,6 @@ namespace spec\Http\Message\Encoding; use Psr\Http\Message\StreamInterface; -use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; class CompressStreamSpec extends ObjectBehavior diff --git a/spec/Encoding/DechunkStreamSpec.php b/spec/Encoding/DechunkStreamSpec.php index 3616d1b..2ef2aa2 100644 --- a/spec/Encoding/DechunkStreamSpec.php +++ b/spec/Encoding/DechunkStreamSpec.php @@ -3,7 +3,6 @@ namespace spec\Http\Message\Encoding; use Psr\Http\Message\StreamInterface; -use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; class DechunkStreamSpec extends ObjectBehavior diff --git a/spec/Encoding/DecompressStreamSpec.php b/spec/Encoding/DecompressStreamSpec.php index baafad0..78a5923 100644 --- a/spec/Encoding/DecompressStreamSpec.php +++ b/spec/Encoding/DecompressStreamSpec.php @@ -3,7 +3,6 @@ namespace spec\Http\Message\Encoding; use Psr\Http\Message\StreamInterface; -use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; class DecompressStreamSpec extends ObjectBehavior diff --git a/spec/Encoding/FilteredStreamStubSpec.php b/spec/Encoding/FilteredStreamStubSpec.php index 6e6692e..7e3f3f6 100644 --- a/spec/Encoding/FilteredStreamStubSpec.php +++ b/spec/Encoding/FilteredStreamStubSpec.php @@ -12,14 +12,22 @@ function it_throws_during_instantiation_with_invalid_read_filter_options(StreamI { $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); $this->beConstructedWith($stream, 'foo'); - $this->shouldThrow('RuntimeException')->duringInstantiation(); + if (\PHP_MAJOR_VERSION < 8) { + $this->shouldThrow('RuntimeException')->duringInstantiation(); + } else { + $this->shouldThrow('PhpSpec\Exception\Example\ErrorException')->duringInstantiation(); + } } function it_throws_during_instantiation_with_invalid_write_filter_options(StreamInterface $stream) { $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); $this->beConstructedWith($stream, null, 'foo'); - $this->shouldThrow('RuntimeException')->duringInstantiation(); + if (\PHP_MAJOR_VERSION < 8) { + $this->shouldThrow('RuntimeException')->duringInstantiation(); + } else { + $this->shouldThrow('PhpSpec\Exception\Example\ErrorException')->duringInstantiation(); + } } function let(StreamInterface $stream) diff --git a/spec/Encoding/GzipDecodeStreamSpec.php b/spec/Encoding/GzipDecodeStreamSpec.php index 17b8dea..e2bbee2 100644 --- a/spec/Encoding/GzipDecodeStreamSpec.php +++ b/spec/Encoding/GzipDecodeStreamSpec.php @@ -3,7 +3,6 @@ namespace spec\Http\Message\Encoding; use Psr\Http\Message\StreamInterface; -use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; class GzipDecodeStreamSpec extends ObjectBehavior diff --git a/spec/Encoding/GzipEncodeStreamSpec.php b/spec/Encoding/GzipEncodeStreamSpec.php index 2037be5..e750606 100644 --- a/spec/Encoding/GzipEncodeStreamSpec.php +++ b/spec/Encoding/GzipEncodeStreamSpec.php @@ -3,7 +3,6 @@ namespace spec\Http\Message\Encoding; use Psr\Http\Message\StreamInterface; -use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; class GzipEncodeStreamSpec extends ObjectBehavior diff --git a/spec/Encoding/ZlibStreamBehavior.php b/spec/Encoding/ZlibStreamBehavior.php index bcd8311..6f1d298 100644 --- a/spec/Encoding/ZlibStreamBehavior.php +++ b/spec/Encoding/ZlibStreamBehavior.php @@ -2,9 +2,6 @@ namespace spec\Http\Message\Encoding { - use Psr\Http\Message\StreamInterface; - use PhpSpec\Exception\Example\SkippingException; - trait ZlibStreamBehavior { function it_throws_an_exception_when_zlib_is_not_enabled() diff --git a/spec/StreamFactory/StreamFactoryBehavior.php b/spec/StreamFactory/StreamFactoryBehavior.php index f78a1c6..05447d8 100644 --- a/spec/StreamFactory/StreamFactoryBehavior.php +++ b/spec/StreamFactory/StreamFactoryBehavior.php @@ -56,7 +56,7 @@ function it_does_not_rewind_existing_resource() ->shouldHaveContent('def'); } - public function getMatchers() + public function getMatchers(): array { return [ 'haveContent' => function (StreamInterface $subject, $key) { From 39db36d5972e9e6d00ea852b650953f928d8f10d Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 11 Nov 2020 10:19:56 +0000 Subject: [PATCH 088/132] Release 1.10.0 (#135) * Bump branch alias * Update CHANGELOG.md * Fixed date * Fixed links --- CHANGELOG.md | 10 +++++++++- composer.json | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c31778..bcd66d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.10.0] - 2020-11-11 + +- Added support for PHP 8.0. + ## [1.9.1] - 2020-10-13 - Improved detection of binary stream to not consider newlines, carriage return or tabs as binary. @@ -198,7 +202,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Message factory (Guzzle, Diactoros) -[Unreleased]: https://github.com/php-http/message/compare/1.7.2...HEAD +[Unreleased]: https://github.com/php-http/message/compare/1.10.0...HEAD +[1.10.0]: https://github.com/php-http/message/compare/1.9.1...1.10.0 +[1.9.1]: https://github.com/php-http/message/compare/1.9.0...1.9.1 +[1.9.0]: https://github.com/php-http/message/compare/1.8.0...1.9.0 +[1.8.0]: https://github.com/php-http/message/compare/1.7.2...1.8.0 [1.7.2]: https://github.com/php-http/message/compare/v1.7.1...1.7.2 [1.7.1]: https://github.com/php-http/message/compare/1.7.0...v1.7.1 [1.7.0]: https://github.com/php-http/message/compare/1.6.0...1.7.0 diff --git a/composer.json b/composer.json index 9a60d8f..ef50ea3 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.10-dev" } }, "autoload": { From 6e2c5745fc47cfd7365ed3c0b132d31df19dff62 Mon Sep 17 00:00:00 2001 From: Dennis Riehle Date: Thu, 3 Dec 2020 08:28:50 +0100 Subject: [PATCH 089/132] migrated to laminas/laminas-diactoros (#125) (#134) --- CHANGELOG.md | 11 ++++++++ composer.json | 6 ++--- .../DiactorosStreamFactorySpec.php | 2 +- .../DiactorosMessageFactory.php | 27 ++++++++++++++++--- src/StreamFactory/DiactorosStreamFactory.php | 16 ++++++++--- src/UriFactory/DiactorosUriFactory.php | 9 +++++-- 6 files changed, 58 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd66d6..0bbcd06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] + +- Migrated from `zendframework/zend-diactoros` to `laminas/laminas-diactoros`. + Users are encouraged to update their dependencies by simply replacing the Zend package with the Laminas package. + Due to the [laminas-zendframework-brige](https://github.com/laminas/laminas-zendframework-bridge), BC changes + are not expected and legacy code does not need to be refactored (though it is + [recommended and simple](https://docs.laminas.dev/migration/)). +- The diactoros factories of `php-http/message` will return objects from the `Laminas\Diactoros\` namespace, if + the respective classes are available via autoloading, but continue to return objects from `Zend\Diactoros\` + namespace otherwise. + ## [1.10.0] - 2020-11-11 - Added support for PHP 8.0. diff --git a/composer.json b/composer.json index ef50ea3..fc67cd0 100644 --- a/composer.json +++ b/composer.json @@ -29,13 +29,13 @@ "guzzlehttp/psr7": "^1.0", "phpspec/phpspec": "^5.1 || ^6.3", "slim/slim": "^3.0", - "zendframework/zend-diactoros": "^1.0" + "laminas/laminas-diactoros": "^2.0" }, "suggest": { "ext-zlib": "Used with compressor/decompressor streams", "guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories", - "slim/slim": "Used with Slim Framework PSR-7 implementation", - "zendframework/zend-diactoros": "Used with Diactoros Factories" + "laminas/laminas-diactoros": "Used with Diactoros Factories", + "slim/slim": "Used with Slim Framework PSR-7 implementation" }, "config": { "sort-packages": true diff --git a/spec/StreamFactory/DiactorosStreamFactorySpec.php b/spec/StreamFactory/DiactorosStreamFactorySpec.php index 372ef1b..dbf6927 100644 --- a/spec/StreamFactory/DiactorosStreamFactorySpec.php +++ b/spec/StreamFactory/DiactorosStreamFactorySpec.php @@ -2,7 +2,7 @@ namespace spec\Http\Message\StreamFactory; -use Zend\Diactoros\Stream; +use Laminas\Diactoros\Stream; use PhpSpec\ObjectBehavior; class DiactorosStreamFactorySpec extends ObjectBehavior diff --git a/src/MessageFactory/DiactorosMessageFactory.php b/src/MessageFactory/DiactorosMessageFactory.php index 94b9ad2..6d54d35 100644 --- a/src/MessageFactory/DiactorosMessageFactory.php +++ b/src/MessageFactory/DiactorosMessageFactory.php @@ -4,8 +4,10 @@ use Http\Message\MessageFactory; use Http\Message\StreamFactory\DiactorosStreamFactory; -use Zend\Diactoros\Request; -use Zend\Diactoros\Response; +use Laminas\Diactoros\Request as LaminasRequest; +use Laminas\Diactoros\Response as LaminasResponse; +use Zend\Diactoros\Request as ZendRequest; +use Zend\Diactoros\Response as ZendResponse; /** * Creates Diactoros messages. @@ -36,7 +38,16 @@ public function createRequest( $body = null, $protocolVersion = '1.1' ) { - return (new Request( + if (class_exists(LaminasRequest::class)) { + return (new LaminasRequest( + $uri, + $method, + $this->streamFactory->createStream($body), + $headers + ))->withProtocolVersion($protocolVersion); + } + + return (new ZendRequest( $uri, $method, $this->streamFactory->createStream($body), @@ -54,7 +65,15 @@ public function createResponse( $body = null, $protocolVersion = '1.1' ) { - return (new Response( + if (class_exists(LaminasResponse::class)) { + return (new LaminasResponse( + $this->streamFactory->createStream($body), + $statusCode, + $headers + ))->withProtocolVersion($protocolVersion); + } + + return (new ZendResponse( $this->streamFactory->createStream($body), $statusCode, $headers diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index 95bf0ca..8ae2b28 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -3,8 +3,9 @@ namespace Http\Message\StreamFactory; use Http\Message\StreamFactory; +use Laminas\Diactoros\Stream as LaminasStream; use Psr\Http\Message\StreamInterface; -use Zend\Diactoros\Stream; +use Zend\Diactoros\Stream as ZendStream; /** * Creates Diactoros streams. @@ -25,10 +26,19 @@ public function createStream($body = null) } if (is_resource($body)) { - return new Stream($body); + if (class_exists(LaminasStream::class)) { + return new LaminasStream($body); + } + + return new ZendStream($body); + } + + if (class_exists(LaminasStream::class)) { + $stream = new LaminasStream('php://memory', 'rw'); + } else { + $stream = new ZendStream('php://memory', 'rw'); } - $stream = new Stream('php://memory', 'rw'); if (null !== $body && '' !== $body) { $stream->write((string) $body); } diff --git a/src/UriFactory/DiactorosUriFactory.php b/src/UriFactory/DiactorosUriFactory.php index f3b73d0..be883de 100644 --- a/src/UriFactory/DiactorosUriFactory.php +++ b/src/UriFactory/DiactorosUriFactory.php @@ -3,8 +3,9 @@ namespace Http\Message\UriFactory; use Http\Message\UriFactory; +use Laminas\Diactoros\Uri as LaminasUri; use Psr\Http\Message\UriInterface; -use Zend\Diactoros\Uri; +use Zend\Diactoros\Uri as ZendUri; /** * Creates Diactoros URI. @@ -23,7 +24,11 @@ public function createUri($uri) if ($uri instanceof UriInterface) { return $uri; } elseif (is_string($uri)) { - return new Uri($uri); + if (class_exists(LaminasUri::class)) { + return new LaminasUri($uri); + } + + return new ZendUri($uri); } throw new \InvalidArgumentException('URI must be a string or UriInterface'); From 613250d3d94648b81a3355a1aa404c88d098c02e Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 16 Dec 2020 08:40:50 +0100 Subject: [PATCH 090/132] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52abe2b..7d778f7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # HTTP Message [![Latest Version](https://img.shields.io/github/release/php-http/message.svg?style=flat-square)](https://github.com/php-http/message/releases) -![GitHub Workflow Status](https://img.shields.io/github/workflow/status/php-http/message/CI?style=flat-square) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/php-http/message/CI?style=flat-square)](https://github.com/php-http/message/actions?query=workflow%3ACI+branch%3Amaster) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/message.svg?style=flat-square)](https://packagist.org/packages/php-http/message) **HTTP Message related tools.** From d23ac28dd2787fb4786d7da5cd6df1ff28859e74 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 16 Dec 2020 08:47:34 +0100 Subject: [PATCH 091/132] add license badge to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7d778f7..df1a7d5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # HTTP Message [![Latest Version](https://img.shields.io/github/release/php-http/message.svg?style=flat-square)](https://github.com/php-http/message/releases) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/php-http/message/CI?style=flat-square)](https://github.com/php-http/message/actions?query=workflow%3ACI+branch%3Amaster) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/message.svg?style=flat-square)](https://packagist.org/packages/php-http/message) From c6f875f769f4c62fa2df71f9e6275e641024366c Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 24 Jan 2021 10:51:22 +0100 Subject: [PATCH 092/132] final class has no use for protected property or method, make them private --- src/CookieJar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CookieJar.php b/src/CookieJar.php index 6d60ec2..1a3f5e4 100644 --- a/src/CookieJar.php +++ b/src/CookieJar.php @@ -12,7 +12,7 @@ final class CookieJar implements \Countable, \IteratorAggregate /** * @var \SplObjectStorage */ - protected $cookies; + private $cookies; public function __construct() { @@ -92,7 +92,7 @@ public function getMatchingCookies(Cookie $cookie) * * @return Cookie[] */ - protected function findMatchingCookies(callable $match) + private function findMatchingCookies(callable $match) { $cookies = []; From 659f8760e3deba6c453ba99c33e4e79338f54ced Mon Sep 17 00:00:00 2001 From: "Chun-Sheng, Li" Date: Mon, 1 Feb 2021 16:48:42 +0800 Subject: [PATCH 093/132] Allow to specify hashing algorithm for WSSE --- CHANGELOG.md | 4 ++++ src/Authentication/Wsse.php | 16 +++++++++++++--- src/CookieJar.php | 2 +- src/Encoding/FilteredStream.php | 3 +-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bbcd06..4cc009a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. the respective classes are available via autoloading, but continue to return objects from `Zend\Diactoros\` namespace otherwise. +## [1.11.0] - unreleased + +- Allow to specify the hashing algorithm for WSSE authentication. + ## [1.10.0] - 2020-11-11 - Added support for PHP 8.0. diff --git a/src/Authentication/Wsse.php b/src/Authentication/Wsse.php index fbbde33..f343633 100644 --- a/src/Authentication/Wsse.php +++ b/src/Authentication/Wsse.php @@ -3,6 +3,7 @@ namespace Http\Message\Authentication; use Http\Message\Authentication; +use InvalidArgumentException; use Psr\Http\Message\RequestInterface; /** @@ -22,14 +23,24 @@ final class Wsse implements Authentication */ private $password; + /** + * @var string + */ + private $hashAlgorithm; + /** * @param string $username * @param string $password + * @param string $hashAlgorithm To use a better hashing algorithm than the weak sha1, pass the algorithm to use, e.g. "sha512" */ - public function __construct($username, $password) + public function __construct($username, $password, $hashAlgorithm = 'sha1') { $this->username = $username; $this->password = $password; + if (false === in_array($hashAlgorithm, hash_algos())) { + throw new InvalidArgumentException(sprintf('Unaccepted hashing algorithm: %s', $hashAlgorithm)); + } + $this->hashAlgorithm = $hashAlgorithm; } /** @@ -37,10 +48,9 @@ public function __construct($username, $password) */ public function authenticate(RequestInterface $request) { - // TODO: generate better nonce? $nonce = substr(md5(uniqid(uniqid().'_', true)), 0, 16); $created = date('c'); - $digest = base64_encode(sha1(base64_decode($nonce).$created.$this->password, true)); + $digest = base64_encode(hash($this->hashAlgorithm, base64_decode($nonce).$created.$this->password, true)); $wsse = sprintf( 'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', diff --git a/src/CookieJar.php b/src/CookieJar.php index 1a3f5e4..1479cc6 100644 --- a/src/CookieJar.php +++ b/src/CookieJar.php @@ -10,7 +10,7 @@ final class CookieJar implements \Countable, \IteratorAggregate { /** - * @var \SplObjectStorage + * @var \SplObjectStorage */ private $cookies; diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index 65f40de..a937c82 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -13,12 +13,11 @@ */ abstract class FilteredStream implements StreamInterface { - const BUFFER_SIZE = 8192; - use StreamDecorator { rewind as private doRewind; seek as private doSeek; } + const BUFFER_SIZE = 8192; /** * @var callable From fb0dbce7355cad4f4f6a225f537c34d013571f29 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 1 Feb 2021 09:54:58 +0100 Subject: [PATCH 094/132] prepare release --- CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cc009a..b36da2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [1.11.0] - 2020-02-01 - Migrated from `zendframework/zend-diactoros` to `laminas/laminas-diactoros`. Users are encouraged to update their dependencies by simply replacing the Zend package with the Laminas package. @@ -17,8 +17,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. the respective classes are available via autoloading, but continue to return objects from `Zend\Diactoros\` namespace otherwise. -## [1.11.0] - unreleased - - Allow to specify the hashing algorithm for WSSE authentication. ## [1.10.0] - 2020-11-11 From 9b8d8f7179ba76e19c13737af5974f3b84915953 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 24 May 2021 16:20:12 +0200 Subject: [PATCH 095/132] support guzzle psr7 version 2 --- CHANGELOG.md | 4 ++++ src/UriFactory/GuzzleUriFactory.php | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b36da2d..2c580bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.11.1] - 2021-05-24 + +- Support GuzzleHttp/Psr7 version 2.0 in the (deprecated) GuzzleUriFactory. + ## [1.11.0] - 2020-02-01 - Migrated from `zendframework/zend-diactoros` to `laminas/laminas-diactoros`. diff --git a/src/UriFactory/GuzzleUriFactory.php b/src/UriFactory/GuzzleUriFactory.php index b16ca52..e09ac61 100644 --- a/src/UriFactory/GuzzleUriFactory.php +++ b/src/UriFactory/GuzzleUriFactory.php @@ -2,7 +2,8 @@ namespace Http\Message\UriFactory; -use GuzzleHttp\Psr7; +use function GuzzleHttp\Psr7\uri_for; +use GuzzleHttp\Psr7\Utils; use Http\Message\UriFactory; /** @@ -19,6 +20,10 @@ final class GuzzleUriFactory implements UriFactory */ public function createUri($uri) { - return Psr7\uri_for($uri); + if (class_exists(Utils::class)) { + return Utils::uriFor($uri); + } + + return uri_for($uri); } } From 11dd897486dcbff8e4634e27fe929a2d64d38498 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 24 May 2021 16:35:30 +0200 Subject: [PATCH 096/132] fix code rot in ci setup --- .github/workflows/static.yml | 2 +- phpstan-baseline.neon | 27 +++++++++++---------------- src/Authentication/QueryParam.php | 2 +- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index b2f69cf..6530f18 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -31,6 +31,6 @@ jobs: uses: actions/checkout@v2 - name: PHP-CS-Fixer - uses: docker://oskarstark/php-cs-fixer-ga + uses: docker://oskarstark/php-cs-fixer-ga:2.19.0 with: args: --dry-run --diff-format udiff diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 9c95e48..40013ca 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11,17 +11,17 @@ parameters: path: src/Authentication/Header.php - - message: "#^Property Http\\\\Message\\\\Authentication\\\\QueryParam\\:\\:\\$params type has no value type specified in iterable type array\\.$#" + message: "#The Http\\\\Message\\\\Authentication\\\\Matching class is deprecated since version 1.2 and will be removed in 2.0.#" count: 1 - path: src/Authentication/QueryParam.php + path: src/Authentication/Matching.php - - message: "#^Method Http\\\\Message\\\\Authentication\\\\QueryParam\\:\\:__construct\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#" + message: "#^Property Http\\\\Message\\\\Authentication\\\\QueryParam\\:\\:\\$params type has no value type specified in iterable type array\\.$#" count: 1 path: src/Authentication/QueryParam.php - - message: "#^Parameter \\#2 \\$prefix of function http_build_query expects string, null given\\.$#" + message: "#^Method Http\\\\Message\\\\Authentication\\\\QueryParam\\:\\:__construct\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#" count: 1 path: src/Authentication/QueryParam.php @@ -46,7 +46,7 @@ parameters: path: src/Cookie.php - - message: "#^Parameter \\#2 \\$str2 of function strcasecmp expects string, string\\|null given\\.$#" + message: "#^Parameter \\#2 \\$string2 of function strcasecmp expects string, string\\|null given\\.$#" count: 1 path: src/Cookie.php @@ -76,7 +76,7 @@ parameters: path: src/Cookie.php - - message: "#^Parameter \\#1 \\$str of function rtrim expects string, string\\|null given\\.$#" + message: "#^Parameter \\#1 \\$string of function rtrim expects string, string\\|null given\\.$#" count: 1 path: src/Cookie.php @@ -160,16 +160,6 @@ parameters: count: 2 path: src/Encoding/Filter/Chunk.php - - - message: "#^Parameter \\#2 \\$bucket of function stream_bucket_append expects object, resource given\\.$#" - count: 2 - path: src/Encoding/Filter/Chunk.php - - - - message: "#^Unreachable statement \\- code above always terminates\\.$#" - count: 1 - path: src/Encoding/Filter/Chunk.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" count: 1 @@ -215,6 +205,11 @@ parameters: count: 1 path: src/MessageFactory/SlimMessageFactory.php + - + message: "#The Http\\\\Message\\\\RequestMatcher\\\\RegexRequestMatcher class is deprecated since version 1.2 and will be removed in 2.0.#" + count: 1 + path: src/RequestMatcher/RegexRequestMatcher.php + - message: "#^Property Http\\\\Message\\\\RequestMatcher\\\\RequestMatcher\\:\\:\\$methods type has no value type specified in iterable type array\\.$#" count: 1 diff --git a/src/Authentication/QueryParam.php b/src/Authentication/QueryParam.php index 7f95d44..243efef 100644 --- a/src/Authentication/QueryParam.php +++ b/src/Authentication/QueryParam.php @@ -38,7 +38,7 @@ public function authenticate(RequestInterface $request) $params = array_merge($params, $this->params); - $query = http_build_query($params, null, '&'); + $query = http_build_query($params, '', '&'); $uri = $uri->withQuery($query); From 295c82867d07261f2fa4b3a26677519fc6f7f5f6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 3 Aug 2021 13:52:11 +0200 Subject: [PATCH 097/132] GuzzleStreamFactory: support guzzle/psr7 version 2 (#141) --- CHANGELOG.md | 4 ++++ src/StreamFactory/GuzzleStreamFactory.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c580bd..0ab29dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.11.2] - 2021-08-03 + +- Support GuzzleHttp/Psr7 version 2.0 in the (deprecated) GuzzleStreamFactory. + ## [1.11.1] - 2021-05-24 - Support GuzzleHttp/Psr7 version 2.0 in the (deprecated) GuzzleUriFactory. diff --git a/src/StreamFactory/GuzzleStreamFactory.php b/src/StreamFactory/GuzzleStreamFactory.php index 9adeeb5..14d83e9 100644 --- a/src/StreamFactory/GuzzleStreamFactory.php +++ b/src/StreamFactory/GuzzleStreamFactory.php @@ -2,6 +2,7 @@ namespace Http\Message\StreamFactory; +use GuzzleHttp\Psr7\Utils; use Http\Message\StreamFactory; /** @@ -18,6 +19,10 @@ final class GuzzleStreamFactory implements StreamFactory */ public function createStream($body = null) { + if (class_exists(Utils::class)) { + return Utils::streamFor($body); + } + return \GuzzleHttp\Psr7\stream_for($body); } } From cf70baeb1ccc9d97b1f8de088d548f2e622cfc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Sat, 28 Aug 2021 11:37:59 +0200 Subject: [PATCH 098/132] Add support for adjusting binary detection regex in FullHttpMessageFormatter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regrettably, in our applications, php serialize() is often used instead of JSON as a serialization format used over wire. Instead of changing ∂efault regex for everyone (which could be a security risk in case target endpoint is untrusted), this allows to inject custom regex. --- CHANGELOG.md | 4 ++++ .../FullHttpMessageFormatterSpec.php | 21 +++++++++++++++++++ src/Formatter/FullHttpMessageFormatter.php | 12 ++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ab29dd..de4af69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.12.0] - ? + +- Added support for adjusting binary detection regex in FullHttpMessageFormatter + ## [1.11.2] - 2021-08-03 - Support GuzzleHttp/Psr7 version 2.0 in the (deprecated) GuzzleStreamFactory. diff --git a/spec/Formatter/FullHttpMessageFormatterSpec.php b/spec/Formatter/FullHttpMessageFormatterSpec.php index 5d2e6bf..e89b7f2 100644 --- a/spec/Formatter/FullHttpMessageFormatterSpec.php +++ b/spec/Formatter/FullHttpMessageFormatterSpec.php @@ -249,6 +249,27 @@ function it_omits_body_with_null_bytes(RequestInterface $request, StreamInterfac $this->formatRequest($request)->shouldReturn($expectedMessage); } + function it_allows_to_change_binary_detection(RequestInterface $request, StreamInterface $stream) + { + $this->beConstructedWith(1, '/\x01/'); + + $stream->isSeekable()->willReturn(true); + $stream->rewind()->shouldBeCalled(); + $stream->__toString()->willReturn("\0"); + $request->getBody()->willReturn($stream); + $request->getMethod()->willReturn('GET'); + $request->getRequestTarget()->willReturn('/foo'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([]); + + $expectedMessage = <<formatRequest($request)->shouldReturn($expectedMessage); + } + function it_omits_body_with_line_break(RequestInterface $request, StreamInterface $stream) { $this->beConstructedWith(7); diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index 64ce3ce..bb22efe 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -21,12 +21,19 @@ class FullHttpMessageFormatter implements Formatter */ private $maxBodyLength; + /** + * @var string + */ + private $binaryDetectionRegex; + /** * @param int|null $maxBodyLength + * @param string $binaryDetectionRegex By default, this is all non-printable ASCII characters and except for \t, \r, \n */ - public function __construct($maxBodyLength = 1000) + public function __construct($maxBodyLength = 1000, string $binaryDetectionRegex = '/([\x00-\x09\x0C\x0E-\x1F\x7F])/') { $this->maxBodyLength = $maxBodyLength; + $this->binaryDetectionRegex = $binaryDetectionRegex; } /** @@ -86,8 +93,7 @@ private function addBody(MessageInterface $request, $message) $data = $stream->__toString(); $stream->rewind(); - // all non-printable ASCII characters and except for \t, \r, \n - if (preg_match('/([\x00-\x09\x0C\x0E-\x1F\x7F])/', $data)) { + if (preg_match($this->binaryDetectionRegex, $data)) { return $message.'[binary stream omitted]'; } From 39eb7548be982a81085fe5a6e2a44268cd586291 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 29 Aug 2021 11:13:12 +0200 Subject: [PATCH 099/132] prepare release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de4af69..d3eb840 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [1.12.0] - ? +## [1.12.0] - 2021-08-29 - Added support for adjusting binary detection regex in FullHttpMessageFormatter From 2ccf2c58c6dbc018cbd4214dd12269d9acaa4e73 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 18 Oct 2021 07:56:42 +0100 Subject: [PATCH 100/132] Test on PHP 8.1 (#143) --- .github/workflows/ci.yml | 8 +++++++- composer.json | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08a1fbb..f6c6c16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.1', '7.2', '7.3', '7.4', '8.0'] + php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] steps: - name: Checkout code @@ -23,6 +23,12 @@ jobs: tools: composer coverage: none + - name: Require PHPSpec 7.1 dependencies + run: | + composer require "phpspec/phpspec:^7.1@dev" --no-interaction --no-update + composer update --prefer-dist --no-interaction --no-progress --ignore-platform-req=php + if: "matrix.php == '8.1'" + - name: Install dependencies run: composer update --prefer-dist --no-interaction --no-progress diff --git a/composer.json b/composer.json index fc67cd0..5d24bcd 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "ext-zlib": "*", "ergebnis/composer-normalize": "^2.6", "guzzlehttp/psr7": "^1.0", - "phpspec/phpspec": "^5.1 || ^6.3", + "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", "slim/slim": "^3.0", "laminas/laminas-diactoros": "^2.0" }, From d8224f1ba67e3fb31288cc4d3379e48a8183614d Mon Sep 17 00:00:00 2001 From: "Roland Franssen :)" Date: Mon, 7 Feb 2022 19:36:34 +0100 Subject: [PATCH 101/132] formatResponseForRequest --- CHANGELOG.md | 4 ++++ spec/Formatter/CurlCommandFormatterSpec.php | 3 ++- spec/Formatter/FullHttpMessageFormatterSpec.php | 3 ++- spec/Formatter/SimpleFormatterSpec.php | 3 ++- src/Formatter.php | 2 ++ src/Formatter/CurlCommandFormatter.php | 8 ++++++++ src/Formatter/FullHttpMessageFormatter.php | 8 ++++++++ src/Formatter/SimpleFormatter.php | 8 ++++++++ 8 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3eb840..7e3fa59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.13.0] - tomorrow + +- Added `Formatter::formatResponseForRequest()` + ## [1.12.0] - 2021-08-29 - Added support for adjusting binary detection regex in FullHttpMessageFormatter diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php index f847a6b..0ee2b98 100644 --- a/spec/Formatter/CurlCommandFormatterSpec.php +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -54,9 +54,10 @@ function it_formats_post_request(RequestInterface $request, UriInterface $uri, S $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --http2 --request POST --data 'body \" data test'\'' bar'"); } - function it_does_nothing_for_response(ResponseInterface $response) + function it_does_nothing_for_response(ResponseInterface $response, RequestInterface $request) { $this->formatResponse($response)->shouldReturn(''); + $this->formatResponseForRequest($response, $request)->shouldReturn(''); } function it_formats_the_request_with_user_agent(RequestInterface $request, UriInterface $uri, StreamInterface $body) diff --git a/spec/Formatter/FullHttpMessageFormatterSpec.php b/spec/Formatter/FullHttpMessageFormatterSpec.php index e89b7f2..33f83f6 100644 --- a/spec/Formatter/FullHttpMessageFormatterSpec.php +++ b/spec/Formatter/FullHttpMessageFormatterSpec.php @@ -126,7 +126,7 @@ function it_does_not_format_no_seekable_request(RequestInterface $request, Strea $this->formatRequest($request)->shouldReturn($expectedMessage); } - function it_formats_the_response_with_size_limit(ResponseInterface $response, StreamInterface $stream) + function it_formats_the_response_with_size_limit(ResponseInterface $response, StreamInterface $stream, RequestInterface $request) { $this->beConstructedWith(18); @@ -150,6 +150,7 @@ function it_formats_the_response_with_size_limit(ResponseInterface $response, St This is an HTML st STR; $this->formatResponse($response)->shouldReturn($expectedMessage); + $this->formatResponseForRequest($response, $request)->shouldReturn($expectedMessage); } function it_formats_the_response_without_size_limit(ResponseInterface $response, StreamInterface $stream) diff --git a/spec/Formatter/SimpleFormatterSpec.php b/spec/Formatter/SimpleFormatterSpec.php index ef70eb8..9c44d67 100644 --- a/spec/Formatter/SimpleFormatterSpec.php +++ b/spec/Formatter/SimpleFormatterSpec.php @@ -29,12 +29,13 @@ function it_formats_the_request(RequestInterface $request, UriInterface $uri) $this->formatRequest($request)->shouldReturn('GET http://foo.com/bar 1.1'); } - function it_formats_the_response(ResponseInterface $response) + function it_formats_the_response(ResponseInterface $response, RequestInterface $request) { $response->getReasonPhrase()->willReturn('OK'); $response->getProtocolVersion()->willReturn('1.1'); $response->getStatusCode()->willReturn('200'); $this->formatResponse($response)->shouldReturn('200 OK 1.1'); + $this->formatResponseForRequest($response, $request)->shouldReturn('200 OK 1.1'); } } diff --git a/src/Formatter.php b/src/Formatter.php index d6cd21b..5c2d1aa 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -9,6 +9,8 @@ * Formats a request and/or a response as a string. * * @author Márk Sági-Kazár + * + * @method string formatResponseForRequest(ResponseInterface $response, RequestInterface $request) Formats a response in context of its request. */ interface Formatter { diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 78b1d55..31f5e7b 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -68,6 +68,14 @@ public function formatResponse(ResponseInterface $response) return ''; } + /** + * {@inheritdoc} + */ + public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request) + { + return $this->formatResponse($response); + } + /** * @return string */ diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index bb22efe..451f667 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -74,6 +74,14 @@ public function formatResponse(ResponseInterface $response) return $this->addBody($response, $message); } + /** + * {@inheritdoc} + */ + public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request) + { + return $this->formatResponse($response); + } + /** * Add the message body if the stream is seekable. * diff --git a/src/Formatter/SimpleFormatter.php b/src/Formatter/SimpleFormatter.php index b1fcabd..cfdfef9 100644 --- a/src/Formatter/SimpleFormatter.php +++ b/src/Formatter/SimpleFormatter.php @@ -39,4 +39,12 @@ public function formatResponse(ResponseInterface $response) $response->getProtocolVersion() ); } + + /** + * {@inheritdoc} + */ + public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request) + { + return $this->formatResponse($response); + } } From b46b1b1769a1b52195ba7714b2090b99afd56d1e Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Thu, 10 Feb 2022 09:17:32 +0100 Subject: [PATCH 102/132] deprecate-formatResponse --- CHANGELOG.md | 1 + src/Formatter.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e3fa59..e8e5f53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [1.13.0] - tomorrow - Added `Formatter::formatResponseForRequest()` +- Deprecated `Formatter::formatResponse()` ## [1.12.0] - 2021-08-29 diff --git a/src/Formatter.php b/src/Formatter.php index 5c2d1aa..b8cf7b4 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -9,7 +9,7 @@ * Formats a request and/or a response as a string. * * @author Márk Sági-Kazár - * + * * @method string formatResponseForRequest(ResponseInterface $response, RequestInterface $request) Formats a response in context of its request. */ interface Formatter @@ -22,6 +22,8 @@ interface Formatter public function formatRequest(RequestInterface $request); /** + * @deprecated since 1.13, use formatResponseForRequest() instead + * * Formats a response. * * @return string From 7ce699a9601926880026c23edcde14a4a07bb762 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 10 Feb 2022 09:16:32 +0100 Subject: [PATCH 103/132] adjust baseline to reformatted error messages and fix some issues --- .github/workflows/static.yml | 3 ++ composer.json | 5 ++- phpstan-baseline.neon | 67 ++++++++++------------------------- src/Authentication/Header.php | 5 ++- src/CookieJar.php | 2 ++ src/Encoding/Filter/Chunk.php | 1 + src/Stream/BufferedStream.php | 3 ++ 7 files changed, 35 insertions(+), 51 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 6530f18..373207a 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -15,6 +15,9 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Install legacy zend diactoros as we reference that as well + run: composer require "zendframework/zend-diactoros:2.2.1" --no-interaction --no-update + - name: PHPStan uses: docker://oskarstark/phpstan-ga env: diff --git a/composer.json b/composer.json index 5d24bcd..1a614df 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,10 @@ "slim/slim": "Used with Slim Framework PSR-7 implementation" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "ergebnis/composer-normalize": true + } }, "extra": { "branch-alias": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 40013ca..065b358 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,20 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Property Http\\\\Message\\\\Authentication\\\\Header\\:\\:\\$value type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Authentication/Header.php - - - - message: "#^Method Http\\\\Message\\\\Authentication\\\\Header\\:\\:__construct\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/Authentication/Header.php - - - - message: "#The Http\\\\Message\\\\Authentication\\\\Matching class is deprecated since version 1.2 and will be removed in 2.0.#" - count: 1 - path: src/Authentication/Matching.php - - message: "#^Property Http\\\\Message\\\\Authentication\\\\QueryParam\\:\\:\\$params type has no value type specified in iterable type array\\.$#" count: 1 @@ -41,7 +26,7 @@ parameters: path: src/Builder/ResponseBuilder.php - - message: "#^Method Http\\\\Message\\\\Cookie\\:\\:createWithoutValidation\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:createWithoutValidation\\(\\) has no return type specified\\.$#" count: 1 path: src/Cookie.php @@ -56,17 +41,17 @@ parameters: path: src/Cookie.php - - message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateName\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateName\\(\\) has no return type specified\\.$#" count: 1 path: src/Cookie.php - - message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateValue\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateValue\\(\\) has no return type specified\\.$#" count: 1 path: src/Cookie.php - - message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateMaxAge\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateMaxAge\\(\\) has no return type specified\\.$#" count: 1 path: src/Cookie.php @@ -86,12 +71,12 @@ parameters: path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookie\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookie\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookie\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookie\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php @@ -101,22 +86,22 @@ parameters: path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:setCookies\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:setCookies\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookies\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookies\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookies\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookies\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeMatchingCookies\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeMatchingCookies\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php @@ -126,7 +111,7 @@ parameters: path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:clear\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:clear\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php @@ -141,37 +126,27 @@ parameters: path: src/CookieUtil.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\ChunkStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Encoding\\\\ChunkStream\\:\\:fill\\(\\) has no return type specified\\.$#" count: 1 path: src/Encoding/ChunkStream.php - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$consumed with no typehint specified\\.$#" - count: 1 - path: src/Encoding/Filter/Chunk.php - - - - message: "#^Access to an undefined property Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:\\$stream\\.$#" - count: 2 - path: src/Encoding/Filter/Chunk.php - - message: "#^Access to an undefined property object\\:\\:\\$datalen\\.$#" count: 2 path: src/Encoding/Filter/Chunk.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return type specified\\.$#" count: 1 path: src/Encoding/FilteredStream.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return type specified\\.$#" count: 1 path: src/Encoding/FilteredStream.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return type specified\\.$#" count: 1 path: src/Encoding/FilteredStream.php @@ -205,11 +180,6 @@ parameters: count: 1 path: src/MessageFactory/SlimMessageFactory.php - - - message: "#The Http\\\\Message\\\\RequestMatcher\\\\RegexRequestMatcher class is deprecated since version 1.2 and will be removed in 2.0.#" - count: 1 - path: src/RequestMatcher/RegexRequestMatcher.php - - message: "#^Property Http\\\\Message\\\\RequestMatcher\\\\RequestMatcher\\:\\:\\$methods type has no value type specified in iterable type array\\.$#" count: 1 @@ -236,7 +206,7 @@ parameters: path: src/Stream/BufferedStream.php - - message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#" + message: "#^Dead catch \\- Exception is already caught#" count: 1 path: src/Stream/BufferedStream.php @@ -266,12 +236,12 @@ parameters: path: src/Stream/BufferedStream.php - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:seek\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:seek\\(\\) has no return type specified\\.$#" count: 1 path: src/Stream/BufferedStream.php - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:rewind\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:rewind\\(\\) has no return type specified\\.$#" count: 1 path: src/Stream/BufferedStream.php @@ -294,4 +264,3 @@ parameters: message: "#^Unreachable statement \\- code above always terminates\\.$#" count: 1 path: src/UriFactory/SlimUriFactory.php - diff --git a/src/Authentication/Header.php b/src/Authentication/Header.php index 97a04dd..77f6382 100644 --- a/src/Authentication/Header.php +++ b/src/Authentication/Header.php @@ -13,10 +13,13 @@ class Header implements Authentication private $name; /** - * @var string|array + * @var string|string[] */ private $value; + /** + * @param string|string[] $value + */ public function __construct(string $name, $value) { $this->name = $name; diff --git a/src/CookieJar.php b/src/CookieJar.php index 1479cc6..914ad97 100644 --- a/src/CookieJar.php +++ b/src/CookieJar.php @@ -195,6 +195,7 @@ public function clear() /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function count() { return $this->cookies->count(); @@ -203,6 +204,7 @@ public function count() /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function getIterator() { return clone $this->cookies; diff --git a/src/Encoding/Filter/Chunk.php b/src/Encoding/Filter/Chunk.php index 0f8f53b..538e270 100644 --- a/src/Encoding/Filter/Chunk.php +++ b/src/Encoding/Filter/Chunk.php @@ -12,6 +12,7 @@ class Chunk extends \php_user_filter /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { diff --git a/src/Stream/BufferedStream.php b/src/Stream/BufferedStream.php index 1eac974..3d38731 100644 --- a/src/Stream/BufferedStream.php +++ b/src/Stream/BufferedStream.php @@ -203,6 +203,9 @@ public function read($length) if (null === $this->resource) { throw new \RuntimeException('Cannot read on a detached stream'); } + if ($length < 0) { + throw new \InvalidArgumentException('Can not read a negative amount of bytes'); + } $read = ''; From 0e5a4ef15c3d22a9f5e1b88a6c6652cfe37ab378 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 11 Feb 2022 14:26:24 +0100 Subject: [PATCH 104/132] php 8 seems to behave the same as php 7 - maybe it was a regression in php 8 previews that got fixed before stable? --- spec/Encoding/FilteredStreamStubSpec.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/spec/Encoding/FilteredStreamStubSpec.php b/spec/Encoding/FilteredStreamStubSpec.php index 7e3f3f6..6e6692e 100644 --- a/spec/Encoding/FilteredStreamStubSpec.php +++ b/spec/Encoding/FilteredStreamStubSpec.php @@ -12,22 +12,14 @@ function it_throws_during_instantiation_with_invalid_read_filter_options(StreamI { $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); $this->beConstructedWith($stream, 'foo'); - if (\PHP_MAJOR_VERSION < 8) { - $this->shouldThrow('RuntimeException')->duringInstantiation(); - } else { - $this->shouldThrow('PhpSpec\Exception\Example\ErrorException')->duringInstantiation(); - } + $this->shouldThrow('RuntimeException')->duringInstantiation(); } function it_throws_during_instantiation_with_invalid_write_filter_options(StreamInterface $stream) { $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); $this->beConstructedWith($stream, null, 'foo'); - if (\PHP_MAJOR_VERSION < 8) { - $this->shouldThrow('RuntimeException')->duringInstantiation(); - } else { - $this->shouldThrow('PhpSpec\Exception\Example\ErrorException')->duringInstantiation(); - } + $this->shouldThrow('RuntimeException')->duringInstantiation(); } function let(StreamInterface $stream) From 1c84052622db39c6d2eee35ed1820cb52d7b1778 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 11 Feb 2022 14:34:02 +0100 Subject: [PATCH 105/132] phpdoc for the new method --- src/Formatter.php | 3 +++ src/Formatter/CurlCommandFormatter.php | 4 +++- src/Formatter/FullHttpMessageFormatter.php | 4 +++- src/Formatter/SimpleFormatter.php | 4 +++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Formatter.php b/src/Formatter.php index b8cf7b4..6ef70bb 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -10,6 +10,9 @@ * * @author Márk Sági-Kazár * + * The formatResponseForRequest method will be added to this interface in the next major version, replacing the formatRequest method. + * Meanwhile, callers SHOULD check the formatter for the existence of formatResponseForRequest and call that if available. + * * @method string formatResponseForRequest(ResponseInterface $response, RequestInterface $request) Formats a response in context of its request. */ interface Formatter diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 31f5e7b..80d2971 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -69,7 +69,9 @@ public function formatResponse(ResponseInterface $response) } /** - * {@inheritdoc} + * Formats a response in context of its request. + * + * @return string */ public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request) { diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index 451f667..8b9b126 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -75,7 +75,9 @@ public function formatResponse(ResponseInterface $response) } /** - * {@inheritdoc} + * Formats a response in context of its request. + * + * @return string */ public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request) { diff --git a/src/Formatter/SimpleFormatter.php b/src/Formatter/SimpleFormatter.php index cfdfef9..ee99ae3 100644 --- a/src/Formatter/SimpleFormatter.php +++ b/src/Formatter/SimpleFormatter.php @@ -41,7 +41,9 @@ public function formatResponse(ResponseInterface $response) } /** - * {@inheritdoc} + * Formats a response in context of its request. + * + * @return string */ public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request) { From 7886e647a30a966a1a8d1dad1845b71ca8678361 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 11 Feb 2022 14:41:14 +0100 Subject: [PATCH 106/132] prepare release --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8e5f53..a185f46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [1.13.0] - tomorrow +## [1.13.0] - 2022-02-11 -- Added `Formatter::formatResponseForRequest()` -- Deprecated `Formatter::formatResponse()` +- Added `Formatter::formatResponseForRequest()` to allow the formatter to get context from the request to decide what of the response to output. +- Deprecated `Formatter::formatResponse()` in favor of the new `formatResponseForRequest` method. ## [1.12.0] - 2021-08-29 -- Added support for adjusting binary detection regex in FullHttpMessageFormatter +- Added support for adjusting binary detection regex in FullHttpMessageFormatter. ## [1.11.2] - 2021-08-03 From 0b1ce26c631209b652397884332543c2bebf9005 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 11 Apr 2023 11:21:55 +0200 Subject: [PATCH 107/132] Allow "psr/http-message" v2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1a614df..b8f5ce7 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "php": "^7.1 || ^8.0", "clue/stream-filter": "^1.5", "php-http/message-factory": "^1.0.2", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0 || ^2.0" }, "provide": { "php-http/message-factory-implementation": "1.0" From acd10afda402529fc3c10fda16cd51cbc92348cd Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 14 Apr 2023 15:40:59 +0200 Subject: [PATCH 108/132] semantic branch naming --- .github/workflows/checks.yml | 6 +++--- .github/workflows/static.yml | 6 +++--- .github/workflows/{ci.yml => tests.yml} | 10 ++++++---- README.md | 2 +- composer.json | 5 ----- 5 files changed, 13 insertions(+), 16 deletions(-) rename .github/workflows/{ci.yml => tests.yml} (93%) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 3a3dfee..eeb7320 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -3,7 +3,7 @@ name: Checks on: push: branches: - - master + - '*.x' pull_request: jobs: @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Composer normalize uses: docker://ergebnis/composer-normalize-action @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Roave BC Check uses: docker://nyholm/roave-bc-check-ga diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 373207a..50d9911 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -3,7 +3,7 @@ name: Static analysis on: push: branches: - - master + - '*.x' pull_request: jobs: @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install legacy zend diactoros as we reference that as well run: composer require "zendframework/zend-diactoros:2.2.1" --no-interaction --no-update @@ -31,7 +31,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga:2.19.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/tests.yml similarity index 93% rename from .github/workflows/ci.yml rename to .github/workflows/tests.yml index f6c6c16..da1e6ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/tests.yml @@ -1,7 +1,9 @@ -name: CI +name: tests on: push: + branches: + - '*.x' pull_request: jobs: @@ -14,7 +16,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -44,7 +46,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -67,7 +69,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/README.md b/README.md index df1a7d5..7699b91 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Latest Version](https://img.shields.io/github/release/php-http/message.svg?style=flat-square)](https://github.com/php-http/message/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/php-http/message/CI?style=flat-square)](https://github.com/php-http/message/actions?query=workflow%3ACI+branch%3Amaster) +[![tests](https://github.com/php-http/message/actions/workflows/ci.yml/badge.svg)](https://github.com/php-http/message/actions/workflows/ci.yml) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/message.svg?style=flat-square)](https://packagist.org/packages/php-http/message) **HTTP Message related tools.** diff --git a/composer.json b/composer.json index 1a614df..f8f8de8 100644 --- a/composer.json +++ b/composer.json @@ -43,11 +43,6 @@ "ergebnis/composer-normalize": true } }, - "extra": { - "branch-alias": { - "dev-master": "1.10-dev" - } - }, "autoload": { "psr-4": { "Http\\Message\\": "src/" From 1b3063ec7cfe641d1055d9b9559346bfc7e32593 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 14 Apr 2023 15:41:56 +0200 Subject: [PATCH 109/132] cleanup ci --- .github/workflows/static.yml | 3 --- .github/workflows/tests.yml | 8 +------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 50d9911..b4775f8 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -15,9 +15,6 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Install legacy zend diactoros as we reference that as well - run: composer require "zendframework/zend-diactoros:2.2.1" --no-interaction --no-update - - name: PHPStan uses: docker://oskarstark/phpstan-ga env: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index da1e6ed..54c6135 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] steps: - name: Checkout code @@ -25,12 +25,6 @@ jobs: tools: composer coverage: none - - name: Require PHPSpec 7.1 dependencies - run: | - composer require "phpspec/phpspec:^7.1@dev" --no-interaction --no-update - composer update --prefer-dist --no-interaction --no-progress --ignore-platform-req=php - if: "matrix.php == '8.1'" - - name: Install dependencies run: composer update --prefer-dist --no-interaction --no-progress From 9f7f2e98c8ada2837742bbe40a2f6329f1924511 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 14 Apr 2023 15:46:47 +0200 Subject: [PATCH 110/132] cs fixer update --- .github/workflows/static.yml | 2 +- .gitignore | 4 +- .php-cs-fixer.dist.php | 18 +++++ .php_cs.dist | 17 ----- spec/Authentication/AutoBasicAuthSpec.php | 13 ++-- spec/Authentication/BasicAuthSpec.php | 10 +-- spec/Authentication/BearerSpec.php | 10 +-- spec/Authentication/ChainSpec.php | 10 +-- spec/Authentication/HeaderSpec.php | 8 +-- spec/Authentication/MatchingSpec.php | 18 ++--- spec/Authentication/QueryParamSpec.php | 10 +-- .../Authentication/RequestConditionalSpec.php | 12 ++-- spec/Authentication/WsseSpec.php | 12 ++-- spec/Builder/ResponseBuilderSpec.php | 8 +-- spec/CookieJarSpec.php | 28 ++++---- spec/CookieSpec.php | 67 +++++++++---------- spec/CookieUtilSpec.php | 51 +++++++------- spec/Decorator/MessageDecoratorSpec.php | 41 ++++++------ spec/Decorator/RequestDecoratorSpec.php | 31 +++++---- spec/Decorator/ResponseDecoratorSpec.php | 25 ++++--- spec/Decorator/StreamDecoratorSpec.php | 43 ++++++------ spec/Encoding/ChunkStreamSpec.php | 12 ++-- spec/Encoding/CompressStreamSpec.php | 15 +++-- spec/Encoding/DechunkStreamSpec.php | 22 +++--- spec/Encoding/DecompressStreamSpec.php | 15 +++-- spec/Encoding/DeflateStreamSpec.php | 14 ++-- spec/Encoding/FilteredStreamStubSpec.php | 12 ++-- spec/Encoding/GzipDecodeStreamSpec.php | 15 +++-- spec/Encoding/GzipEncodeStreamSpec.php | 17 ++--- spec/Encoding/InflateStreamSpec.php | 15 +++-- spec/Encoding/MemoryStream.php | 2 +- spec/Encoding/StreamBehavior.php | 2 +- spec/Encoding/ZlibStreamBehavior.php | 4 +- spec/Formatter/CurlCommandFormatterSpec.php | 26 +++---- .../FullHttpMessageFormatterSpec.php | 28 ++++---- spec/Formatter/SimpleFormatterSpec.php | 10 +-- .../DiactorosMessageFactorySpec.php | 2 +- .../GuzzleMessageFactorySpec.php | 2 +- .../MessageFactory/MessageFactoryBehavior.php | 6 +- .../MessageFactory/SlimMessageFactorySpec.php | 2 +- .../CallbackRequestMatcherSpec.php | 11 ++- .../RegexRequestMatcherSpec.php | 13 ++-- spec/RequestMatcher/RequestMatcherSpec.php | 25 +++---- spec/Stream/BufferedStreamSpec.php | 32 ++++----- .../DiactorosStreamFactorySpec.php | 4 +- spec/StreamFactory/SlimStreamFactorySpec.php | 6 +- spec/StreamFactory/StreamFactoryBehavior.php | 14 ++-- spec/UriFactory/DiactorosUriFactorySpec.php | 8 +-- spec/UriFactory/GuzzleUriFactorySpec.php | 8 +-- spec/UriFactory/SlimUriFactorySpec.php | 8 +-- spec/UriFactory/UriFactoryBehavior.php | 8 +-- src/Authentication/Wsse.php | 3 +- src/Cookie.php | 2 - src/Encoding/FilteredStream.php | 2 +- src/UriFactory/GuzzleUriFactory.php | 3 +- 55 files changed, 398 insertions(+), 408 deletions(-) create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .php_cs.dist diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index b4775f8..93d1956 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -31,6 +31,6 @@ jobs: uses: actions/checkout@v3 - name: PHP-CS-Fixer - uses: docker://oskarstark/php-cs-fixer-ga:2.19.0 + uses: docker://oskarstark/php-cs-fixer-ga with: args: --dry-run --diff-format udiff diff --git a/.gitignore b/.gitignore index 9771070..fddbbfb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -.php_cs -.php_cs.cache +.php-cs-fixer.php +.php-cs-fixer.cache /build/ /composer.lock /phpspec.yml diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..472cc1e --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,18 @@ +in(__DIR__.'/src') + ->in(__DIR__.'/spec') + ->name('*.php') +; + +$config = new PhpCsFixer\Config(); + +return $config + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'single_line_throw' => false, + ]) + ->setFinder($finder) +; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index 1144ed4..0000000 --- a/.php_cs.dist +++ /dev/null @@ -1,17 +0,0 @@ -setRiskyAllowed(true) - ->setRules([ - '@Symfony' => true, - 'array_syntax' => ['syntax' => 'short'], - 'single_line_throw' => false, - ]) - ->setFinder( - PhpCsFixer\Finder::create() - ->in(__DIR__.'/src') - ->name('*.php') - ) -; - -return $config; diff --git a/spec/Authentication/AutoBasicAuthSpec.php b/spec/Authentication/AutoBasicAuthSpec.php index 33130ed..ba4ea8e 100644 --- a/spec/Authentication/AutoBasicAuthSpec.php +++ b/spec/Authentication/AutoBasicAuthSpec.php @@ -3,23 +3,22 @@ namespace spec\Http\Message\Authentication; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; class AutoBasicAuthSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Authentication\AutoBasicAuth'); } - function it_is_an_authentication() + public function it_is_an_authentication() { $this->shouldImplement('Http\Message\Authentication'); } - function it_authenticates_a_request( + public function it_authenticates_a_request( RequestInterface $request, UriInterface $uri, UriInterface $uriWithoutUserInfo, @@ -38,7 +37,7 @@ function it_authenticates_a_request( $this->authenticate($request)->shouldReturn($authenticatedRequest); } - function it_authenticates_a_request_without_password( + public function it_authenticates_a_request_without_password( RequestInterface $request, UriInterface $uri, UriInterface $uriWithoutUserInfo, @@ -57,7 +56,7 @@ function it_authenticates_a_request_without_password( $this->authenticate($request)->shouldReturn($authenticatedRequest); } - function it_does_not_authenticate_a_request(RequestInterface $request, UriInterface $uri) + public function it_does_not_authenticate_a_request(RequestInterface $request, UriInterface $uri) { $request->getUri()->willReturn($uri); $uri->getUserInfo()->willReturn(''); @@ -65,7 +64,7 @@ function it_does_not_authenticate_a_request(RequestInterface $request, UriInterf $this->authenticate($request)->shouldReturn($request); } - function it_authenticates_a_request_without_user_info_removal( + public function it_authenticates_a_request_without_user_info_removal( RequestInterface $request, UriInterface $uri, RequestInterface $authenticatedRequest diff --git a/spec/Authentication/BasicAuthSpec.php b/spec/Authentication/BasicAuthSpec.php index e70d097..c0e2b80 100644 --- a/spec/Authentication/BasicAuthSpec.php +++ b/spec/Authentication/BasicAuthSpec.php @@ -2,27 +2,27 @@ namespace spec\Http\Message\Authentication; -use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\RequestInterface; class BasicAuthSpec extends ObjectBehavior { - function let() + public function let() { $this->beConstructedWith('john.doe', 'secret'); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Authentication\BasicAuth'); } - function it_is_an_authentication() + public function it_is_an_authentication() { $this->shouldImplement('Http\Message\Authentication'); } - function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) + public function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) { $request->withHeader('Authorization', 'Basic '.base64_encode('john.doe:secret'))->willReturn($newRequest); diff --git a/spec/Authentication/BearerSpec.php b/spec/Authentication/BearerSpec.php index aaca72a..a8670ac 100644 --- a/spec/Authentication/BearerSpec.php +++ b/spec/Authentication/BearerSpec.php @@ -2,27 +2,27 @@ namespace spec\Http\Message\Authentication; -use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\RequestInterface; class BearerSpec extends ObjectBehavior { - function let() + public function let() { $this->beConstructedWith('token'); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Authentication\Bearer'); } - function it_is_an_authentication() + public function it_is_an_authentication() { $this->shouldImplement('Http\Message\Authentication'); } - function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) + public function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) { $request->withHeader('Authorization', 'Bearer token')->willReturn($newRequest); diff --git a/spec/Authentication/ChainSpec.php b/spec/Authentication/ChainSpec.php index 61e752b..55f5d9a 100644 --- a/spec/Authentication/ChainSpec.php +++ b/spec/Authentication/ChainSpec.php @@ -3,29 +3,29 @@ namespace spec\Http\Message\Authentication; use Http\Message\Authentication; -use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\RequestInterface; class ChainSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Authentication\Chain'); } - function it_is_an_authentication() + public function it_is_an_authentication() { $this->shouldImplement('Http\Message\Authentication'); } - function it_throws_an_exception_when_non_authentication_is_passed() + public function it_throws_an_exception_when_non_authentication_is_passed() { $this->beConstructedWith(['authentication']); $this->shouldThrow('InvalidArgumentException')->duringInstantiation(); } - function it_authenticates_a_request( + public function it_authenticates_a_request( Authentication $auth1, Authentication $auth2, RequestInterface $originalRequest, diff --git a/spec/Authentication/HeaderSpec.php b/spec/Authentication/HeaderSpec.php index b6ee348..9558184 100644 --- a/spec/Authentication/HeaderSpec.php +++ b/spec/Authentication/HeaderSpec.php @@ -7,22 +7,22 @@ class HeaderSpec extends ObjectBehavior { - function let() + public function let() { $this->beConstructedWith('X-AUTH-TOKEN', 'REAL'); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Authentication\Header'); } - function it_is_an_authentication() + public function it_is_an_authentication() { $this->shouldImplement('Http\Message\Authentication'); } - function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) + public function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) { $request->withHeader('X-AUTH-TOKEN', 'REAL')->willReturn($newRequest); diff --git a/spec/Authentication/MatchingSpec.php b/spec/Authentication/MatchingSpec.php index 58f458b..23cd1d6 100644 --- a/spec/Authentication/MatchingSpec.php +++ b/spec/Authentication/MatchingSpec.php @@ -3,38 +3,38 @@ namespace spec\Http\Message\Authentication; use Http\Message\Authentication; -use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\RequestInterface; class MatchingSpec extends ObjectBehavior { - function let(Authentication $authentication) + public function let(Authentication $authentication) { - $matcher = function($request) { return true; }; + $matcher = function ($request) { return true; }; $this->beConstructedWith($authentication, $matcher); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Authentication\Matching'); } - function it_is_an_authentication() + public function it_is_an_authentication() { $this->shouldImplement('Http\Message\Authentication'); } - function it_authenticates_a_request(Authentication $authentication, RequestInterface $request, RequestInterface $newRequest) + public function it_authenticates_a_request(Authentication $authentication, RequestInterface $request, RequestInterface $newRequest) { $authentication->authenticate($request)->willReturn($newRequest); $this->authenticate($request)->shouldReturn($newRequest); } - function it_does_not_authenticate_a_request(Authentication $authentication, RequestInterface $request) + public function it_does_not_authenticate_a_request(Authentication $authentication, RequestInterface $request) { - $matcher = function($request) { return false; }; + $matcher = function ($request) { return false; }; $this->beConstructedWith($authentication, $matcher); @@ -43,7 +43,7 @@ function it_does_not_authenticate_a_request(Authentication $authentication, Requ $this->authenticate($request)->shouldReturn($request); } - function it_creates_a_matcher_from_url(Authentication $authentication) + public function it_creates_a_matcher_from_url(Authentication $authentication) { $this->createUrlMatcher($authentication, 'url')->shouldHaveType('Http\Message\Authentication\Matching'); } diff --git a/spec/Authentication/QueryParamSpec.php b/spec/Authentication/QueryParamSpec.php index 5e8b92e..eae560f 100644 --- a/spec/Authentication/QueryParamSpec.php +++ b/spec/Authentication/QueryParamSpec.php @@ -2,13 +2,13 @@ namespace spec\Http\Message\Authentication; +use PhpSpec\ObjectBehavior; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; -use PhpSpec\ObjectBehavior; class QueryParamSpec extends ObjectBehavior { - function let() + public function let() { $this->beConstructedWith([ 'username' => 'username', @@ -16,17 +16,17 @@ function let() ]); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Authentication\QueryParam'); } - function it_is_an_authentication() + public function it_is_an_authentication() { $this->shouldImplement('Http\Message\Authentication'); } - function it_authenticates_a_request( + public function it_authenticates_a_request( RequestInterface $request, UriInterface $uri, RequestInterface $newRequest, diff --git a/spec/Authentication/RequestConditionalSpec.php b/spec/Authentication/RequestConditionalSpec.php index 5946736..f143f7a 100644 --- a/spec/Authentication/RequestConditionalSpec.php +++ b/spec/Authentication/RequestConditionalSpec.php @@ -4,27 +4,27 @@ use Http\Message\Authentication; use Http\Message\RequestMatcher; -use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\RequestInterface; class RequestConditionalSpec extends ObjectBehavior { - function let(RequestMatcher $requestMatcher, Authentication $authentication) + public function let(RequestMatcher $requestMatcher, Authentication $authentication) { $this->beConstructedWith($requestMatcher, $authentication); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Authentication\RequestConditional'); } - function it_is_an_authentication() + public function it_is_an_authentication() { $this->shouldImplement('Http\Message\Authentication'); } - function it_authenticates_a_request( + public function it_authenticates_a_request( Authentication $authentication, RequestMatcher $requestMatcher, RequestInterface $request, @@ -36,7 +36,7 @@ function it_authenticates_a_request( $this->authenticate($request)->shouldReturn($newRequest); } - function it_does_not_authenticate_a_request( + public function it_does_not_authenticate_a_request( Authentication $authentication, RequestMatcher $requestMatcher, RequestInterface $request diff --git a/spec/Authentication/WsseSpec.php b/spec/Authentication/WsseSpec.php index 926e9da..bb48c1f 100644 --- a/spec/Authentication/WsseSpec.php +++ b/spec/Authentication/WsseSpec.php @@ -2,34 +2,34 @@ namespace spec\Http\Message\Authentication; -use Psr\Http\Message\RequestInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Psr\Http\Message\RequestInterface; class WsseSpec extends ObjectBehavior { - function let() + public function let() { $this->beConstructedWith('john.doe', 'secret'); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Authentication\Wsse'); } - function it_is_an_authentication() + public function it_is_an_authentication() { $this->shouldImplement('Http\Message\Authentication'); } - function it_authenticates_a_request( + public function it_authenticates_a_request( RequestInterface $request, RequestInterface $newRequest, RequestInterface $newerRequest ) { $request->withHeader('Authorization', 'WSSE profile="UsernameToken"')->willReturn($newRequest); - $newRequest->withHeader('X-WSSE', Argument::that(function($arg) { + $newRequest->withHeader('X-WSSE', Argument::that(function ($arg) { return preg_match('/UsernameToken Username=".*", PasswordDigest=".*", Nonce=".*", Created=".*"/', $arg); }))->willReturn($newerRequest); diff --git a/spec/Builder/ResponseBuilderSpec.php b/spec/Builder/ResponseBuilderSpec.php index c4cc81e..4dfe977 100644 --- a/spec/Builder/ResponseBuilderSpec.php +++ b/spec/Builder/ResponseBuilderSpec.php @@ -7,13 +7,13 @@ class ResponseBuilderSpec extends ObjectBehavior { - function it_is_initializable(ResponseInterface $response) + public function it_is_initializable(ResponseInterface $response) { $this->beConstructedWith($response); $this->shouldHaveType('Http\Message\Builder\ResponseBuilder'); } - function it_reads_headers_from_array(ResponseInterface $response) + public function it_reads_headers_from_array(ResponseInterface $response) { $response->withStatus(200, 'OK')->willReturn($response); $response->withProtocolVersion('1.1')->willReturn($response); @@ -24,9 +24,9 @@ function it_reads_headers_from_array(ResponseInterface $response) } /** - * @link https://github.com/php-http/message/issues/41 + * @see https://github.com/php-http/message/issues/41 */ - function it_splits_headers_correctly(ResponseInterface $response) + public function it_splits_headers_correctly(ResponseInterface $response) { $response->withStatus(200, 'OK')->willReturn($response); $response->withProtocolVersion('1.1')->willReturn($response); diff --git a/spec/CookieJarSpec.php b/spec/CookieJarSpec.php index f528395..9a8acb6 100644 --- a/spec/CookieJarSpec.php +++ b/spec/CookieJarSpec.php @@ -7,17 +7,17 @@ class CookieJarSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\CookieJar'); } - function it_is_an_iterator_aggregate() + public function it_is_an_iterator_aggregate() { $this->getIterator()->shouldHaveType('Iterator'); } - function it_has_a_cookie() + public function it_has_a_cookie() { $cookie = new Cookie('name', 'value'); @@ -27,7 +27,7 @@ function it_has_a_cookie() $this->hasCookies()->shouldReturn(true); } - function it_accepts_a_cookie() + public function it_accepts_a_cookie() { $cookie = new Cookie('name', 'value'); $cookie2 = new Cookie('name', 'value2'); @@ -39,7 +39,7 @@ function it_accepts_a_cookie() $this->hasCookie($cookie2)->shouldReturn(true); } - function it_removes_a_cookie_with_an_empty_value() + public function it_removes_a_cookie_with_an_empty_value() { $cookie = new Cookie('name', 'value'); $cookie2 = new Cookie('name'); @@ -51,7 +51,7 @@ function it_removes_a_cookie_with_an_empty_value() $this->hasCookie($cookie2)->shouldReturn(false); } - function it_removes_a_cookie_with_a_lower_expiration_time() + public function it_removes_a_cookie_with_a_lower_expiration_time() { $cookie = new Cookie('name', 'value', 100); $cookie2 = new Cookie('name', 'value', 1000); @@ -63,7 +63,7 @@ function it_removes_a_cookie_with_a_lower_expiration_time() $this->hasCookie($cookie2)->shouldReturn(true); } - function it_removes_a_cookie() + public function it_removes_a_cookie() { $cookie = new Cookie('name', 'value', 100); @@ -73,7 +73,7 @@ function it_removes_a_cookie() $this->hasCookie($cookie)->shouldReturn(false); } - function it_returns_all_cookies() + public function it_returns_all_cookies() { $cookie = new Cookie('name', 'value'); $cookie2 = new Cookie('name2', 'value'); @@ -84,7 +84,7 @@ function it_returns_all_cookies() $this->getCookies()->shouldBeAnArrayOfInstance('Http\Message\Cookie'); } - function it_returns_the_matching_cookies() + public function it_returns_the_matching_cookies() { $cookie = new Cookie('name', 'value'); $cookie2 = new Cookie('name', 'value2'); @@ -94,7 +94,7 @@ function it_returns_the_matching_cookies() $this->getMatchingCookies($cookie2)->shouldBeAnArrayOfInstance('Http\Message\Cookie'); } - function it_sets_cookies() + public function it_sets_cookies() { $cookie = new Cookie('name', 'value'); @@ -105,7 +105,7 @@ function it_sets_cookies() $this->count()->shouldReturn(1); } - function it_accepts_cookies() + public function it_accepts_cookies() { $cookie = new Cookie('name', 'value'); $cookie2 = new Cookie('name2', 'value'); @@ -119,7 +119,7 @@ function it_accepts_cookies() $this->count()->shouldReturn(2); } - function it_removes_cookies() + public function it_removes_cookies() { $cookie = new Cookie('name', 'value'); $cookie2 = new Cookie('name2', 'value'); @@ -133,7 +133,7 @@ function it_removes_cookies() $this->count()->shouldReturn(1); } - function it_removes_matching_cookies() + public function it_removes_matching_cookies() { $cookie = new Cookie('name', 'value'); $cookie2 = new Cookie('name2', 'value', 0, 'php-http.org'); @@ -148,7 +148,7 @@ function it_removes_matching_cookies() $this->count()->shouldReturn(1); } - function it_clears_cookies() + public function it_clears_cookies() { $cookie = new Cookie('name', 'value', 0, 'php-http.org'); $cookie2 = new Cookie('name2', 'value'); diff --git a/spec/CookieSpec.php b/spec/CookieSpec.php index c4e0c01..5f77e97 100644 --- a/spec/CookieSpec.php +++ b/spec/CookieSpec.php @@ -7,17 +7,17 @@ class CookieSpec extends ObjectBehavior { - function let() + public function let() { $this->beConstructedWith('name', 'value'); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Cookie'); } - function it_has_a_name() + public function it_has_a_name() { $this->getName()->shouldReturn('name'); } @@ -25,7 +25,7 @@ function it_has_a_name() /** * @dataProvider invalidCharacterExamples */ - function it_throws_an_exception_when_the_name_contains_invalid_character() + public function it_throws_an_exception_when_the_name_contains_invalid_character() { foreach (self::invalidCharacterExamples() as $example) { $this->beConstructedWith($example[0]); @@ -38,23 +38,22 @@ function it_throws_an_exception_when_the_name_contains_invalid_character() $expectation->duringInstantiation(); } - } - function it_throws_an_expection_when_name_is_empty() + public function it_throws_an_expection_when_name_is_empty() { $this->beConstructedWith(''); $this->shouldThrow('InvalidArgumentException')->duringInstantiation(); } - function it_has_a_value() + public function it_has_a_value() { $this->getValue()->shouldReturn('value'); $this->hasValue()->shouldReturn(true); } - function it_throws_an_exception_when_the_value_contains_invalid_character() + public function it_throws_an_exception_when_the_value_contains_invalid_character() { foreach (self::invalidCharacterExamples() as $example) { $this->beConstructedWith('name', $example[0]); @@ -69,7 +68,7 @@ function it_throws_an_exception_when_the_value_contains_invalid_character() } } - function it_accepts_a_value() + public function it_accepts_a_value() { $cookie = $this->withValue('value2'); @@ -77,7 +76,7 @@ function it_accepts_a_value() $cookie->getValue()->shouldReturn('value2'); } - function it_throws_an_exception_when_the_new_value_contains_invalid_character() + public function it_throws_an_exception_when_the_new_value_contains_invalid_character() { foreach (self::invalidCharacterExamples() as $example) { if ($example[1]) { @@ -90,7 +89,7 @@ function it_throws_an_exception_when_the_new_value_contains_invalid_character() } } - function it_has_a_max_age_time() + public function it_has_a_max_age_time() { $this->beConstructedWith('name', 'value', 10); @@ -98,7 +97,7 @@ function it_has_a_max_age_time() $this->hasMaxAge()->shouldReturn(true); } - function it_accepts_a_max_age() + public function it_accepts_a_max_age() { $cookie = $this->withMaxAge(1); @@ -106,12 +105,12 @@ function it_accepts_a_max_age() $cookie->getMaxAge()->shouldReturn(1); } - function it_throws_an_exception_when_max_age_is_invalid() + public function it_throws_an_exception_when_max_age_is_invalid() { $this->shouldThrow('InvalidArgumentException')->duringWithMaxAge('-1'); } - function it_has_an_expires_attribute() + public function it_has_an_expires_attribute() { $expires = new \DateTime('+10 seconds'); @@ -122,7 +121,7 @@ function it_has_an_expires_attribute() $this->isExpired()->shouldReturn(false); } - function it_accepts_an_expires_attribute() + public function it_accepts_an_expires_attribute() { $expires = new \DateTime('+10 seconds'); @@ -132,7 +131,7 @@ function it_accepts_an_expires_attribute() $cookie->getExpires()->shouldReturn($expires); } - function it_is_expired() + public function it_is_expired() { $this->beConstructedWith('name', 'value', null, null, null, false, false, new \DateTime('-2 minutes')); @@ -141,13 +140,13 @@ function it_is_expired() $this->isExpired()->shouldReturn(true); } - function it_has_a_domain() + public function it_has_a_domain() { $this->getDomain()->shouldReturn(null); $this->hasDomain()->shouldReturn(false); } - function it_has_a_valid_domain() + public function it_has_a_valid_domain() { $this->beConstructedWith('name', 'value', null, '.PhP-hTtP.oRg'); @@ -155,7 +154,7 @@ function it_has_a_valid_domain() $this->hasDomain()->shouldReturn(true); } - function it_accepts_a_domain() + public function it_accepts_a_domain() { $cookie = $this->withDomain('.PhP-hTtP.oRg'); @@ -163,7 +162,7 @@ function it_accepts_a_domain() $cookie->getDomain()->shouldReturn('php-http.org'); } - function it_matches_a_domain() + public function it_matches_a_domain() { $this->beConstructedWith('name', 'value', null, 'php-http.org'); @@ -172,12 +171,12 @@ function it_matches_a_domain() $this->matchDomain('wWw.PhP-hTtP.oRg')->shouldReturn(true); } - function it_has_a_path() + public function it_has_a_path() { $this->getPath()->shouldReturn('/'); } - function it_accepts_a_path() + public function it_accepts_a_path() { $cookie = $this->withPath('/path'); @@ -185,7 +184,7 @@ function it_accepts_a_path() $cookie->getPath()->shouldReturn('/path'); } - function it_matches_a_path() + public function it_matches_a_path() { $this->beConstructedWith('name', 'value', null, null, '/path/to/somewhere'); @@ -194,7 +193,7 @@ function it_matches_a_path() $this->matchPath('/path/to/somewhereelse')->shouldReturn(false); } - function it_matches_the_root_path() + public function it_matches_the_root_path() { $this->beConstructedWith('name', 'value', null, null, '/'); @@ -203,12 +202,12 @@ function it_matches_the_root_path() $this->matchPath('/cookies/')->shouldReturn(true); } - function it_is_secure() + public function it_is_secure() { $this->isSecure()->shouldReturn(false); } - function it_accepts_security() + public function it_accepts_security() { $cookie = $this->withSecure(true); @@ -216,12 +215,12 @@ function it_accepts_security() $cookie->isSecure()->shouldReturn(true); } - function it_can_be_http_only() + public function it_can_be_http_only() { $this->isHttpOnly()->shouldReturn(false); } - function it_accepts_http_only() + public function it_accepts_http_only() { $cookie = $this->withHttpOnly(true); @@ -229,7 +228,7 @@ function it_accepts_http_only() $cookie->isHttpOnly()->shouldReturn(true); } - function it_matches_other_cookies() + public function it_matches_other_cookies() { $this->beConstructedWith('name', 'value', null, 'php-http.org'); @@ -240,26 +239,26 @@ function it_matches_other_cookies() $this->match($notMatches)->shouldReturn(false); } - function it_validates_itself() + public function it_validates_itself() { $this->isValid()->shouldReturn(true); } - function it_can_be_constructed_without_name_validation() + public function it_can_be_constructed_without_name_validation() { $this->beConstructedThrough('createWithoutValidation', ["\x20"]); $this->isValid()->shouldReturn(false); } - function it_can_be_constructed_without_value_validation() + public function it_can_be_constructed_without_value_validation() { $this->beConstructedThrough('createWithoutValidation', ['name', "\x20"]); $this->isValid()->shouldReturn(false); } - function it_can_be_constructed_without_max_age_validation() + public function it_can_be_constructed_without_max_age_validation() { $this->beConstructedThrough('createWithoutValidation', ['name', 'value', '-1']); @@ -279,7 +278,7 @@ private static function invalidCharacterExamples() ['z', false], ["\x20", true], ['0', false], - ["\x7F", true] + ["\x7F", true], ]; } } diff --git a/spec/CookieUtilSpec.php b/spec/CookieUtilSpec.php index 6c831c1..3777b0a 100644 --- a/spec/CookieUtilSpec.php +++ b/spec/CookieUtilSpec.php @@ -2,147 +2,146 @@ namespace spec\Http\Message; -use Http\Message\Exception\UnexpectedValueException; use PhpSpec\ObjectBehavior; class CookieUtilSpec extends ObjectBehavior { - function it_parses_cookie_date_string_1() + public function it_parses_cookie_date_string_1() { $this->testCookieParse('Friday, 31 Jul 20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); } - function it_parses_cookie_date_string_2() + public function it_parses_cookie_date_string_2() { $this->testCookieParse('Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); } - function it_parses_cookie_date_string_3() + public function it_parses_cookie_date_string_3() { $this->testCookieParse('Fri, 31-Jul-2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); } - function it_parses_cookie_date_string_4() + public function it_parses_cookie_date_string_4() { $this->testCookieParse('Fri, 31 Jul 2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); } - function it_parses_cookie_date_string_5() + public function it_parses_cookie_date_string_5() { $this->testCookieParse('Fri, 31-07-2020 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); } - function it_parses_cookie_date_string_6() + public function it_parses_cookie_date_string_6() { $this->testCookieParse('Fri, 31-07-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); } - function it_parses_cookie_date_string_7() + public function it_parses_cookie_date_string_7() { $this->testCookieParse('Friday, 31-Jul-20 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); } - function it_parses_cookie_date_string_8() + public function it_parses_cookie_date_string_8() { $this->testCookieParse('Fri Jul 31 08:49:37 2020', 'Friday, 31-Jul-2020 08:49:37 +0000'); } - function it_parses_cookie_date_string_9() + public function it_parses_cookie_date_string_9() { $this->testCookieParse('Friday July 31st 2020, 08:49:37 GMT', 'Friday, 31-Jul-2020 08:49:37 +0000'); } - function it_parses_cookie_date_string_10() + public function it_parses_cookie_date_string_10() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('Wed, 09 Jun 2021 10:18:14 GMT', 'Wednesday, 09-Jun-2021 10:18:14 +0000'); } - function it_parses_cookie_date_string_11() + public function it_parses_cookie_date_string_11() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('Wed, 09 Jun 2021 22:18:14 GMT', 'Wednesday, 09-Jun-2021 22:18:14 +0000'); } - function it_parses_cookie_date_string_12() + public function it_parses_cookie_date_string_12() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('Tue, 18 Oct 2011 07:42:42.123 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'); } - function it_parses_cookie_date_string_13() + public function it_parses_cookie_date_string_13() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('18 Oct 2011 07:42:42 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'); } - function it_parses_cookie_date_string_14() + public function it_parses_cookie_date_string_14() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('8 Oct 2011 7:42:42 GMT', 'Saturday, 08-Oct-2011 07:42:42 +0000'); } - function it_parses_cookie_date_string_15() + public function it_parses_cookie_date_string_15() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('8 Oct 2011 7:2:42 GMT', 'Saturday, 08-Oct-2011 07:02:42 +0000'); } - function it_parses_cookie_date_string_16() + public function it_parses_cookie_date_string_16() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('Oct 18 2011 07:42:42 GMT', 'Tuesday, 18-Oct-2011 07:42:42 +0000'); } - function it_parses_cookie_date_string_17() + public function it_parses_cookie_date_string_17() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('Tue Oct 18 2011 07:05:03 GMT+0000 (GMT)', 'Tuesday, 18-Oct-2011 07:05:03 +0000'); } - function it_parses_cookie_date_string_18() + public function it_parses_cookie_date_string_18() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('09 Jun 2021 10:18:14 GMT', 'Wednesday, 09-Jun-2021 10:18:14 +0000'); } - function it_parses_cookie_date_string_19() + public function it_parses_cookie_date_string_19() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('01 Jan 1970 00:00:00 GMT', 'Thursday, 01-Jan-1970 00:00:00 +0000'); } - function it_parses_cookie_date_string_20() + public function it_parses_cookie_date_string_20() { // https://github.com/salesforce/tough-cookie/blob/master/test/date_test.js#L52 $this->testCookieParse('01 Jan 1601 00:00:00 GMT', 'Monday, 01-Jan-1601 00:00:00 +0000'); } - function it_parses_cookie_date_string_21() + public function it_parses_cookie_date_string_21() { // implicit year $this->testCookieParse('10 Feb 81 13:00:00 GMT', 'Tuesday, 10-Feb-1981 13:00:00 +0000'); } - function it_parses_cookie_date_string_22() + public function it_parses_cookie_date_string_22() { // dashes $this->testCookieParse('Thu, 17-Apr-2014 02:12:29 GMT', 'Thursday, 17-Apr-2014 02:12:29 +0000'); } - function it_parses_cookie_date_string_23() + public function it_parses_cookie_date_string_23() { // dashes and UTC $this->testCookieParse('Thu, 17-Apr-2014 02:12:29 UTC', 'Thursday, 17-Apr-2014 02:12:29 +0000'); } - function it_throws_an_exception_if_cookie_date_string_is_unparseable_1() + public function it_throws_an_exception_if_cookie_date_string_is_unparseable_1() { $this->beConstructedThrough('parseDate', ['Flursday July 31st 2020, 08:49:37 GMT']); $this->shouldThrow('Http\Message\Exception\UnexpectedValueException'); } - function it_throws_an_exception_if_cookie_date_string_is_unparseable_2() + public function it_throws_an_exception_if_cookie_date_string_is_unparseable_2() { $this->beConstructedThrough('parseDate', ['99 Jix 3038 48:86:72 ZMT']); $this->shouldThrow('Http\Message\Exception\UnexpectedValueException'); diff --git a/spec/Decorator/MessageDecoratorSpec.php b/spec/Decorator/MessageDecoratorSpec.php index e9d0fe9..5c28dcd 100644 --- a/spec/Decorator/MessageDecoratorSpec.php +++ b/spec/Decorator/MessageDecoratorSpec.php @@ -3,46 +3,45 @@ namespace spec\Http\Message\Decorator; use Http\Message\Decorator\MessageDecorator; +use PhpSpec\ObjectBehavior; use Psr\Http\Message\MessageInterface; use Psr\Http\Message\StreamInterface; -use Psr\Http\Message\UriInterface; -use PhpSpec\ObjectBehavior; class MessageDecoratorSpec extends ObjectBehavior { - function let(MessageInterface $message) + public function let(MessageInterface $message) { $this->beAnInstanceOf('spec\Http\Message\Decorator\MessageDecoratorStub', [$message]); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('spec\Http\Message\Decorator\MessageDecoratorStub'); } - function it_is_a_message() + public function it_is_a_message() { $this->shouldImplement('Psr\Http\Message\MessageInterface'); } - function it_is_a_message_decorator() + public function it_is_a_message_decorator() { $this->shouldUseTrait('Http\Message\Decorator\MessageDecorator'); } - function it_has_a_message() + public function it_has_a_message() { $this->getMessage()->shouldImplement('Psr\Http\Message\MessageInterface'); } - function it_has_a_protocol_version(MessageInterface $message) + public function it_has_a_protocol_version(MessageInterface $message) { $message->getProtocolVersion()->willReturn('1.1'); $this->getProtocolVersion()->shouldReturn('1.1'); } - function it_accepts_a_protocol_version(MessageInterface $message, MessageInterface $newMessage) + public function it_accepts_a_protocol_version(MessageInterface $message, MessageInterface $newMessage) { $message->withProtocolVersion('1.1')->willReturn($newMessage); @@ -50,10 +49,10 @@ function it_accepts_a_protocol_version(MessageInterface $message, MessageInterfa $new->getMessage()->shouldReturn($newMessage); } - function it_has_headers(MessageInterface $message) + public function it_has_headers(MessageInterface $message) { $headers = [ - 'Content-Type' => 'application/xml' + 'Content-Type' => 'application/xml', ]; $message->getHeaders()->willReturn($headers); @@ -61,28 +60,28 @@ function it_has_headers(MessageInterface $message) $this->getHeaders()->shouldReturn($headers); } - function it_can_check_a_header(MessageInterface $message) + public function it_can_check_a_header(MessageInterface $message) { $message->hasHeader('Content-Type')->willReturn(true); $this->hasHeader('Content-Type')->shouldReturn(true); } - function it_has_a_header(MessageInterface $message) + public function it_has_a_header(MessageInterface $message) { $message->getHeader('Content-Type')->willReturn('application/xml'); $this->getHeader('Content-Type')->shouldReturn('application/xml'); } - function it_has_a_header_line(MessageInterface $message) + public function it_has_a_header_line(MessageInterface $message) { $message->getHeaderLine('Accept-Encoding')->willReturn('gzip, deflate'); $this->getHeaderLine('Accept-Encoding')->shouldReturn('gzip, deflate'); } - function it_accepts_a_header(MessageInterface $message, MessageInterface $newMessage) + public function it_accepts_a_header(MessageInterface $message, MessageInterface $newMessage) { $message->withHeader('Content-Type', 'application/xml')->willReturn($newMessage); @@ -90,7 +89,7 @@ function it_accepts_a_header(MessageInterface $message, MessageInterface $newMes $new->getMessage()->shouldReturn($newMessage); } - function it_accepts_added_headers(MessageInterface $message, MessageInterface $newMessage) + public function it_accepts_added_headers(MessageInterface $message, MessageInterface $newMessage) { $message->withAddedHeader('Content-Type', 'application/xml')->willReturn($newMessage); @@ -98,7 +97,7 @@ function it_accepts_added_headers(MessageInterface $message, MessageInterface $n $new->getMessage()->shouldReturn($newMessage); } - function it_removes_a_header(MessageInterface $message, MessageInterface $newMessage) + public function it_removes_a_header(MessageInterface $message, MessageInterface $newMessage) { $message->withoutHeader('Content-Type')->willReturn($newMessage); @@ -106,14 +105,14 @@ function it_removes_a_header(MessageInterface $message, MessageInterface $newMes $new->getMessage()->shouldReturn($newMessage); } - function it_has_a_body(MessageInterface $message, StreamInterface $body) + public function it_has_a_body(MessageInterface $message, StreamInterface $body) { $message->getBody()->willReturn($body); $this->getBody()->shouldReturn($body); } - function it_accepts_a_body(MessageInterface $message, MessageInterface $newMessage, StreamInterface $body) + public function it_accepts_a_body(MessageInterface $message, MessageInterface $newMessage, StreamInterface $body) { $message->withBody($body)->willReturn($newMessage); @@ -121,12 +120,12 @@ function it_accepts_a_body(MessageInterface $message, MessageInterface $newMessa $new->getMessage()->shouldReturn($newMessage); } - function getMatchers(): array + public function getMatchers(): array { return [ 'useTrait' => function ($subject, $trait) { return class_uses($subject, $trait); - } + }, ]; } } diff --git a/spec/Decorator/RequestDecoratorSpec.php b/spec/Decorator/RequestDecoratorSpec.php index efe4648..b1e200c 100644 --- a/spec/Decorator/RequestDecoratorSpec.php +++ b/spec/Decorator/RequestDecoratorSpec.php @@ -3,53 +3,52 @@ namespace spec\Http\Message\Decorator; use Http\Message\Decorator\RequestDecorator; +use PhpSpec\ObjectBehavior; use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\StreamInterface; use Psr\Http\Message\UriInterface; -use PhpSpec\ObjectBehavior; class RequestDecoratorSpec extends ObjectBehavior { - function let(RequestInterface $request) + public function let(RequestInterface $request) { $this->beAnInstanceOf('spec\Http\Message\Decorator\RequestDecoratorStub', [$request]); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('spec\Http\Message\Decorator\RequestDecoratorStub'); } - function it_is_a_request() + public function it_is_a_request() { $this->shouldImplement('Psr\Http\Message\RequestInterface'); } - function it_is_a_request_decorator() + public function it_is_a_request_decorator() { $this->shouldUseTrait('Http\Message\Decorator\RequestDecorator'); } - function it_has_a_request() + public function it_has_a_request() { $this->getRequest()->shouldImplement('Psr\Http\Message\RequestInterface'); } - function it_accepts_a_request(RequestInterface $request) + public function it_accepts_a_request(RequestInterface $request) { $new = $this->withRequest($request); $new->getRequest()->shouldReturn($request); } - function it_has_a_request_target(RequestInterface $request) + public function it_has_a_request_target(RequestInterface $request) { $request->getRequestTarget()->willReturn('/'); $this->getRequestTarget()->shouldReturn('/'); } - function it_accepts_a_request_target(RequestInterface $request, RequestInterface $newRequest) + public function it_accepts_a_request_target(RequestInterface $request, RequestInterface $newRequest) { $request->withRequestTarget('/')->willReturn($newRequest); @@ -57,14 +56,14 @@ function it_accepts_a_request_target(RequestInterface $request, RequestInterface $new->getMessage()->shouldReturn($newRequest); } - function it_has_a_method(RequestInterface $request) + public function it_has_a_method(RequestInterface $request) { $request->getMethod()->willReturn('GET'); $this->getMethod()->shouldReturn('GET'); } - function it_accepts_a_method(RequestInterface $request, RequestInterface $newRequest) + public function it_accepts_a_method(RequestInterface $request, RequestInterface $newRequest) { $request->withMethod('GET')->willReturn($newRequest); @@ -72,14 +71,14 @@ function it_accepts_a_method(RequestInterface $request, RequestInterface $newReq $new->getMessage()->shouldReturn($newRequest); } - function it_has_an_uri(RequestInterface $request, UriInterface $uri) + public function it_has_an_uri(RequestInterface $request, UriInterface $uri) { $request->getUri()->willReturn($uri); $this->getUri()->shouldReturn($uri); } - function it_accepts_an_uri(RequestInterface $request, RequestInterface $newRequest, UriInterface $uri) + public function it_accepts_an_uri(RequestInterface $request, RequestInterface $newRequest, UriInterface $uri) { $request->withUri($uri, false)->willReturn($newRequest); @@ -87,12 +86,12 @@ function it_accepts_an_uri(RequestInterface $request, RequestInterface $newReque $new->getMessage()->shouldReturn($newRequest); } - function getMatchers(): array + public function getMatchers(): array { return [ 'useTrait' => function ($subject, $trait) { return class_uses($subject, $trait); - } + }, ]; } } diff --git a/spec/Decorator/ResponseDecoratorSpec.php b/spec/Decorator/ResponseDecoratorSpec.php index 587a86a..3c7798b 100644 --- a/spec/Decorator/ResponseDecoratorSpec.php +++ b/spec/Decorator/ResponseDecoratorSpec.php @@ -3,52 +3,51 @@ namespace spec\Http\Message\Decorator; use Http\Message\Decorator\ResponseDecorator; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\ResponseInterface; class ResponseDecoratorSpec extends ObjectBehavior { - function let(ResponseInterface $response) + public function let(ResponseInterface $response) { $this->beAnInstanceOf('spec\Http\Message\Decorator\ResponseDecoratorStub', [$response]); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('spec\Http\Message\Decorator\ResponseDecoratorStub'); } - function it_is_a_response() + public function it_is_a_response() { $this->shouldImplement('Psr\Http\Message\ResponseInterface'); } - function it_is_a_response_decorator() + public function it_is_a_response_decorator() { $this->shouldUseTrait('Http\Message\Decorator\ResponseDecorator'); } - function it_has_a_response() + public function it_has_a_response() { $this->getResponse()->shouldImplement('Psr\Http\Message\ResponseInterface'); } - function it_accepts_a_response(ResponseInterface $response) + public function it_accepts_a_response(ResponseInterface $response) { $new = $this->withResponse($response); $new->getResponse()->shouldReturn($response); } - function it_has_a_status_code(ResponseInterface $response) + public function it_has_a_status_code(ResponseInterface $response) { $response->getStatusCode()->willReturn(200); $this->getStatusCode()->shouldReturn(200); } - function it_accepts_a_status(ResponseInterface $response, ResponseInterface $newResponse) + public function it_accepts_a_status(ResponseInterface $response, ResponseInterface $newResponse) { $response->withStatus(200, 'OK')->willReturn($newResponse); @@ -56,19 +55,19 @@ function it_accepts_a_status(ResponseInterface $response, ResponseInterface $new $new->getMessage()->shouldReturn($newResponse); } - function it_has_a_reason_phrase(ResponseInterface $response) + public function it_has_a_reason_phrase(ResponseInterface $response) { $response->getReasonPhrase()->willReturn('OK'); $this->getReasonPhrase()->shouldReturn('OK'); } - function getMatchers(): array + public function getMatchers(): array { return [ 'useTrait' => function ($subject, $trait) { return class_uses($subject, $trait); - } + }, ]; } } diff --git a/spec/Decorator/StreamDecoratorSpec.php b/spec/Decorator/StreamDecoratorSpec.php index 7dbcaf5..46bb0d5 100644 --- a/spec/Decorator/StreamDecoratorSpec.php +++ b/spec/Decorator/StreamDecoratorSpec.php @@ -3,126 +3,125 @@ namespace spec\Http\Message\Decorator; use Http\Message\Decorator\StreamDecorator; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; +use Psr\Http\Message\StreamInterface; class StreamDecoratorSpec extends ObjectBehavior { - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beAnInstanceOf('spec\Http\Message\Decorator\StreamDecoratorStub', [$stream]); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('spec\Http\Message\Decorator\StreamDecoratorStub'); } - function it_is_a_stream_decorator() + public function it_is_a_stream_decorator() { $this->shouldUseTrait('Http\Message\Decorator\StreamDecorator'); } - function it_casts_the_stream_to_string(StreamInterface $stream) + public function it_casts_the_stream_to_string(StreamInterface $stream) { $stream->__toString()->willReturn('body'); $this->__toString()->shouldReturn('body'); } - function it_closes_the_stream(StreamInterface $stream) + public function it_closes_the_stream(StreamInterface $stream) { $stream->close()->shouldBeCalled(); $this->close(); } - function it_detaches_the_stream(StreamInterface $stream) + public function it_detaches_the_stream(StreamInterface $stream) { $stream->detach()->willReturn('detached'); $this->detach()->shouldReturn('detached'); } - function it_returns_the_size_of_the_stream(StreamInterface $stream) + public function it_returns_the_size_of_the_stream(StreamInterface $stream) { $stream->getSize()->willReturn(1234); $this->getSize()->shouldReturn(1234); } - function it_returns_the_current_position_of_the_stream(StreamInterface $stream) + public function it_returns_the_current_position_of_the_stream(StreamInterface $stream) { $stream->tell()->willReturn(0); $this->tell()->shouldReturn(0); } - function it_checks_whether_the_stream_is_eof(StreamInterface $stream) + public function it_checks_whether_the_stream_is_eof(StreamInterface $stream) { $stream->eof()->willReturn(false); $this->eof()->shouldReturn(false); } - function it_checks_whether_the_stream_is_seekable(StreamInterface $stream) + public function it_checks_whether_the_stream_is_seekable(StreamInterface $stream) { $stream->isSeekable()->willReturn(true); $this->isSeekable()->shouldReturn(true); } - function it_seeks_the_current_position_of_the_stream(StreamInterface $stream) + public function it_seeks_the_current_position_of_the_stream(StreamInterface $stream) { $stream->seek(0, SEEK_SET)->shouldBeCalled(); $this->seek(0); } - function it_rewinds_to_the_beginning_of_the_stream(StreamInterface $stream) + public function it_rewinds_to_the_beginning_of_the_stream(StreamInterface $stream) { $stream->rewind()->shouldBeCalled(); $this->rewind(); } - function it_checks_whether_the_stream_is_writable(StreamInterface $stream) + public function it_checks_whether_the_stream_is_writable(StreamInterface $stream) { $stream->isWritable()->willReturn(true); $this->isWritable()->shouldReturn(true); } - function it_writes_to_the_stream(StreamInterface $stream) + public function it_writes_to_the_stream(StreamInterface $stream) { $stream->write('body')->shouldBeCalled(); $this->write('body'); } - function it_checks_whether_the_stream_is_readable(StreamInterface $stream) + public function it_checks_whether_the_stream_is_readable(StreamInterface $stream) { $stream->isReadable()->willReturn(true); $this->isReadable()->shouldReturn(true); } - function it_reads_from_the_stream(StreamInterface $stream) + public function it_reads_from_the_stream(StreamInterface $stream) { $stream->read(4)->willReturn('body'); $this->read(4)->shouldReturn('body'); } - function it_returns_the_contents_of_the_stream(StreamInterface $stream) + public function it_returns_the_contents_of_the_stream(StreamInterface $stream) { $stream->getContents()->willReturn('body'); $this->getContents()->shouldReturn('body'); } - function it_returns_metadata_of_the_stream(StreamInterface $stream) + public function it_returns_metadata_of_the_stream(StreamInterface $stream) { $stream->getMetadata(null)->willReturn(['key' => 'value']); $stream->getMetadata('key')->willReturn('value'); @@ -133,12 +132,12 @@ function it_returns_metadata_of_the_stream(StreamInterface $stream) $this->getMetadata('key2')->shouldReturn(null); } - function getMatchers(): array + public function getMatchers(): array { return [ 'useTrait' => function ($subject, $trait) { return class_uses($subject, $trait); - } + }, ]; } } diff --git a/spec/Encoding/ChunkStreamSpec.php b/spec/Encoding/ChunkStreamSpec.php index 35b68a7..b008112 100644 --- a/spec/Encoding/ChunkStreamSpec.php +++ b/spec/Encoding/ChunkStreamSpec.php @@ -2,24 +2,24 @@ namespace spec\Http\Message\Encoding; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\StreamInterface; class ChunkStreamSpec extends ObjectBehavior { use StreamBehavior; - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beConstructedWith($stream); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Encoding\ChunkStream'); } - function it_chunks_content() + public function it_chunks_content() { $stream = new MemoryStream('This is a stream'); $this->beConstructedWith($stream, 6); @@ -27,7 +27,7 @@ function it_chunks_content() $this->getContents()->shouldReturn("10\r\nThis is a stream\r\n0\r\n\r\n"); } - function it_chunks_in_multiple() + public function it_chunks_in_multiple() { $stream = new MemoryStream('This is a stream', 6); $this->beConstructedWith($stream, 6); @@ -35,7 +35,7 @@ function it_chunks_in_multiple() $this->getContents()->shouldReturn("6\r\nThis i\r\n6\r\ns a st\r\n4\r\nream\r\n0\r\n\r\n"); } - function it_does_not_know_the_content_size() + public function it_does_not_know_the_content_size() { $stream = new MemoryStream('This is a stream'); $this->beConstructedWith($stream, 6); diff --git a/spec/Encoding/CompressStreamSpec.php b/spec/Encoding/CompressStreamSpec.php index ad58b1f..79ac873 100644 --- a/spec/Encoding/CompressStreamSpec.php +++ b/spec/Encoding/CompressStreamSpec.php @@ -2,24 +2,25 @@ namespace spec\Http\Message\Encoding; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\StreamInterface; class CompressStreamSpec extends ObjectBehavior { - use StreamBehavior, ZlibStreamBehavior; + use StreamBehavior; + use ZlibStreamBehavior; - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beConstructedWith($stream); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Encoding\CompressStream'); } - function it_reads() + public function it_reads() { $stream = new MemoryStream('This is a test stream'); $this->beConstructedWith($stream); @@ -28,7 +29,7 @@ function it_reads() $this->read(4)->shouldReturn(substr(gzcompress('This is a test stream'), 0, 4)); } - function it_gets_content() + public function it_gets_content() { $stream = new MemoryStream('This is a test stream'); $this->beConstructedWith($stream); @@ -37,7 +38,7 @@ function it_gets_content() $this->getContents()->shouldReturn(gzcompress('This is a test stream')); } - function it_does_not_know_the_content_size() + public function it_does_not_know_the_content_size() { $stream = new MemoryStream('This is a test stream'); $this->beConstructedWith($stream); diff --git a/spec/Encoding/DechunkStreamSpec.php b/spec/Encoding/DechunkStreamSpec.php index 2ef2aa2..0077f2b 100644 --- a/spec/Encoding/DechunkStreamSpec.php +++ b/spec/Encoding/DechunkStreamSpec.php @@ -2,24 +2,24 @@ namespace spec\Http\Message\Encoding; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\StreamInterface; class DechunkStreamSpec extends ObjectBehavior { use StreamBehavior; - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beConstructedWith($stream); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Encoding\DechunkStream'); } - function it_reads() + public function it_reads() { $stream = new MemoryStream("4\r\ntest\r\n4\r\ntest\r\n0\r\n\r\n\0"); $this->beConstructedWith($stream); @@ -28,7 +28,7 @@ function it_reads() $this->read(6)->shouldReturn('st'); } - function it_gets_content() + public function it_gets_content() { $stream = new MemoryStream("4\r\ntest\r\n0\r\n\r\n\0"); $this->beConstructedWith($stream); @@ -36,11 +36,11 @@ function it_gets_content() $this->getContents()->shouldReturn('test'); } - function it_does_not_know_the_content_size() - { - $stream = new MemoryStream("4\r\ntest\r\n4\r\ntest\r\n0\r\n\r\n\0"); - $this->beConstructedWith($stream); + public function it_does_not_know_the_content_size() + { + $stream = new MemoryStream("4\r\ntest\r\n4\r\ntest\r\n0\r\n\r\n\0"); + $this->beConstructedWith($stream); - $this->getSize()->shouldReturn(null); - } + $this->getSize()->shouldReturn(null); + } } diff --git a/spec/Encoding/DecompressStreamSpec.php b/spec/Encoding/DecompressStreamSpec.php index 78a5923..cee6c9a 100644 --- a/spec/Encoding/DecompressStreamSpec.php +++ b/spec/Encoding/DecompressStreamSpec.php @@ -2,24 +2,25 @@ namespace spec\Http\Message\Encoding; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\StreamInterface; class DecompressStreamSpec extends ObjectBehavior { - use StreamBehavior, ZlibStreamBehavior; + use StreamBehavior; + use ZlibStreamBehavior; - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beConstructedWith($stream); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Encoding\DecompressStream'); } - function it_reads() + public function it_reads() { // "This is a test stream" | deflate $stream = new MemoryStream(gzcompress('This is a test stream')); @@ -28,7 +29,7 @@ function it_reads() $this->read(4)->shouldReturn('This'); } - function it_gets_content() + public function it_gets_content() { // "This is a test stream" | deflate $stream = new MemoryStream(gzcompress('This is a test stream')); @@ -37,7 +38,7 @@ function it_gets_content() $this->getContents()->shouldReturn('This is a test stream'); } - function it_does_not_know_the_content_size() + public function it_does_not_know_the_content_size() { $stream = new MemoryStream(gzcompress('This is a test stream')); $this->beConstructedWith($stream); diff --git a/spec/Encoding/DeflateStreamSpec.php b/spec/Encoding/DeflateStreamSpec.php index ac6fa5a..008c58d 100644 --- a/spec/Encoding/DeflateStreamSpec.php +++ b/spec/Encoding/DeflateStreamSpec.php @@ -2,33 +2,33 @@ namespace spec\Http\Message\Encoding; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\StreamInterface; class DeflateStreamSpec extends ObjectBehavior { use StreamBehavior; - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beConstructedWith($stream); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Encoding\DeflateStream'); } - function it_reads() + public function it_reads() { $stream = new MemoryStream('This is a test stream'); $this->beConstructedWith($stream); $stream->rewind(); - $this->read(4)->shouldReturn(substr(gzdeflate('This is a test stream'),0, 4)); + $this->read(4)->shouldReturn(substr(gzdeflate('This is a test stream'), 0, 4)); } - function it_gets_content() + public function it_gets_content() { $stream = new MemoryStream('This is a test stream'); $this->beConstructedWith($stream); @@ -37,7 +37,7 @@ function it_gets_content() $this->getContents()->shouldReturn(gzdeflate('This is a test stream')); } - function it_does_not_know_the_content_size() + public function it_does_not_know_the_content_size() { $stream = new MemoryStream('This stream is a test stream'); $this->beConstructedWith($stream); diff --git a/spec/Encoding/FilteredStreamStubSpec.php b/spec/Encoding/FilteredStreamStubSpec.php index 6e6692e..dc4db8f 100644 --- a/spec/Encoding/FilteredStreamStubSpec.php +++ b/spec/Encoding/FilteredStreamStubSpec.php @@ -8,27 +8,27 @@ class FilteredStreamStubSpec extends ObjectBehavior { - function it_throws_during_instantiation_with_invalid_read_filter_options(StreamInterface $stream) + public function it_throws_during_instantiation_with_invalid_read_filter_options(StreamInterface $stream) { $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); $this->beConstructedWith($stream, 'foo'); $this->shouldThrow('RuntimeException')->duringInstantiation(); } - function it_throws_during_instantiation_with_invalid_write_filter_options(StreamInterface $stream) + public function it_throws_during_instantiation_with_invalid_write_filter_options(StreamInterface $stream) { $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); $this->beConstructedWith($stream, null, 'foo'); $this->shouldThrow('RuntimeException')->duringInstantiation(); } - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beAnInstanceOf('spec\Http\Message\Encoding\FilteredStreamStub'); $this->beConstructedWith($stream); } - function it_reads() + public function it_reads() { // "This is a test stream" | base64_encode $stream = new MemoryStream('This is a test stream'); @@ -37,7 +37,7 @@ function it_reads() $this->read(4)->shouldReturn('VGhp'); } - function it_gets_content() + public function it_gets_content() { // "This is a test stream" | base64_encode $stream = new MemoryStream('This is a test stream'); @@ -46,7 +46,7 @@ function it_gets_content() $this->getContents()->shouldReturn('VGhpcyBpcyBhIHRlc3Qgc3RyZWFt'); } - function it_does_not_know_the_content_size() + public function it_does_not_know_the_content_size() { $stream = new MemoryStream(gzencode('This is a test stream')); $this->beConstructedWith($stream); diff --git a/spec/Encoding/GzipDecodeStreamSpec.php b/spec/Encoding/GzipDecodeStreamSpec.php index e2bbee2..32ea393 100644 --- a/spec/Encoding/GzipDecodeStreamSpec.php +++ b/spec/Encoding/GzipDecodeStreamSpec.php @@ -2,24 +2,25 @@ namespace spec\Http\Message\Encoding; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\StreamInterface; class GzipDecodeStreamSpec extends ObjectBehavior { - use StreamBehavior, ZlibStreamBehavior; + use StreamBehavior; + use ZlibStreamBehavior; - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beConstructedWith($stream); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Encoding\GzipDecodeStream'); } - function it_reads() + public function it_reads() { // "This is a test stream" | deflate $stream = new MemoryStream(gzencode('This is a test stream')); @@ -28,7 +29,7 @@ function it_reads() $this->read(4)->shouldReturn('This'); } - function it_gets_content() + public function it_gets_content() { // "This is a test stream" | deflate $stream = new MemoryStream(gzencode('This is a test stream')); @@ -37,7 +38,7 @@ function it_gets_content() $this->getContents()->shouldReturn('This is a test stream'); } - function it_does_not_know_the_content_size() + public function it_does_not_know_the_content_size() { $stream = new MemoryStream(gzencode('This is a test stream')); $this->beConstructedWith($stream); diff --git a/spec/Encoding/GzipEncodeStreamSpec.php b/spec/Encoding/GzipEncodeStreamSpec.php index e750606..bcce227 100644 --- a/spec/Encoding/GzipEncodeStreamSpec.php +++ b/spec/Encoding/GzipEncodeStreamSpec.php @@ -2,33 +2,34 @@ namespace spec\Http\Message\Encoding; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\StreamInterface; class GzipEncodeStreamSpec extends ObjectBehavior { - use StreamBehavior, ZlibStreamBehavior; + use StreamBehavior; + use ZlibStreamBehavior; - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beConstructedWith($stream); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Encoding\GzipEncodeStream'); } - function it_reads() + public function it_reads() { $stream = new MemoryStream('This is a test stream'); $this->beConstructedWith($stream); $stream->rewind(); - $this->read(4)->shouldReturn(substr(gzencode('This is a test stream'),0, 4)); + $this->read(4)->shouldReturn(substr(gzencode('This is a test stream'), 0, 4)); } - function it_gets_content() + public function it_gets_content() { $stream = new MemoryStream('This is a test stream'); $this->beConstructedWith($stream); @@ -37,7 +38,7 @@ function it_gets_content() $this->getContents()->shouldReturn(gzencode('This is a test stream')); } - function it_does_not_know_the_content_size() + public function it_does_not_know_the_content_size() { $stream = new MemoryStream('This is a test stream'); $this->beConstructedWith($stream); diff --git a/spec/Encoding/InflateStreamSpec.php b/spec/Encoding/InflateStreamSpec.php index 32e094e..f61ff84 100644 --- a/spec/Encoding/InflateStreamSpec.php +++ b/spec/Encoding/InflateStreamSpec.php @@ -2,24 +2,25 @@ namespace spec\Http\Message\Encoding; -use Psr\Http\Message\StreamInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\StreamInterface; class InflateStreamSpec extends ObjectBehavior { - use StreamBehavior, ZlibStreamBehavior; + use StreamBehavior; + use ZlibStreamBehavior; - function let(StreamInterface $stream) + public function let(StreamInterface $stream) { $this->beConstructedWith($stream); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Encoding\InflateStream'); } - function it_reads() + public function it_reads() { // "This is a test stream" | deflate $stream = new MemoryStream(gzdeflate('This is a test stream')); @@ -28,7 +29,7 @@ function it_reads() $this->read(4)->shouldReturn('This'); } - function it_gets_content() + public function it_gets_content() { // "This is a test stream" | deflate $stream = new MemoryStream(gzdeflate('This is a test stream')); @@ -37,7 +38,7 @@ function it_gets_content() $this->getContents()->shouldReturn('This is a test stream'); } - function it_does_not_know_the_content_size() + public function it_does_not_know_the_content_size() { $stream = new MemoryStream(gzdeflate('This stream is a test stream')); $this->beConstructedWith($stream); diff --git a/spec/Encoding/MemoryStream.php b/spec/Encoding/MemoryStream.php index afedd2b..72acab7 100644 --- a/spec/Encoding/MemoryStream.php +++ b/spec/Encoding/MemoryStream.php @@ -12,7 +12,7 @@ class MemoryStream implements StreamInterface private $chunkSize; - public function __construct($body = "", $chunkSize = 8192) + public function __construct($body = '', $chunkSize = 8192) { $this->size = strlen($body); $this->resource = fopen('php://memory', 'rw+'); diff --git a/spec/Encoding/StreamBehavior.php b/spec/Encoding/StreamBehavior.php index 54e1f5e..5834a03 100644 --- a/spec/Encoding/StreamBehavior.php +++ b/spec/Encoding/StreamBehavior.php @@ -4,7 +4,7 @@ trait StreamBehavior { - function it_is_a_stream() + public function it_is_a_stream() { $this->shouldImplement('Psr\Http\Message\StreamInterface'); } diff --git a/spec/Encoding/ZlibStreamBehavior.php b/spec/Encoding/ZlibStreamBehavior.php index 6f1d298..39dce20 100644 --- a/spec/Encoding/ZlibStreamBehavior.php +++ b/spec/Encoding/ZlibStreamBehavior.php @@ -1,10 +1,9 @@ shouldHaveType('Http\Message\Formatter\CurlCommandFormatter'); } - function it_is_a_formatter() + public function it_is_a_formatter() { $this->shouldImplement('Http\Message\Formatter'); } - function it_formats_the_request(RequestInterface $request, UriInterface $uri, StreamInterface $body) + public function it_formats_the_request(RequestInterface $request, UriInterface $uri, StreamInterface $body) { $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); @@ -29,13 +29,13 @@ function it_formats_the_request(RequestInterface $request, UriInterface $uri, St $request->getMethod()->willReturn('GET'); $request->getProtocolVersion()->willReturn('1.1'); - $request->getHeaders()->willReturn(['foo'=>['bar', 'baz']]); + $request->getHeaders()->willReturn(['foo' => ['bar', 'baz']]); $request->getHeaderLine('foo')->willReturn('bar, baz'); $this->formatRequest($request)->shouldReturn('curl \'http://foo.com/bar\' -H \'foo: bar, baz\''); } - function it_formats_post_request(RequestInterface $request, UriInterface $uri, StreamInterface $body) + public function it_formats_post_request(RequestInterface $request, UriInterface $uri, StreamInterface $body) { $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); @@ -54,13 +54,13 @@ function it_formats_post_request(RequestInterface $request, UriInterface $uri, S $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --http2 --request POST --data 'body \" data test'\'' bar'"); } - function it_does_nothing_for_response(ResponseInterface $response, RequestInterface $request) + public function it_does_nothing_for_response(ResponseInterface $response, RequestInterface $request) { $this->formatResponse($response)->shouldReturn(''); $this->formatResponseForRequest($response, $request)->shouldReturn(''); } - function it_formats_the_request_with_user_agent(RequestInterface $request, UriInterface $uri, StreamInterface $body) + public function it_formats_the_request_with_user_agent(RequestInterface $request, UriInterface $uri, StreamInterface $body) { $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); @@ -69,12 +69,12 @@ function it_formats_the_request_with_user_agent(RequestInterface $request, UriIn $request->getMethod()->willReturn('GET'); $request->getProtocolVersion()->willReturn('1.1'); $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); - $request->getHeaders()->willReturn(['user-agent'=>['foobar-browser']]); + $request->getHeaders()->willReturn(['user-agent' => ['foobar-browser']]); $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' -A 'foobar-browser'"); } - function it_formats_requests_with_null_bytes(RequestInterface $request, UriInterface $uri, StreamInterface $body) + public function it_formats_requests_with_null_bytes(RequestInterface $request, UriInterface $uri, StreamInterface $body) { $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); @@ -92,7 +92,7 @@ function it_formats_requests_with_null_bytes(RequestInterface $request, UriInter $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[binary stream omitted]'"); } - function it_formats_requests_with_line_break(RequestInterface $request, UriInterface $uri, StreamInterface $body) + public function it_formats_requests_with_line_break(RequestInterface $request, UriInterface $uri, StreamInterface $body) { $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); @@ -110,7 +110,7 @@ function it_formats_requests_with_line_break(RequestInterface $request, UriInter $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data 'foo\nbar'"); } - function it_formats_requests_with_nonseekable_body(RequestInterface $request, UriInterface $uri, StreamInterface $body) + public function it_formats_requests_with_nonseekable_body(RequestInterface $request, UriInterface $uri, StreamInterface $body) { $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); @@ -128,7 +128,7 @@ function it_formats_requests_with_nonseekable_body(RequestInterface $request, Ur $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[non-seekable stream omitted]'"); } - function it_formats_requests_with_long_body(RequestInterface $request, UriInterface $uri, StreamInterface $body) + public function it_formats_requests_with_long_body(RequestInterface $request, UriInterface $uri, StreamInterface $body) { $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); diff --git a/spec/Formatter/FullHttpMessageFormatterSpec.php b/spec/Formatter/FullHttpMessageFormatterSpec.php index 33f83f6..e5fa362 100644 --- a/spec/Formatter/FullHttpMessageFormatterSpec.php +++ b/spec/Formatter/FullHttpMessageFormatterSpec.php @@ -9,22 +9,22 @@ class FullHttpMessageFormatterSpec extends ObjectBehavior { - function let($maxBodyLength) + public function let($maxBodyLength) { $this->beConstructedWith($maxBodyLength); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Formatter\FullHttpMessageFormatter'); } - function it_is_a_formatter() + public function it_is_a_formatter() { $this->shouldImplement('Http\Message\Formatter'); } - function it_formats_the_request_with_size_limit(RequestInterface $request, StreamInterface $stream) + public function it_formats_the_request_with_size_limit(RequestInterface $request, StreamInterface $stream) { $this->beConstructedWith(18); @@ -50,7 +50,7 @@ function it_formats_the_request_with_size_limit(RequestInterface $request, Strea $this->formatRequest($request)->shouldReturn($expectedMessage); } - function it_formats_the_request_without_size_limit(RequestInterface $request, StreamInterface $stream) + public function it_formats_the_request_without_size_limit(RequestInterface $request, StreamInterface $stream) { $this->beConstructedWith(null); @@ -76,7 +76,7 @@ function it_formats_the_request_without_size_limit(RequestInterface $request, St $this->formatRequest($request)->shouldReturn($expectedMessage); } - function it_does_not_format_the_request(RequestInterface $request, StreamInterface $stream) + public function it_does_not_format_the_request(RequestInterface $request, StreamInterface $stream) { $this->beConstructedWith(0); @@ -101,7 +101,7 @@ function it_does_not_format_the_request(RequestInterface $request, StreamInterfa $this->formatRequest($request)->shouldReturn($expectedMessage); } - function it_does_not_format_no_seekable_request(RequestInterface $request, StreamInterface $stream) + public function it_does_not_format_no_seekable_request(RequestInterface $request, StreamInterface $stream) { $this->beConstructedWith(1000); @@ -126,7 +126,7 @@ function it_does_not_format_no_seekable_request(RequestInterface $request, Strea $this->formatRequest($request)->shouldReturn($expectedMessage); } - function it_formats_the_response_with_size_limit(ResponseInterface $response, StreamInterface $stream, RequestInterface $request) + public function it_formats_the_response_with_size_limit(ResponseInterface $response, StreamInterface $stream, RequestInterface $request) { $this->beConstructedWith(18); @@ -153,7 +153,7 @@ function it_formats_the_response_with_size_limit(ResponseInterface $response, St $this->formatResponseForRequest($response, $request)->shouldReturn($expectedMessage); } - function it_formats_the_response_without_size_limit(ResponseInterface $response, StreamInterface $stream) + public function it_formats_the_response_without_size_limit(ResponseInterface $response, StreamInterface $stream) { $this->beConstructedWith(null); @@ -179,7 +179,7 @@ function it_formats_the_response_without_size_limit(ResponseInterface $response, $this->formatResponse($response)->shouldReturn($expectedMessage); } - function it_does_not_format_the_response(ResponseInterface $response, StreamInterface $stream) + public function it_does_not_format_the_response(ResponseInterface $response, StreamInterface $stream) { $this->beConstructedWith(0); @@ -204,7 +204,7 @@ function it_does_not_format_the_response(ResponseInterface $response, StreamInte $this->formatResponse($response)->shouldReturn($expectedMessage); } - function it_does_not_format_no_seekable_response(ResponseInterface $response, StreamInterface $stream) + public function it_does_not_format_no_seekable_response(ResponseInterface $response, StreamInterface $stream) { $this->beConstructedWith(1000); @@ -229,7 +229,7 @@ function it_does_not_format_no_seekable_response(ResponseInterface $response, St $this->formatResponse($response)->shouldReturn($expectedMessage); } - function it_omits_body_with_null_bytes(RequestInterface $request, StreamInterface $stream) + public function it_omits_body_with_null_bytes(RequestInterface $request, StreamInterface $stream) { $this->beConstructedWith(1); @@ -250,7 +250,7 @@ function it_omits_body_with_null_bytes(RequestInterface $request, StreamInterfac $this->formatRequest($request)->shouldReturn($expectedMessage); } - function it_allows_to_change_binary_detection(RequestInterface $request, StreamInterface $stream) + public function it_allows_to_change_binary_detection(RequestInterface $request, StreamInterface $stream) { $this->beConstructedWith(1, '/\x01/'); @@ -271,7 +271,7 @@ function it_allows_to_change_binary_detection(RequestInterface $request, StreamI $this->formatRequest($request)->shouldReturn($expectedMessage); } - function it_omits_body_with_line_break(RequestInterface $request, StreamInterface $stream) + public function it_omits_body_with_line_break(RequestInterface $request, StreamInterface $stream) { $this->beConstructedWith(7); diff --git a/spec/Formatter/SimpleFormatterSpec.php b/spec/Formatter/SimpleFormatterSpec.php index 9c44d67..c8fc5cf 100644 --- a/spec/Formatter/SimpleFormatterSpec.php +++ b/spec/Formatter/SimpleFormatterSpec.php @@ -2,24 +2,24 @@ namespace spec\Http\Message\Formatter; +use PhpSpec\ObjectBehavior; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\UriInterface; -use PhpSpec\ObjectBehavior; class SimpleFormatterSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\Formatter\SimpleFormatter'); } - function it_is_a_formatter() + public function it_is_a_formatter() { $this->shouldImplement('Http\Message\Formatter'); } - function it_formats_the_request(RequestInterface $request, UriInterface $uri) + public function it_formats_the_request(RequestInterface $request, UriInterface $uri) { $uri->__toString()->willReturn('http://foo.com/bar'); $request->getMethod()->willReturn('GET'); @@ -29,7 +29,7 @@ function it_formats_the_request(RequestInterface $request, UriInterface $uri) $this->formatRequest($request)->shouldReturn('GET http://foo.com/bar 1.1'); } - function it_formats_the_response(ResponseInterface $response, RequestInterface $request) + public function it_formats_the_response(ResponseInterface $response, RequestInterface $request) { $response->getReasonPhrase()->willReturn('OK'); $response->getProtocolVersion()->willReturn('1.1'); diff --git a/spec/MessageFactory/DiactorosMessageFactorySpec.php b/spec/MessageFactory/DiactorosMessageFactorySpec.php index 8dea0ad..89cffb3 100644 --- a/spec/MessageFactory/DiactorosMessageFactorySpec.php +++ b/spec/MessageFactory/DiactorosMessageFactorySpec.php @@ -8,7 +8,7 @@ class DiactorosMessageFactorySpec extends ObjectBehavior { use MessageFactoryBehavior; - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\MessageFactory\DiactorosMessageFactory'); } diff --git a/spec/MessageFactory/GuzzleMessageFactorySpec.php b/spec/MessageFactory/GuzzleMessageFactorySpec.php index f885555..be7de66 100644 --- a/spec/MessageFactory/GuzzleMessageFactorySpec.php +++ b/spec/MessageFactory/GuzzleMessageFactorySpec.php @@ -8,7 +8,7 @@ class GuzzleMessageFactorySpec extends ObjectBehavior { use MessageFactoryBehavior; - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\MessageFactory\GuzzleMessageFactory'); } diff --git a/spec/MessageFactory/MessageFactoryBehavior.php b/spec/MessageFactory/MessageFactoryBehavior.php index 1c7a50d..42c51ae 100644 --- a/spec/MessageFactory/MessageFactoryBehavior.php +++ b/spec/MessageFactory/MessageFactoryBehavior.php @@ -4,12 +4,12 @@ trait MessageFactoryBehavior { - function it_is_a_message_factory() + public function it_is_a_message_factory() { $this->shouldImplement('Http\Message\MessageFactory'); } - function it_creates_a_request() + public function it_creates_a_request() { $request = $this->createRequest('GET', '/', ['X-hello' => 'world'], 'lorem'); @@ -20,7 +20,7 @@ function it_creates_a_request() $request->getHeaderLine('X-hello')->shouldReturn('world'); } - function it_creates_a_response() + public function it_creates_a_response() { $response = $this->createResponse(); diff --git a/spec/MessageFactory/SlimMessageFactorySpec.php b/spec/MessageFactory/SlimMessageFactorySpec.php index e39452e..b549a55 100644 --- a/spec/MessageFactory/SlimMessageFactorySpec.php +++ b/spec/MessageFactory/SlimMessageFactorySpec.php @@ -11,7 +11,7 @@ class SlimMessageFactorySpec extends ObjectBehavior { use MessageFactoryBehavior; - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\MessageFactory\SlimMessageFactory'); } diff --git a/spec/RequestMatcher/CallbackRequestMatcherSpec.php b/spec/RequestMatcher/CallbackRequestMatcherSpec.php index 6aa27df..fbf12a5 100644 --- a/spec/RequestMatcher/CallbackRequestMatcherSpec.php +++ b/spec/RequestMatcher/CallbackRequestMatcherSpec.php @@ -3,27 +3,26 @@ namespace spec\Http\Message\RequestMatcher; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; use Psr\Http\Message\RequestInterface; class CallbackRequestMatcherSpec extends ObjectBehavior { - function let() + public function let() { $this->beConstructedWith(function () {}); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\RequestMatcher\CallbackRequestMatcher'); } - function it_is_a_request_matcher() + public function it_is_a_request_matcher() { $this->shouldImplement('Http\Message\RequestMatcher'); } - function it_matches_a_request(RequestInterface $request) + public function it_matches_a_request(RequestInterface $request) { $callback = function () { return true; }; @@ -32,7 +31,7 @@ function it_matches_a_request(RequestInterface $request) $this->matches($request)->shouldReturn(true); } - function it_does_not_match_a_request(RequestInterface $request) + public function it_does_not_match_a_request(RequestInterface $request) { $callback = function () { return false; }; diff --git a/spec/RequestMatcher/RegexRequestMatcherSpec.php b/spec/RequestMatcher/RegexRequestMatcherSpec.php index e6e2c28..9f1dc7a 100644 --- a/spec/RequestMatcher/RegexRequestMatcherSpec.php +++ b/spec/RequestMatcher/RegexRequestMatcherSpec.php @@ -2,29 +2,28 @@ namespace spec\Http\Message\RequestMatcher; -use Http\Message\RequestMatcher; +use PhpSpec\ObjectBehavior; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; -use PhpSpec\ObjectBehavior; class RegexRequestMatcherSpec extends ObjectBehavior { - function let($regex) + public function let($regex) { $this->beConstructedWith($regex); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\RequestMatcher\RegexRequestMatcher'); } - function it_is_a_request_matcher() + public function it_is_a_request_matcher() { $this->shouldImplement('Http\Message\RequestMatcher'); } - function it_matches_a_request(RequestInterface $request, UriInterface $uri) + public function it_matches_a_request(RequestInterface $request, UriInterface $uri) { $this->beConstructedWith('/test/'); @@ -34,7 +33,7 @@ function it_matches_a_request(RequestInterface $request, UriInterface $uri) $this->matches($request)->shouldReturn(true); } - function it_does_not_match_a_request(RequestInterface $request, UriInterface $uri) + public function it_does_not_match_a_request(RequestInterface $request, UriInterface $uri) { $this->beConstructedWith('/test/'); diff --git a/spec/RequestMatcher/RequestMatcherSpec.php b/spec/RequestMatcher/RequestMatcherSpec.php index 6ea1f92..0a000f1 100644 --- a/spec/RequestMatcher/RequestMatcherSpec.php +++ b/spec/RequestMatcher/RequestMatcherSpec.php @@ -2,24 +2,23 @@ namespace spec\Http\Message\RequestMatcher; -use Http\Message\RequestMatcher; +use PhpSpec\ObjectBehavior; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; -use PhpSpec\ObjectBehavior; class RequestMatcherSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\RequestMatcher\RequestMatcher'); } - function it_is_a_request_matcher() + public function it_is_a_request_matcher() { $this->shouldImplement('Http\Message\RequestMatcher'); } - function it_matches_a_path(RequestInterface $request, UriInterface $uri) + public function it_matches_a_path(RequestInterface $request, UriInterface $uri) { $this->beConstructedWith('^/tes?'); @@ -29,7 +28,7 @@ function it_matches_a_path(RequestInterface $request, UriInterface $uri) $this->matches($request)->shouldReturn(true); } - function it_does_not_match_a_path(RequestInterface $request, UriInterface $uri) + public function it_does_not_match_a_path(RequestInterface $request, UriInterface $uri) { $this->beConstructedWith('#^/tes?#'); @@ -39,8 +38,7 @@ function it_does_not_match_a_path(RequestInterface $request, UriInterface $uri) $this->matches($request)->shouldReturn(false); } - - function it_matches_a_host(RequestInterface $request, UriInterface $uri) + public function it_matches_a_host(RequestInterface $request, UriInterface $uri) { $this->beConstructedWith(null, 'php-htt?'); @@ -50,7 +48,7 @@ function it_matches_a_host(RequestInterface $request, UriInterface $uri) $this->matches($request)->shouldReturn(true); } - function it_does_not_match_a_host(RequestInterface $request, UriInterface $uri) + public function it_does_not_match_a_host(RequestInterface $request, UriInterface $uri) { $this->beConstructedWith(null, 'php-htt?'); @@ -60,7 +58,7 @@ function it_does_not_match_a_host(RequestInterface $request, UriInterface $uri) $this->matches($request)->shouldReturn(false); } - function it_matches_a_method(RequestInterface $request) + public function it_matches_a_method(RequestInterface $request) { $this->beConstructedWith(null, null, 'get'); @@ -69,7 +67,7 @@ function it_matches_a_method(RequestInterface $request) $this->matches($request)->shouldReturn(true); } - function it_does_not_match_a_method(RequestInterface $request) + public function it_does_not_match_a_method(RequestInterface $request) { $this->beConstructedWith(null, null, 'get'); @@ -78,8 +76,7 @@ function it_does_not_match_a_method(RequestInterface $request) $this->matches($request)->shouldReturn(false); } - - function it_matches_a_scheme(RequestInterface $request, UriInterface $uri) + public function it_matches_a_scheme(RequestInterface $request, UriInterface $uri) { $this->beConstructedWith(null, null, null, 'http'); @@ -89,7 +86,7 @@ function it_matches_a_scheme(RequestInterface $request, UriInterface $uri) $this->matches($request)->shouldReturn(true); } - function it_does_not_match_a_scheme(RequestInterface $request, UriInterface $uri) + public function it_does_not_match_a_scheme(RequestInterface $request, UriInterface $uri) { $this->beConstructedWith(null, null, null, 'http'); diff --git a/spec/Stream/BufferedStreamSpec.php b/spec/Stream/BufferedStreamSpec.php index c1cbba6..f80fa69 100644 --- a/spec/Stream/BufferedStreamSpec.php +++ b/spec/Stream/BufferedStreamSpec.php @@ -17,8 +17,8 @@ public function let(StreamInterface $stream) public function it_is_castable_to_string(StreamInterface $stream) { $eofCounter = 0; - $stream->eof()->will(function () use(&$eofCounter) { - return (++$eofCounter > 1); + $stream->eof()->will(function () use (&$eofCounter) { + return ++$eofCounter > 1; }); $stream->read(8192)->willReturn('foo'); @@ -42,8 +42,8 @@ public function it_gets_size(StreamInterface $stream) $this->getSize()->shouldReturn(null); $eofCounter = 0; - $stream->eof()->will(function () use(&$eofCounter) { - return (++$eofCounter > 1); + $stream->eof()->will(function () use (&$eofCounter) { + return ++$eofCounter > 1; }); $stream->read(8192)->willReturn('foo'); @@ -57,8 +57,8 @@ public function it_tells(StreamInterface $stream) $this->tell()->shouldReturn(0); $eofCounter = 0; - $stream->eof()->will(function () use(&$eofCounter) { - return (++$eofCounter > 1); + $stream->eof()->will(function () use (&$eofCounter) { + return ++$eofCounter > 1; }); $stream->read(8192)->willReturn('foo'); @@ -78,8 +78,8 @@ public function it_eof(StreamInterface $stream) // Case not sync but underlying is true $eofCounter = 0; - $stream->eof()->will(function () use(&$eofCounter) { - return (++$eofCounter > 1); + $stream->eof()->will(function () use (&$eofCounter) { + return ++$eofCounter > 1; }); $stream->read(8192)->willReturn('foo'); @@ -102,8 +102,8 @@ public function it_seeks(StreamInterface $stream) $this->tell()->shouldReturn(0); $eofCounter = 0; - $stream->eof()->will(function () use(&$eofCounter) { - return (++$eofCounter > 1); + $stream->eof()->will(function () use (&$eofCounter) { + return ++$eofCounter > 1; }); $stream->read(8192)->willReturn('foo'); @@ -119,8 +119,8 @@ public function it_rewinds(StreamInterface $stream) $this->tell()->shouldReturn(0); $eofCounter = 0; - $stream->eof()->will(function () use(&$eofCounter) { - return (++$eofCounter > 1); + $stream->eof()->will(function () use (&$eofCounter) { + return ++$eofCounter > 1; }); $stream->read(8192)->willReturn('foo'); @@ -145,8 +145,8 @@ public function it_is_readable(StreamInterface $stream) public function it_reads(StreamInterface $stream) { $eofCounter = 0; - $stream->eof()->will(function () use(&$eofCounter) { - return (++$eofCounter > 1); + $stream->eof()->will(function () use (&$eofCounter) { + return ++$eofCounter > 1; }); $stream->read(3)->willReturn('foo'); @@ -165,8 +165,8 @@ public function it_reads(StreamInterface $stream) public function it_get_contents(StreamInterface $stream) { $eofCounter = 0; - $stream->eof()->will(function () use(&$eofCounter) { - return (++$eofCounter > 1); + $stream->eof()->will(function () use (&$eofCounter) { + return ++$eofCounter > 1; }); $stream->read(8192)->willReturn('foo'); diff --git a/spec/StreamFactory/DiactorosStreamFactorySpec.php b/spec/StreamFactory/DiactorosStreamFactorySpec.php index dbf6927..f7da767 100644 --- a/spec/StreamFactory/DiactorosStreamFactorySpec.php +++ b/spec/StreamFactory/DiactorosStreamFactorySpec.php @@ -9,12 +9,12 @@ class DiactorosStreamFactorySpec extends ObjectBehavior { use StreamFactoryBehavior; - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\StreamFactory\DiactorosStreamFactory'); } - function it_creates_a_stream_from_stream() + public function it_creates_a_stream_from_stream() { $this->createStream(new Stream('php://memory')) ->shouldHaveType('Psr\Http\Message\StreamInterface'); diff --git a/spec/StreamFactory/SlimStreamFactorySpec.php b/spec/StreamFactory/SlimStreamFactorySpec.php index c3bfef3..308f739 100644 --- a/spec/StreamFactory/SlimStreamFactorySpec.php +++ b/spec/StreamFactory/SlimStreamFactorySpec.php @@ -2,8 +2,8 @@ namespace spec\Http\Message\StreamFactory; -use Slim\Http\Stream; use PhpSpec\ObjectBehavior; +use Slim\Http\Stream; /** * @require Slim\Http\Stream @@ -12,12 +12,12 @@ class SlimStreamFactorySpec extends ObjectBehavior { use StreamFactoryBehavior; - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\StreamFactory\SlimStreamFactory'); } - function it_creates_a_stream_from_stream() + public function it_creates_a_stream_from_stream() { $resource = fopen('php://memory', 'rw'); $this->createStream(new Stream($resource)) diff --git a/spec/StreamFactory/StreamFactoryBehavior.php b/spec/StreamFactory/StreamFactoryBehavior.php index 05447d8..5a4953c 100644 --- a/spec/StreamFactory/StreamFactoryBehavior.php +++ b/spec/StreamFactory/StreamFactoryBehavior.php @@ -7,28 +7,28 @@ trait StreamFactoryBehavior { - function it_is_a_stream_factory() + public function it_is_a_stream_factory() { $this->shouldImplement('Http\Message\StreamFactory'); } - function it_creates_a_stream_from_string() + public function it_creates_a_stream_from_string() { $this->createStream('foo')->shouldHaveType('Psr\Http\Message\StreamInterface'); } - function it_creates_a_stream_from_resource() + public function it_creates_a_stream_from_resource() { $this->createStream(fopen('php://memory', 'rw')) ->shouldHaveType('Psr\Http\Message\StreamInterface'); } - function it_creates_a_stream_from_null() + public function it_creates_a_stream_from_null() { $this->createStream(null)->shouldHaveType('Psr\Http\Message\StreamInterface'); } - function it_creates_a_stream_from_non_seekable_resource() + public function it_creates_a_stream_from_non_seekable_resource() { $url = 'https://raw.githubusercontent.com/php-http/multipart-stream-builder/master/tests/Resources/httplug.png'; $resource = fopen($url, 'r'); @@ -36,7 +36,7 @@ function it_creates_a_stream_from_non_seekable_resource() ->shouldHaveType('Psr\Http\Message\StreamInterface'); } - function it_does_not_rewind_existing_stream() + public function it_does_not_rewind_existing_stream() { $stream = new Stream(fopen('php://memory', 'rw')); $stream->write('abcdef'); @@ -46,7 +46,7 @@ function it_does_not_rewind_existing_stream() ->shouldHaveContent('def'); } - function it_does_not_rewind_existing_resource() + public function it_does_not_rewind_existing_resource() { $resource = fopen('php://memory', 'rw'); fwrite($resource, 'abcdef'); diff --git a/spec/UriFactory/DiactorosUriFactorySpec.php b/spec/UriFactory/DiactorosUriFactorySpec.php index 823ad3c..d362dcd 100644 --- a/spec/UriFactory/DiactorosUriFactorySpec.php +++ b/spec/UriFactory/DiactorosUriFactorySpec.php @@ -2,22 +2,22 @@ namespace spec\Http\Message\UriFactory; -use Psr\Http\Message\UriInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\UriInterface; class DiactorosUriFactorySpec extends ObjectBehavior { use UriFactoryBehavior; - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\UriFactory\DiactorosUriFactory'); } /** - * TODO: Remove this when https://github.com/phpspec/phpspec/issues/825 is resolved + * TODO: Remove this when https://github.com/phpspec/phpspec/issues/825 is resolved. */ - function it_creates_a_uri_from_uri(UriInterface $uri) + public function it_creates_a_uri_from_uri(UriInterface $uri) { $this->createUri($uri)->shouldReturn($uri); } diff --git a/spec/UriFactory/GuzzleUriFactorySpec.php b/spec/UriFactory/GuzzleUriFactorySpec.php index 3cb19f5..a9b5510 100644 --- a/spec/UriFactory/GuzzleUriFactorySpec.php +++ b/spec/UriFactory/GuzzleUriFactorySpec.php @@ -2,22 +2,22 @@ namespace spec\Http\Message\UriFactory; -use Psr\Http\Message\UriInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\UriInterface; class GuzzleUriFactorySpec extends ObjectBehavior { use UriFactoryBehavior; - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\UriFactory\GuzzleUriFactory'); } /** - * TODO: Remove this when https://github.com/phpspec/phpspec/issues/825 is resolved + * TODO: Remove this when https://github.com/phpspec/phpspec/issues/825 is resolved. */ - function it_creates_a_uri_from_uri(UriInterface $uri) + public function it_creates_a_uri_from_uri(UriInterface $uri) { $this->createUri($uri)->shouldReturn($uri); } diff --git a/spec/UriFactory/SlimUriFactorySpec.php b/spec/UriFactory/SlimUriFactorySpec.php index b373f5f..a486625 100644 --- a/spec/UriFactory/SlimUriFactorySpec.php +++ b/spec/UriFactory/SlimUriFactorySpec.php @@ -2,8 +2,8 @@ namespace spec\Http\Message\UriFactory; -use Psr\Http\Message\UriInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\UriInterface; /** * @require Slim\Http\Uri @@ -12,15 +12,15 @@ class SlimUriFactorySpec extends ObjectBehavior { use UriFactoryBehavior; - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Http\Message\UriFactory\SlimUriFactory'); } /** - * TODO: Remove this when https://github.com/phpspec/phpspec/issues/825 is resolved + * TODO: Remove this when https://github.com/phpspec/phpspec/issues/825 is resolved. */ - function it_creates_a_uri_from_uri(UriInterface $uri) + public function it_creates_a_uri_from_uri(UriInterface $uri) { $this->createUri($uri)->shouldReturn($uri); } diff --git a/spec/UriFactory/UriFactoryBehavior.php b/spec/UriFactory/UriFactoryBehavior.php index bb2aeda..f7116bc 100644 --- a/spec/UriFactory/UriFactoryBehavior.php +++ b/spec/UriFactory/UriFactoryBehavior.php @@ -6,22 +6,22 @@ trait UriFactoryBehavior { - function it_is_a_uri_factory() + public function it_is_a_uri_factory() { $this->shouldImplement('Http\Message\UriFactory'); } - function it_creates_a_uri_from_string() + public function it_creates_a_uri_from_string() { $this->createUri('http://php-http.org')->shouldHaveType('Psr\Http\Message\UriInterface'); } - function it_creates_a_uri_from_uri(UriInterface $uri) + public function it_creates_a_uri_from_uri(UriInterface $uri) { $this->createUri($uri)->shouldReturn($uri); } - function it_throws_an_exception_when_uri_is_invalid() + public function it_throws_an_exception_when_uri_is_invalid() { $this->shouldThrow('InvalidArgumentException')->duringCreateUri(null); } diff --git a/src/Authentication/Wsse.php b/src/Authentication/Wsse.php index f343633..88c266b 100644 --- a/src/Authentication/Wsse.php +++ b/src/Authentication/Wsse.php @@ -3,7 +3,6 @@ namespace Http\Message\Authentication; use Http\Message\Authentication; -use InvalidArgumentException; use Psr\Http\Message\RequestInterface; /** @@ -38,7 +37,7 @@ public function __construct($username, $password, $hashAlgorithm = 'sha1') $this->username = $username; $this->password = $password; if (false === in_array($hashAlgorithm, hash_algos())) { - throw new InvalidArgumentException(sprintf('Unaccepted hashing algorithm: %s', $hashAlgorithm)); + throw new \InvalidArgumentException(sprintf('Unaccepted hashing algorithm: %s', $hashAlgorithm)); } $this->hashAlgorithm = $hashAlgorithm; } diff --git a/src/Cookie.php b/src/Cookie.php index 0cc2d43..c6eaf51 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -399,8 +399,6 @@ public function withHttpOnly($httpOnly) * * This does not compare the values, only name, domain and path. * - * @param Cookie $cookie - * * @return bool */ public function match(self $cookie) diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index a937c82..a6aec25 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -17,7 +17,7 @@ abstract class FilteredStream implements StreamInterface rewind as private doRewind; seek as private doSeek; } - const BUFFER_SIZE = 8192; + public const BUFFER_SIZE = 8192; /** * @var callable diff --git a/src/UriFactory/GuzzleUriFactory.php b/src/UriFactory/GuzzleUriFactory.php index e09ac61..77989af 100644 --- a/src/UriFactory/GuzzleUriFactory.php +++ b/src/UriFactory/GuzzleUriFactory.php @@ -2,10 +2,11 @@ namespace Http\Message\UriFactory; -use function GuzzleHttp\Psr7\uri_for; use GuzzleHttp\Psr7\Utils; use Http\Message\UriFactory; +use function GuzzleHttp\Psr7\uri_for; + /** * Creates Guzzle URI. * From 68750d6e225b05747aa65cc0066a85eac71cde33 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 14 Apr 2023 16:02:43 +0200 Subject: [PATCH 111/132] phpstan cleanup --- .github/workflows/static.yml | 2 +- phpstan-baseline.neon | 20 +++++--------------- phpstan.neon.dist | 5 +++++ src/CookieJar.php | 2 +- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 93d1956..7d7c8cf 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -33,4 +33,4 @@ jobs: - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga with: - args: --dry-run --diff-format udiff + args: --dry-run --diff diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 065b358..226065a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -80,11 +80,6 @@ parameters: count: 1 path: src/CookieJar.php - - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:findMatchingCookies\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:setCookies\\(\\) has no return type specified\\.$#" count: 1 @@ -115,11 +110,6 @@ parameters: count: 1 path: src/CookieJar.php - - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:getIterator\\(\\) return type has no value type specified in iterable type Traversable\\\\.$#" - count: 1 - path: src/CookieJar.php - - message: "#^Property Http\\\\Message\\\\CookieUtil\\:\\:\\$dateFormats type has no value type specified in iterable type array\\.$#" count: 1 @@ -130,11 +120,6 @@ parameters: count: 1 path: src/Encoding/ChunkStream.php - - - message: "#^Access to an undefined property object\\:\\:\\$datalen\\.$#" - count: 2 - path: src/Encoding/Filter/Chunk.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return type specified\\.$#" count: 1 @@ -264,3 +249,8 @@ parameters: message: "#^Unreachable statement \\- code above always terminates\\.$#" count: 1 path: src/UriFactory/SlimUriFactory.php + + - + message: "#^Call to function array_key_exists\\(\\) with 'chunk' and array will always evaluate to false\\.$#" + count: 1 + path: src/filters.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6f8227f..6355eac 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,3 +5,8 @@ parameters: level: max paths: - src + excludePaths: + analyse: + - %currentWorkingDirectory%/src/MessageFactory/* + - %currentWorkingDirectory%/src/StreamFactory/* + - %currentWorkingDirectory%/src/UriFactory/* diff --git a/src/CookieJar.php b/src/CookieJar.php index 914ad97..165084d 100644 --- a/src/CookieJar.php +++ b/src/CookieJar.php @@ -10,7 +10,7 @@ final class CookieJar implements \Countable, \IteratorAggregate { /** - * @var \SplObjectStorage + * @var \SplObjectStorage */ private $cookies; From 9682dadbe109c254998800ad285330f162a38857 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 14 Apr 2023 16:05:49 +0200 Subject: [PATCH 112/132] drop broken roave-bc-check --- .github/workflows/checks.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index eeb7320..89bec76 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -17,14 +17,3 @@ jobs: - name: Composer normalize uses: docker://ergebnis/composer-normalize-action - - roave-bc-check: - name: Roave BC Check - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Roave BC Check - uses: docker://nyholm/roave-bc-check-ga From bbc965ddd592a0f321020d4f7f7c8ca98c347f48 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 14 Apr 2023 16:25:56 +0200 Subject: [PATCH 113/132] prepare release --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a185f46..497d7aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.14.0] - 2023-04-14 +- +- Allow installation with http-message (PSR-7) version 2 in addition to version 1. +- Support for PHP 8.2 + ## [1.13.0] - 2022-02-11 - Added `Formatter::formatResponseForRequest()` to allow the formatter to get context from the request to decide what of the response to output. From 2ccee04a28c3d98eb3f2b85ce1e2fcff70c0e63b Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 14 Apr 2023 16:26:18 +0200 Subject: [PATCH 114/132] prepare release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 497d7aa..b31e885 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [1.14.0] - 2023-04-14 -- + - Allow installation with http-message (PSR-7) version 2 in addition to version 1. - Support for PHP 8.2 From 9bf26bd57b93d6610e1f65d177f28e16f7d6dda7 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 9 May 2023 21:34:31 +0200 Subject: [PATCH 115/132] fix code to actually be compatible with psr/http-message 2 * add test run with explicit PSR-7 2 (need to remove slim for that build as it does not allow PSR-7 2) --- .github/workflows/tests.yml | 29 ++++++- CHANGELOG.md | 9 +- composer.json | 8 +- phpstan-baseline.neon | 65 -------------- spec/Decorator/MessageDecoratorSpec.php | 4 +- spec/Decorator/StreamDecoratorSpec.php | 2 +- spec/Encoding/FilteredStreamStubSpec.php | 4 +- spec/Encoding/MemoryStream.php | 30 +++---- spec/Formatter/CurlCommandFormatterSpec.php | 32 ++++--- src/Decorator/MessageDecorator.php | 59 +++---------- src/Decorator/RequestDecorator.php | 34 ++------ src/Decorator/ResponseDecorator.php | 19 +---- src/Decorator/StreamDecorator.php | 73 +++------------- src/Encoding/ChunkStream.php | 15 +--- src/Encoding/CompressStream.php | 10 +-- src/Encoding/DechunkStream.php | 10 +-- src/Encoding/DecompressStream.php | 10 +-- src/Encoding/DeflateStream.php | 4 +- src/Encoding/Filter/Chunk.php | 6 +- src/Encoding/FilteredStream.php | 47 ++++------ src/Encoding/GzipDecodeStream.php | 4 +- src/Encoding/GzipEncodeStream.php | 4 +- src/Encoding/InflateStream.php | 10 +-- src/Stream/BufferedStream.php | 95 ++++++--------------- src/StreamFactory/GuzzleStreamFactory.php | 1 + 25 files changed, 177 insertions(+), 407 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 54c6135..82359bf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] steps: - name: Checkout code @@ -31,12 +31,37 @@ jobs: - name: Execute tests run: composer test + psr-7_2: + name: PHP PSR-7 2.0 + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + tools: composer + coverage: none + + - name: Install dependencies + run: | + rm src/MessageFactory/SlimMessageFactory.php src/StreamFactory/SlimStreamFactory.php src/UriFactory/SlimUriFactory.php spec/MessageFactory/SlimMessageFactorySpec.php spec/StreamFactory/SlimStreamFactorySpec.php spec/UriFactory/SlimUriFactorySpec.php + composer remove --dev "slim/slim" --no-interaction --no-update + composer require "psr/http-message:^2.0" --no-interaction --no-update + composer update --prefer-dist --prefer-stable --no-interaction --no-progress + + - name: Execute tests + run: composer test + lowest: name: PHP ${{ matrix.php }} Lowest runs-on: ubuntu-latest strategy: matrix: - php: ['7.1', '7.2', '7.3', '7.4'] + php: ['7.2', '7.3', '7.4'] steps: - name: Checkout code diff --git a/CHANGELOG.md b/CHANGELOG.md index b31e885..9016f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [1.14.0] - 2023-04-14 +## [1.15.0] - 2023-05-10 + +- Actually make compatible with PSR-7 1.1 and 2.0 +- Drop support for PHP 7.1 + +## [1.14.0] - 2023-04-14 (broken) + +**This release is not actually compatible with PSR-7 1.1 or 2.0** - Allow installation with http-message (PSR-7) version 2 in addition to version 1. - Support for PHP 8.2 diff --git a/composer.json b/composer.json index 0ecaad9..05bd274 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,10 @@ } ], "require": { - "php": "^7.1 || ^8.0", + "php": "^7.2 || ^8.0", "clue/stream-filter": "^1.5", "php-http/message-factory": "^1.0.2", - "psr/http-message": "^1.0 || ^2.0" + "psr/http-message": "^1.1 || ^2.0" }, "provide": { "php-http/message-factory-implementation": "1.0" @@ -26,10 +26,10 @@ "require-dev": { "ext-zlib": "*", "ergebnis/composer-normalize": "^2.6", - "guzzlehttp/psr7": "^1.0", + "guzzlehttp/psr7": "^1.0 || ^2.0", "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", "slim/slim": "^3.0", - "laminas/laminas-diactoros": "^2.0" + "laminas/laminas-diactoros": "^2.0 || ^3.0" }, "suggest": { "ext-zlib": "Used with compressor/decompressor streams", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 226065a..a5cda2b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -115,26 +115,6 @@ parameters: count: 1 path: src/CookieUtil.php - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\ChunkStream\\:\\:fill\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Encoding/ChunkStream.php - - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Encoding/FilteredStream.php - - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Encoding/FilteredStream.php - - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Encoding/FilteredStream.php - - message: "#^Method Http\\\\Message\\\\MessageFactory\\\\DiactorosMessageFactory\\:\\:createRequest\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#" count: 1 @@ -180,26 +160,11 @@ parameters: count: 1 path: src/RequestMatcher/RequestMatcher.php - - - message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$size \\(int\\) does not accept int\\|null\\.$#" - count: 1 - path: src/Stream/BufferedStream.php - - message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$resource \\(resource\\) does not accept resource\\|false\\.$#" count: 2 path: src/Stream/BufferedStream.php - - - message: "#^Dead catch \\- Exception is already caught#" - count: 1 - path: src/Stream/BufferedStream.php - - - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:detach\\(\\) should return resource\\|null but empty return statement found\\.$#" - count: 1 - path: src/Stream/BufferedStream.php - - message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$stream \\(Psr\\\\Http\\\\Message\\\\StreamInterface\\) does not accept null\\.$#" count: 1 @@ -210,36 +175,6 @@ parameters: count: 1 path: src/Stream/BufferedStream.php - - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:getSize\\(\\) should return int\\|null but empty return statement found\\.$#" - count: 1 - path: src/Stream/BufferedStream.php - - - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:tell\\(\\) should return int but returns int\\|false\\.$#" - count: 1 - path: src/Stream/BufferedStream.php - - - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:seek\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Stream/BufferedStream.php - - - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:rewind\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Stream/BufferedStream.php - - - - message: "#^Parameter \\#1 \\$string of function strlen expects string, string\\|false given\\.$#" - count: 1 - path: src/Stream/BufferedStream.php - - - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:read\\(\\) should return string but returns string\\|false\\.$#" - count: 1 - path: src/Stream/BufferedStream.php - - message: "#^Parameter \\#1 \\$stream of class Slim\\\\Http\\\\Stream constructor expects resource, resource\\|false given\\.$#" count: 1 diff --git a/spec/Decorator/MessageDecoratorSpec.php b/spec/Decorator/MessageDecoratorSpec.php index 5c28dcd..8c8bd33 100644 --- a/spec/Decorator/MessageDecoratorSpec.php +++ b/spec/Decorator/MessageDecoratorSpec.php @@ -69,9 +69,9 @@ public function it_can_check_a_header(MessageInterface $message) public function it_has_a_header(MessageInterface $message) { - $message->getHeader('Content-Type')->willReturn('application/xml'); + $message->getHeader('Content-Type')->willReturn(['application/xml']); - $this->getHeader('Content-Type')->shouldReturn('application/xml'); + $this->getHeader('Content-Type')->shouldReturn(['application/xml']); } public function it_has_a_header_line(MessageInterface $message) diff --git a/spec/Decorator/StreamDecoratorSpec.php b/spec/Decorator/StreamDecoratorSpec.php index 46bb0d5..1315579 100644 --- a/spec/Decorator/StreamDecoratorSpec.php +++ b/spec/Decorator/StreamDecoratorSpec.php @@ -95,7 +95,7 @@ public function it_checks_whether_the_stream_is_writable(StreamInterface $stream public function it_writes_to_the_stream(StreamInterface $stream) { - $stream->write('body')->shouldBeCalled(); + $stream->write('body')->shouldBeCalled()->willReturn(4); $this->write('body'); } diff --git a/spec/Encoding/FilteredStreamStubSpec.php b/spec/Encoding/FilteredStreamStubSpec.php index dc4db8f..fbaf68c 100644 --- a/spec/Encoding/FilteredStreamStubSpec.php +++ b/spec/Encoding/FilteredStreamStubSpec.php @@ -57,12 +57,12 @@ public function it_does_not_know_the_content_size() class FilteredStreamStub extends FilteredStream { - protected function readFilter() + protected function readFilter(): string { return 'convert.base64-encode'; } - protected function writeFilter() + protected function writeFilter(): string { return 'convert.base64-encode'; } diff --git a/spec/Encoding/MemoryStream.php b/spec/Encoding/MemoryStream.php index 72acab7..a751b43 100644 --- a/spec/Encoding/MemoryStream.php +++ b/spec/Encoding/MemoryStream.php @@ -28,12 +28,12 @@ public function __construct($body = '', $chunkSize = 8192) $this->chunkSize = $chunkSize; } - public function __toString() + public function __toString(): string { return $this->getContents(); } - public function close() + public function close(): void { fclose($this->resource); } @@ -46,64 +46,64 @@ public function detach() return $resource; } - public function getSize() + public function getSize(): int { return $this->size; } - public function tell() + public function tell(): int { return ftell($this->resource); } - public function eof() + public function eof(): bool { return feof($this->resource); } - public function isSeekable() + public function isSeekable(): bool { return true; } - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): void { fseek($this->resource, $offset, $whence); } - public function rewind() + public function rewind(): void { $this->seek(0); } - public function isWritable() + public function isWritable(): bool { return true; } - public function write($string) + public function write(string $string): int { - fwrite($this->resource, $string); + return fwrite($this->resource, $string); } - public function isReadable() + public function isReadable(): bool { return true; } - public function read($length) + public function read(int $length): string { return fread($this->resource, min($this->chunkSize, $length)); } - public function getContents() + public function getContents(): string { $this->rewind(); return $this->read($this->size); } - public function getMetadata($key = null) + public function getMetadata(string $key = null) { $metadata = stream_get_meta_data($this->resource); diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php index 36524da..e6ed104 100644 --- a/spec/Formatter/CurlCommandFormatterSpec.php +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -25,7 +25,8 @@ public function it_formats_the_request(RequestInterface $request, UriInterface $ $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); - $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); + $uri->withFragment('')->shouldBeCalled()->willReturn($uri); + $uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar'); $request->getMethod()->willReturn('GET'); $request->getProtocolVersion()->willReturn('1.1'); @@ -43,9 +44,10 @@ public function it_formats_post_request(RequestInterface $request, UriInterface $body->__toString()->willReturn('body " data'." test' bar"); $body->getSize()->willReturn(1); $body->isSeekable()->willReturn(true); - $body->rewind()->willReturn(true); + $body->rewind()->shouldBeCalled(); - $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); + $uri->withFragment('')->shouldBeCalled()->willReturn($uri); + $uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar'); $request->getMethod()->willReturn('POST'); $request->getProtocolVersion()->willReturn('2.0'); @@ -65,10 +67,10 @@ public function it_formats_the_request_with_user_agent(RequestInterface $request $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); - $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); + $uri->withFragment('')->shouldBeCalled()->willReturn($uri); + $uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar'); $request->getMethod()->willReturn('GET'); $request->getProtocolVersion()->willReturn('1.1'); - $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); $request->getHeaders()->willReturn(['user-agent' => ['foobar-browser']]); $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' -A 'foobar-browser'"); @@ -82,9 +84,10 @@ public function it_formats_requests_with_null_bytes(RequestInterface $request, U $body->__toString()->willReturn("\0"); $body->getSize()->willReturn(1); $body->isSeekable()->willReturn(true); - $body->rewind()->willReturn(true); + $body->rewind()->shouldBeCalled(); - $uri->withFragment('')->willReturn('http://foo.com/bar'); + $uri->withFragment('')->shouldBeCalled()->willReturn($uri); + $uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar'); $request->getMethod()->willReturn('POST'); $request->getProtocolVersion()->willReturn('1.1'); $request->getHeaders()->willReturn([]); @@ -100,9 +103,10 @@ public function it_formats_requests_with_line_break(RequestInterface $request, U $body->__toString()->willReturn("foo\nbar"); $body->getSize()->willReturn(1); $body->isSeekable()->willReturn(true); - $body->rewind()->willReturn(true); + $body->rewind()->shouldBeCalled(); - $uri->withFragment('')->willReturn('http://foo.com/bar'); + $uri->withFragment('')->shouldBeCalled()->willReturn($uri); + $uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar'); $request->getMethod()->willReturn('POST'); $request->getProtocolVersion()->willReturn('1.1'); $request->getHeaders()->willReturn([]); @@ -120,7 +124,8 @@ public function it_formats_requests_with_nonseekable_body(RequestInterface $requ $body->__toString()->shouldNotBeCalled(); $body->rewind()->shouldNotBeCalled(); - $uri->withFragment('')->willReturn('http://foo.com/bar'); + $uri->withFragment('')->shouldBeCalled()->willReturn($uri); + $uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar'); $request->getMethod()->willReturn('POST'); $request->getProtocolVersion()->willReturn('1.1'); $request->getHeaders()->willReturn([]); @@ -133,12 +138,13 @@ public function it_formats_requests_with_long_body(RequestInterface $request, Ur $request->getUri()->willReturn($uri); $request->getBody()->willReturn($body); - $body->__toString()->willReturn('a very long body'); + $body->__toString()->shouldNotBeCalled(); $body->getSize()->willReturn(2097153); $body->isSeekable()->willReturn(true); - $body->rewind()->willReturn(true); + $body->rewind()->shouldNotBeCalled(); - $uri->withFragment('')->willReturn('http://foo.com/bar'); + $uri->withFragment('')->shouldBeCalled()->willReturn($uri); + $uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar'); $request->getMethod()->willReturn('POST'); $request->getProtocolVersion()->willReturn('1.1'); $request->getHeaders()->willReturn([]); diff --git a/src/Decorator/MessageDecorator.php b/src/Decorator/MessageDecorator.php index 0ffc7ca..4ec4690 100644 --- a/src/Decorator/MessageDecorator.php +++ b/src/Decorator/MessageDecorator.php @@ -20,26 +20,18 @@ trait MessageDecorator * * Since the underlying Message is immutable as well * exposing it is not an issue, because it's state cannot be altered - * - * @return MessageInterface */ - public function getMessage() + public function getMessage(): MessageInterface { return $this->message; } - /** - * {@inheritdoc} - */ - public function getProtocolVersion() + public function getProtocolVersion(): string { return $this->message->getProtocolVersion(); } - /** - * {@inheritdoc} - */ - public function withProtocolVersion($version) + public function withProtocolVersion(string $version): MessageInterface { $new = clone $this; $new->message = $this->message->withProtocolVersion($version); @@ -47,42 +39,27 @@ public function withProtocolVersion($version) return $new; } - /** - * {@inheritdoc} - */ - public function getHeaders() + public function getHeaders(): array { return $this->message->getHeaders(); } - /** - * {@inheritdoc} - */ - public function hasHeader($header) + public function hasHeader(string $header): bool { return $this->message->hasHeader($header); } - /** - * {@inheritdoc} - */ - public function getHeader($header) + public function getHeader(string $header): array { return $this->message->getHeader($header); } - /** - * {@inheritdoc} - */ - public function getHeaderLine($header) + public function getHeaderLine(string $header): string { return $this->message->getHeaderLine($header); } - /** - * {@inheritdoc} - */ - public function withHeader($header, $value) + public function withHeader(string $header, $value): MessageInterface { $new = clone $this; $new->message = $this->message->withHeader($header, $value); @@ -90,10 +67,7 @@ public function withHeader($header, $value) return $new; } - /** - * {@inheritdoc} - */ - public function withAddedHeader($header, $value) + public function withAddedHeader(string $header, $value): MessageInterface { $new = clone $this; $new->message = $this->message->withAddedHeader($header, $value); @@ -101,10 +75,7 @@ public function withAddedHeader($header, $value) return $new; } - /** - * {@inheritdoc} - */ - public function withoutHeader($header) + public function withoutHeader(string $header): MessageInterface { $new = clone $this; $new->message = $this->message->withoutHeader($header); @@ -112,18 +83,12 @@ public function withoutHeader($header) return $new; } - /** - * {@inheritdoc} - */ - public function getBody() + public function getBody(): StreamInterface { return $this->message->getBody(); } - /** - * {@inheritdoc} - */ - public function withBody(StreamInterface $body) + public function withBody(StreamInterface $body): MessageInterface { $new = clone $this; $new->message = $this->message->withBody($body); diff --git a/src/Decorator/RequestDecorator.php b/src/Decorator/RequestDecorator.php index bd254a8..1392a76 100644 --- a/src/Decorator/RequestDecorator.php +++ b/src/Decorator/RequestDecorator.php @@ -16,10 +16,8 @@ trait RequestDecorator /** * Exchanges the underlying request with another. - * - * @return self */ - public function withRequest(RequestInterface $request) + public function withRequest(RequestInterface $request): RequestInterface { $new = clone $this; $new->message = $request; @@ -27,18 +25,12 @@ public function withRequest(RequestInterface $request) return $new; } - /** - * {@inheritdoc} - */ - public function getRequestTarget() + public function getRequestTarget(): string { return $this->message->getRequestTarget(); } - /** - * {@inheritdoc} - */ - public function withRequestTarget($requestTarget) + public function withRequestTarget(string $requestTarget): RequestInterface { $new = clone $this; $new->message = $this->message->withRequestTarget($requestTarget); @@ -46,18 +38,12 @@ public function withRequestTarget($requestTarget) return $new; } - /** - * {@inheritdoc} - */ - public function getMethod() + public function getMethod(): string { return $this->message->getMethod(); } - /** - * {@inheritdoc} - */ - public function withMethod($method) + public function withMethod(string $method): RequestInterface { $new = clone $this; $new->message = $this->message->withMethod($method); @@ -65,18 +51,12 @@ public function withMethod($method) return $new; } - /** - * {@inheritdoc} - */ - public function getUri() + public function getUri(): UriInterface { return $this->message->getUri(); } - /** - * {@inheritdoc} - */ - public function withUri(UriInterface $uri, $preserveHost = false) + public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface { $new = clone $this; $new->message = $this->message->withUri($uri, $preserveHost); diff --git a/src/Decorator/ResponseDecorator.php b/src/Decorator/ResponseDecorator.php index 20319ed..0b75438 100644 --- a/src/Decorator/ResponseDecorator.php +++ b/src/Decorator/ResponseDecorator.php @@ -15,10 +15,8 @@ trait ResponseDecorator /** * Exchanges the underlying response with another. - * - * @return self */ - public function withResponse(ResponseInterface $response) + public function withResponse(ResponseInterface $response): ResponseInterface { $new = clone $this; $new->message = $response; @@ -26,18 +24,12 @@ public function withResponse(ResponseInterface $response) return $new; } - /** - * {@inheritdoc} - */ - public function getStatusCode() + public function getStatusCode(): int { return $this->message->getStatusCode(); } - /** - * {@inheritdoc} - */ - public function withStatus($code, $reasonPhrase = '') + public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface { $new = clone $this; $new->message = $this->message->withStatus($code, $reasonPhrase); @@ -45,10 +37,7 @@ public function withStatus($code, $reasonPhrase = '') return $new; } - /** - * {@inheritdoc} - */ - public function getReasonPhrase() + public function getReasonPhrase(): string { return $this->message->getReasonPhrase(); } diff --git a/src/Decorator/StreamDecorator.php b/src/Decorator/StreamDecorator.php index f405c7a..b1f306d 100644 --- a/src/Decorator/StreamDecorator.php +++ b/src/Decorator/StreamDecorator.php @@ -16,122 +16,77 @@ trait StreamDecorator */ protected $stream; - /** - * {@inheritdoc} - */ - public function __toString() + public function __toString(): string { return $this->stream->__toString(); } - /** - * {@inheritdoc} - */ - public function close() + public function close(): void { $this->stream->close(); } - /** - * {@inheritdoc} - */ public function detach() { return $this->stream->detach(); } - /** - * {@inheritdoc} - */ - public function getSize() + public function getSize(): ?int { return $this->stream->getSize(); } - /** - * {@inheritdoc} - */ - public function tell() + public function tell(): int { return $this->stream->tell(); } - /** - * {@inheritdoc} - */ - public function eof() + public function eof(): bool { return $this->stream->eof(); } - /** - * {@inheritdoc} - */ - public function isSeekable() + public function isSeekable(): bool { return $this->stream->isSeekable(); } - /** - * {@inheritdoc} - */ - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): void { $this->stream->seek($offset, $whence); } - /** - * {@inheritdoc} - */ - public function rewind() + public function rewind(): void { $this->stream->rewind(); } - /** - * {@inheritdoc} - */ - public function isWritable() + public function isWritable(): bool { return $this->stream->isWritable(); } - /** - * {@inheritdoc} - */ - public function write($string) + public function write(string $string): int { return $this->stream->write($string); } - /** - * {@inheritdoc} - */ - public function isReadable() + public function isReadable(): bool { return $this->stream->isReadable(); } - /** - * {@inheritdoc} - */ - public function read($length) + public function read(int $length): string { return $this->stream->read($length); } - /** - * {@inheritdoc} - */ - public function getContents() + public function getContents(): string { return $this->stream->getContents(); } - /** - * {@inheritdoc} - */ - public function getMetadata($key = null) + public function getMetadata(string $key = null) { return $this->stream->getMetadata($key); } diff --git a/src/Encoding/ChunkStream.php b/src/Encoding/ChunkStream.php index 74c2fbd..362ed78 100644 --- a/src/Encoding/ChunkStream.php +++ b/src/Encoding/ChunkStream.php @@ -9,26 +9,17 @@ */ class ChunkStream extends FilteredStream { - /** - * {@inheritdoc} - */ - protected function readFilter() + protected function readFilter(): string { return 'chunk'; } - /** - * {@inheritdoc} - */ - protected function writeFilter() + protected function writeFilter(): string { return 'dechunk'; } - /** - * {@inheritdoc} - */ - protected function fill() + protected function fill(): void { parent::fill(); diff --git a/src/Encoding/CompressStream.php b/src/Encoding/CompressStream.php index bdb740a..7e89388 100644 --- a/src/Encoding/CompressStream.php +++ b/src/Encoding/CompressStream.php @@ -27,18 +27,12 @@ public function __construct(StreamInterface $stream, $level = -1) $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 15]); } - /** - * {@inheritdoc} - */ - protected function readFilter() + protected function readFilter(): string { return 'zlib.deflate'; } - /** - * {@inheritdoc} - */ - protected function writeFilter() + protected function writeFilter(): string { return 'zlib.inflate'; } diff --git a/src/Encoding/DechunkStream.php b/src/Encoding/DechunkStream.php index 4cade83..c1fe3a6 100644 --- a/src/Encoding/DechunkStream.php +++ b/src/Encoding/DechunkStream.php @@ -11,18 +11,12 @@ */ class DechunkStream extends FilteredStream { - /** - * {@inheritdoc} - */ - protected function readFilter() + protected function readFilter(): string { return 'dechunk'; } - /** - * {@inheritdoc} - */ - protected function writeFilter() + protected function writeFilter(): string { return 'chunk'; } diff --git a/src/Encoding/DecompressStream.php b/src/Encoding/DecompressStream.php index ab3a345..aa3fdf0 100644 --- a/src/Encoding/DecompressStream.php +++ b/src/Encoding/DecompressStream.php @@ -27,18 +27,12 @@ public function __construct(StreamInterface $stream, $level = -1) $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 15, 'level' => $level]); } - /** - * {@inheritdoc} - */ - protected function readFilter() + protected function readFilter(): string { return 'zlib.inflate'; } - /** - * {@inheritdoc} - */ - protected function writeFilter() + protected function writeFilter(): string { return 'zlib.deflate'; } diff --git a/src/Encoding/DeflateStream.php b/src/Encoding/DeflateStream.php index 2ab3e00..d18dd0a 100644 --- a/src/Encoding/DeflateStream.php +++ b/src/Encoding/DeflateStream.php @@ -26,7 +26,7 @@ public function __construct(StreamInterface $stream, $level = -1) /** * {@inheritdoc} */ - protected function readFilter() + protected function readFilter(): string { return 'zlib.deflate'; } @@ -34,7 +34,7 @@ protected function readFilter() /** * {@inheritdoc} */ - protected function writeFilter() + protected function writeFilter(): string { return 'zlib.inflate'; } diff --git a/src/Encoding/Filter/Chunk.php b/src/Encoding/Filter/Chunk.php index 538e270..7a9e18f 100644 --- a/src/Encoding/Filter/Chunk.php +++ b/src/Encoding/Filter/Chunk.php @@ -9,11 +9,7 @@ */ class Chunk extends \php_user_filter { - /** - * {@inheritdoc} - */ - #[\ReturnTypeWillChange] - public function filter($in, $out, &$consumed, $closing) + public function filter($in, $out, &$consumed, $closing): int { while ($bucket = stream_bucket_make_writeable($in)) { $lenbucket = stream_bucket_new($this->stream, dechex($bucket->datalen)."\r\n"); diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index a6aec25..d2e0e45 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -75,10 +75,7 @@ public function __construct(StreamInterface $stream, $readFilterOptions = null, $this->stream = $stream; } - /** - * {@inheritdoc} - */ - public function read($length) + public function read(int $length): string { if (strlen($this->buffer) >= $length) { $read = substr($this->buffer, 0, $length); @@ -101,10 +98,7 @@ public function read($length) return $read.$this->read($length - strlen($read)); } - /** - * {@inheritdoc} - */ - public function eof() + public function eof(): bool { return $this->stream->eof() && '' === $this->buffer; } @@ -116,7 +110,7 @@ public function eof() * This allow to get last data in the PHP buffer otherwise this * bug is present : https://bugs.php.net/bug.php?id=48725 */ - protected function fill() + protected function fill(): void { $readFilterCallback = $this->readFilterCallback; $this->buffer .= $readFilterCallback($this->stream->read(self::BUFFER_SIZE)); @@ -129,7 +123,7 @@ protected function fill() /** * {@inheritdoc} */ - public function getContents() + public function getContents(): string { $buffer = ''; @@ -149,15 +143,12 @@ public function getContents() /** * Always returns null because we can't tell the size of a stream when we filter. */ - public function getSize() + public function getSize(): ?int { return null; } - /** - * {@inheritdoc} - */ - public function __toString() + public function __toString(): string { return $this->getContents(); } @@ -167,24 +158,24 @@ public function __toString() * * We would need to buffer and process everything to allow seeking. */ - public function isSeekable() + public function isSeekable(): bool { return false; } /** - * {@inheritdoc} + * Filtered streams are not seekable and can thus not be rewound. */ - public function rewind() + public function rewind(): void { @trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version', E_USER_DEPRECATED); $this->doRewind(); } /** - * {@inheritdoc} + * Filtered streams are not seekable. */ - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): void { @trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version', E_USER_DEPRECATED); $this->doSeek($offset, $whence); @@ -193,11 +184,9 @@ public function seek($offset, $whence = SEEK_SET) /** * Returns the read filter name. * - * @return string - * * @deprecated since version 1.5, will be removed in 2.0 */ - public function getReadFilter() + public function getReadFilter(): string { @trigger_error('The '.__CLASS__.'::'.__METHOD__.' method is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED); @@ -206,19 +195,15 @@ public function getReadFilter() /** * Returns the write filter name. - * - * @return string */ - abstract protected function readFilter(); + abstract protected function readFilter(): string; /** * Returns the write filter name. * - * @return string - * * @deprecated since version 1.5, will be removed in 2.0 */ - public function getWriteFilter() + public function getWriteFilter(): string { @trigger_error('The '.__CLASS__.'::'.__METHOD__.' method is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED); @@ -227,8 +212,6 @@ public function getWriteFilter() /** * Returns the write filter name. - * - * @return string */ - abstract protected function writeFilter(); + abstract protected function writeFilter(): string; } diff --git a/src/Encoding/GzipDecodeStream.php b/src/Encoding/GzipDecodeStream.php index 92b5dad..9872499 100644 --- a/src/Encoding/GzipDecodeStream.php +++ b/src/Encoding/GzipDecodeStream.php @@ -30,7 +30,7 @@ public function __construct(StreamInterface $stream, $level = -1) /** * {@inheritdoc} */ - protected function readFilter() + protected function readFilter(): string { return 'zlib.inflate'; } @@ -38,7 +38,7 @@ protected function readFilter() /** * {@inheritdoc} */ - protected function writeFilter() + protected function writeFilter(): string { return 'zlib.deflate'; } diff --git a/src/Encoding/GzipEncodeStream.php b/src/Encoding/GzipEncodeStream.php index 13f097a..36018c2 100644 --- a/src/Encoding/GzipEncodeStream.php +++ b/src/Encoding/GzipEncodeStream.php @@ -30,7 +30,7 @@ public function __construct(StreamInterface $stream, $level = -1) /** * {@inheritdoc} */ - protected function readFilter() + protected function readFilter(): string { return 'zlib.deflate'; } @@ -38,7 +38,7 @@ protected function readFilter() /** * {@inheritdoc} */ - protected function writeFilter() + protected function writeFilter(): string { return 'zlib.inflate'; } diff --git a/src/Encoding/InflateStream.php b/src/Encoding/InflateStream.php index 06c5187..1abe88e 100644 --- a/src/Encoding/InflateStream.php +++ b/src/Encoding/InflateStream.php @@ -27,18 +27,12 @@ public function __construct(StreamInterface $stream, $level = -1) $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => -15, 'level' => $level]); } - /** - * {@inheritdoc} - */ - protected function readFilter() + protected function readFilter(): string { return 'zlib.inflate'; } - /** - * {@inheritdoc} - */ - protected function writeFilter() + protected function writeFilter(): string { return 'zlib.deflate'; } diff --git a/src/Stream/BufferedStream.php b/src/Stream/BufferedStream.php index 3d38731..cf23fc7 100644 --- a/src/Stream/BufferedStream.php +++ b/src/Stream/BufferedStream.php @@ -17,7 +17,7 @@ class BufferedStream implements StreamInterface /** @var resource The buffered resource used to seek previous data */ private $resource; - /** @var int size of the stream if available */ + /** @var int|null size of the stream if available */ private $size; /** @var StreamInterface The underlying stream decorated by this class */ @@ -49,10 +49,7 @@ public function __construct(StreamInterface $stream, $useFileBuffer = true, $mem } } - /** - * {@inheritdoc} - */ - public function __toString() + public function __toString(): string { try { $this->rewind(); @@ -60,15 +57,10 @@ public function __toString() return $this->getContents(); } catch (\Throwable $throwable) { return ''; - } catch (\Exception $exception) { // Layer to be BC with PHP 5, remove this when we only support PHP 7+ - return ''; } } - /** - * {@inheritdoc} - */ - public function close() + public function close(): void { if (null === $this->resource) { throw new \RuntimeException('Cannot close on a detached stream'); @@ -78,13 +70,10 @@ public function close() fclose($this->resource); } - /** - * {@inheritdoc} - */ public function detach() { if (null === $this->resource) { - return; + return null; } // Force reading the remaining data of the stream @@ -98,13 +87,10 @@ public function detach() return $resource; } - /** - * {@inheritdoc} - */ - public function getSize() + public function getSize(): ?int { if (null === $this->resource) { - return; + return null; } if (null === $this->size && $this->stream->eof()) { @@ -114,22 +100,21 @@ public function getSize() return $this->size; } - /** - * {@inheritdoc} - */ - public function tell() + public function tell(): int { if (null === $this->resource) { throw new \RuntimeException('Cannot tell on a detached stream'); } - return ftell($this->resource); + $tell = ftell($this->resource); + if (false === $tell) { + throw new \RuntimeException('ftell failed'); + } + + return $tell; } - /** - * {@inheritdoc} - */ - public function eof() + public function eof(): bool { if (null === $this->resource) { throw new \RuntimeException('Cannot call eof on a detached stream'); @@ -139,18 +124,12 @@ public function eof() return $this->stream->eof() && (ftell($this->resource) === $this->written); } - /** - * {@inheritdoc} - */ - public function isSeekable() + public function isSeekable(): bool { return null !== $this->resource; } - /** - * {@inheritdoc} - */ - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): void { if (null === $this->resource) { throw new \RuntimeException('Cannot seek on a detached stream'); @@ -159,10 +138,7 @@ public function seek($offset, $whence = SEEK_SET) fseek($this->resource, $offset, $whence); } - /** - * {@inheritdoc} - */ - public function rewind() + public function rewind(): void { if (null === $this->resource) { throw new \RuntimeException('Cannot rewind on a detached stream'); @@ -171,34 +147,22 @@ public function rewind() rewind($this->resource); } - /** - * {@inheritdoc} - */ - public function isWritable() + public function isWritable(): bool { return false; } - /** - * {@inheritdoc} - */ - public function write($string) + public function write(string $string): int { throw new \RuntimeException('Cannot write on this stream'); } - /** - * {@inheritdoc} - */ - public function isReadable() + public function isReadable(): bool { return null !== $this->resource; } - /** - * {@inheritdoc} - */ - public function read($length) + public function read(int $length): string { if (null === $this->resource) { throw new \RuntimeException('Cannot read on a detached stream'); @@ -213,6 +177,9 @@ public function read($length) if (ftell($this->resource) !== $this->written) { $read = fread($this->resource, $length); } + if (false === $read) { + throw new \RuntimeException('Failed to read from resource'); + } $bytesRead = strlen($read); @@ -227,10 +194,7 @@ public function read($length) return $read; } - /** - * {@inheritdoc} - */ - public function getContents() + public function getContents(): string { if (null === $this->resource) { throw new \RuntimeException('Cannot read on a detached stream'); @@ -245,17 +209,14 @@ public function getContents() return $read; } - /** - * {@inheritdoc} - */ - public function getMetadata($key = null) + public function getMetadata(?string $key = null) { if (null === $this->resource) { if (null === $key) { return []; } - return; + return null; } $metadata = stream_get_meta_data($this->resource); @@ -265,7 +226,7 @@ public function getMetadata($key = null) } if (!array_key_exists($key, $metadata)) { - return; + return null; } return $metadata[$key]; diff --git a/src/StreamFactory/GuzzleStreamFactory.php b/src/StreamFactory/GuzzleStreamFactory.php index 14d83e9..7a61a7c 100644 --- a/src/StreamFactory/GuzzleStreamFactory.php +++ b/src/StreamFactory/GuzzleStreamFactory.php @@ -23,6 +23,7 @@ public function createStream($body = null) return Utils::streamFor($body); } + // legacy support for guzzle/psr7 1.* return \GuzzleHttp\Psr7\stream_for($body); } } From 2a1fbaa00cf5ffc82f379adf47388663bce8190d Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 10 May 2023 10:19:58 +0200 Subject: [PATCH 116/132] prepare release --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9016f8d..2a98782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# Change Log +# Changelog All notable changes to this project will be documented in this file. @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [1.15.0] - 2023-05-10 +**If you use the decorator classes, you might need to adjust your code to the parameter and return type declarations added in PSR-7** + - Actually make compatible with PSR-7 1.1 and 2.0 - Drop support for PHP 7.1 From b7cdf1749bc0d6b85a2d6d5cec01f7d7a68c3a9c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 27 Apr 2023 20:21:31 +0200 Subject: [PATCH 117/132] Remove direct dependency on php-http/message-factory --- CHANGELOG.md | 4 ++++ composer.json | 2 +- src/MessageFactory/DiactorosMessageFactory.php | 4 ++++ src/MessageFactory/GuzzleMessageFactory.php | 4 ++++ src/MessageFactory/SlimMessageFactory.php | 4 ++++ src/StreamFactory/DiactorosStreamFactory.php | 4 ++++ src/StreamFactory/GuzzleStreamFactory.php | 4 ++++ src/StreamFactory/SlimStreamFactory.php | 4 ++++ src/UriFactory/DiactorosUriFactory.php | 4 ++++ src/UriFactory/GuzzleUriFactory.php | 4 ++++ src/UriFactory/SlimUriFactory.php | 4 ++++ 11 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a98782..0b760d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.16.0] - 2023-XX-XX + +- Remove direct dependency on php-http/message-factory + ## [1.15.0] - 2023-05-10 **If you use the decorator classes, you might need to adjust your code to the parameter and return type declarations added in PSR-7** diff --git a/composer.json b/composer.json index 05bd274..37a86a7 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ "require": { "php": "^7.2 || ^8.0", "clue/stream-filter": "^1.5", - "php-http/message-factory": "^1.0.2", "psr/http-message": "^1.1 || ^2.0" }, "provide": { @@ -27,6 +26,7 @@ "ext-zlib": "*", "ergebnis/composer-normalize": "^2.6", "guzzlehttp/psr7": "^1.0 || ^2.0", + "php-http/message-factory": "^1.0.2", "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", "slim/slim": "^3.0", "laminas/laminas-diactoros": "^2.0 || ^3.0" diff --git a/src/MessageFactory/DiactorosMessageFactory.php b/src/MessageFactory/DiactorosMessageFactory.php index 6d54d35..51d15a2 100644 --- a/src/MessageFactory/DiactorosMessageFactory.php +++ b/src/MessageFactory/DiactorosMessageFactory.php @@ -9,6 +9,10 @@ use Zend\Diactoros\Request as ZendRequest; use Zend\Diactoros\Response as ZendResponse; +if (!interface_exists(MessageFactory::class)) { + throw new \LogicException('You cannot use "Http\Message\MessageFactory\DiactorosMessageFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead'); +} + /** * Creates Diactoros messages. * diff --git a/src/MessageFactory/GuzzleMessageFactory.php b/src/MessageFactory/GuzzleMessageFactory.php index 02989d9..65353ff 100644 --- a/src/MessageFactory/GuzzleMessageFactory.php +++ b/src/MessageFactory/GuzzleMessageFactory.php @@ -6,6 +6,10 @@ use GuzzleHttp\Psr7\Response; use Http\Message\MessageFactory; +if (!interface_exists(MessageFactory::class)) { + throw new \LogicException('You cannot use "Http\Message\MessageFactory\GuzzleMessageFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead'); +} + /** * Creates Guzzle messages. * diff --git a/src/MessageFactory/SlimMessageFactory.php b/src/MessageFactory/SlimMessageFactory.php index bee9322..bc59ef5 100644 --- a/src/MessageFactory/SlimMessageFactory.php +++ b/src/MessageFactory/SlimMessageFactory.php @@ -9,6 +9,10 @@ use Slim\Http\Request; use Slim\Http\Response; +if (!interface_exists(MessageFactory::class)) { + throw new \LogicException('You cannot use "Http\Message\MessageFactory\SlimMessageFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead'); +} + /** * Creates Slim 3 messages. * diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index 8ae2b28..59255d4 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -7,6 +7,10 @@ use Psr\Http\Message\StreamInterface; use Zend\Diactoros\Stream as ZendStream; +if (!interface_exists(StreamFactory::class)) { + throw new \LogicException('You cannot use "Http\Message\MessageFactory\DiactorosStreamFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead'); +} + /** * Creates Diactoros streams. * diff --git a/src/StreamFactory/GuzzleStreamFactory.php b/src/StreamFactory/GuzzleStreamFactory.php index 7a61a7c..fb23ddf 100644 --- a/src/StreamFactory/GuzzleStreamFactory.php +++ b/src/StreamFactory/GuzzleStreamFactory.php @@ -5,6 +5,10 @@ use GuzzleHttp\Psr7\Utils; use Http\Message\StreamFactory; +if (!interface_exists(StreamFactory::class)) { + throw new \LogicException('You cannot use "Http\Message\MessageFactory\GuzzleStreamFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead'); +} + /** * Creates Guzzle streams. * diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index 9274aae..aee112e 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -6,6 +6,10 @@ use Psr\Http\Message\StreamInterface; use Slim\Http\Stream; +if (!interface_exists(StreamFactory::class)) { + throw new \LogicException('You cannot use "Http\Message\MessageFactory\SlimStreamFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead'); +} + /** * Creates Slim 3 streams. * diff --git a/src/UriFactory/DiactorosUriFactory.php b/src/UriFactory/DiactorosUriFactory.php index be883de..f67c7b3 100644 --- a/src/UriFactory/DiactorosUriFactory.php +++ b/src/UriFactory/DiactorosUriFactory.php @@ -7,6 +7,10 @@ use Psr\Http\Message\UriInterface; use Zend\Diactoros\Uri as ZendUri; +if (!interface_exists(UriFactory::class)) { + throw new \LogicException('You cannot use "Http\Message\MessageFactory\DiactorosUriFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead'); +} + /** * Creates Diactoros URI. * diff --git a/src/UriFactory/GuzzleUriFactory.php b/src/UriFactory/GuzzleUriFactory.php index 77989af..7256740 100644 --- a/src/UriFactory/GuzzleUriFactory.php +++ b/src/UriFactory/GuzzleUriFactory.php @@ -7,6 +7,10 @@ use function GuzzleHttp\Psr7\uri_for; +if (!interface_exists(UriFactory::class)) { + throw new \LogicException('You cannot use "Http\Message\MessageFactory\GuzzleUriFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead'); +} + /** * Creates Guzzle URI. * diff --git a/src/UriFactory/SlimUriFactory.php b/src/UriFactory/SlimUriFactory.php index e5bef03..f39d0f6 100644 --- a/src/UriFactory/SlimUriFactory.php +++ b/src/UriFactory/SlimUriFactory.php @@ -6,6 +6,10 @@ use Psr\Http\Message\UriInterface; use Slim\Http\Uri; +if (!interface_exists(UriFactory::class)) { + throw new \LogicException('You cannot use "Http\Message\MessageFactory\SlimUriFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead'); +} + /** * Creates Slim 3 URI. * From 47a14338bf4ebd67d317bf1144253d7db4ab55fd Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 17 May 2023 08:43:38 +0200 Subject: [PATCH 118/132] prepare release --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b760d1..096ee0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [1.16.0] - 2023-XX-XX +## [1.16.0] - 2023-05-17 -- Remove direct dependency on php-http/message-factory +- Remove direct dependency on `php-http/message-factory` as it is only needed for the deprecated Httplug factories. + Upgrade to PSR-17 message factories provided by your HTTP client implementation. + If you need the Httplug factories for the time being, you can `composer require php-http/message-factory` in your application. ## [1.15.0] - 2023-05-10 From 1c5962ca54b75bf7a3ce40aaf038fda78fce7402 Mon Sep 17 00:00:00 2001 From: shoito <37051+shoito@users.noreply.github.com> Date: Sat, 21 Oct 2023 20:55:04 +0900 Subject: [PATCH 119/132] fix GitHub workflow badge URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7699b91..8aeda8f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Latest Version](https://img.shields.io/github/release/php-http/message.svg?style=flat-square)](https://github.com/php-http/message/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) -[![tests](https://github.com/php-http/message/actions/workflows/ci.yml/badge.svg)](https://github.com/php-http/message/actions/workflows/ci.yml) +[![tests](https://img.shields.io/github/actions/workflow/status/php-http/message/tests.yml?branch=1.x&label=tests)](https://github.com/php-http/message/actions/workflows/ci.yml) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/message.svg?style=flat-square)](https://packagist.org/packages/php-http/message) **HTTP Message related tools.** From a91b559590cb7b454f840d8aced80fede25f9745 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 23 Oct 2023 09:27:34 +0200 Subject: [PATCH 120/132] tweak badge design --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8aeda8f..f1d79f7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Latest Version](https://img.shields.io/github/release/php-http/message.svg?style=flat-square)](https://github.com/php-http/message/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) -[![tests](https://img.shields.io/github/actions/workflow/status/php-http/message/tests.yml?branch=1.x&label=tests)](https://github.com/php-http/message/actions/workflows/ci.yml) +[![tests](https://img.shields.io/github/actions/workflow/status/php-http/message/tests.yml?branch=1.x&label=tests&style=flat-square)](https://github.com/php-http/message/actions/workflows/tests.yml) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/message.svg?style=flat-square)](https://packagist.org/packages/php-http/message) **HTTP Message related tools.** From 21c1371599b284bf83d621c466b474a6f103d0fe Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Tue, 23 Jan 2024 09:53:16 +0100 Subject: [PATCH 121/132] chore: add testruns for php 8.3, bump github actions "actions/checkout" 3 => 4, --- .github/workflows/checks.yml | 2 +- .github/workflows/static.yml | 4 ++-- .github/workflows/tests.yml | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 89bec76..1979b2e 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Composer normalize uses: docker://ergebnis/composer-normalize-action diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 7d7c8cf..fe574a0 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: PHPStan uses: docker://oskarstark/phpstan-ga @@ -28,7 +28,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 82359bf..2b2499b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,11 +12,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -37,7 +37,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -65,7 +65,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -88,7 +88,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 From e9a072b10428400766809feefc7cffe02309c53f Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 23 Jan 2024 10:20:56 +0100 Subject: [PATCH 122/132] update to newest cs fixer rules --- spec/Encoding/DechunkStreamSpec.php | 12 ++++++------ src/Authentication/AutoBasicAuth.php | 3 --- src/Authentication/BasicAuth.php | 3 --- src/Authentication/Bearer.php | 3 --- src/Authentication/Chain.php | 3 --- src/Authentication/Header.php | 3 --- src/Authentication/Matching.php | 3 --- src/Authentication/QueryParam.php | 3 --- src/Authentication/RequestConditional.php | 3 --- src/Authentication/Wsse.php | 3 --- src/CookieJar.php | 6 ------ src/Encoding/DeflateStream.php | 6 ------ src/Encoding/FilteredStream.php | 3 --- src/Encoding/GzipDecodeStream.php | 6 ------ src/Encoding/GzipEncodeStream.php | 6 ------ src/Formatter/CurlCommandFormatter.php | 6 ------ src/Formatter/FullHttpMessageFormatter.php | 6 ------ src/Formatter/SimpleFormatter.php | 6 ------ src/MessageFactory/DiactorosMessageFactory.php | 6 ------ src/MessageFactory/GuzzleMessageFactory.php | 6 ------ src/MessageFactory/SlimMessageFactory.php | 6 ------ src/RequestMatcher/CallbackRequestMatcher.php | 3 --- src/RequestMatcher/RegexRequestMatcher.php | 3 --- src/RequestMatcher/RequestMatcher.php | 2 -- src/Stream/BufferedStream.php | 2 +- src/StreamFactory/DiactorosStreamFactory.php | 3 --- src/StreamFactory/GuzzleStreamFactory.php | 3 --- src/StreamFactory/SlimStreamFactory.php | 3 --- src/UriFactory/DiactorosUriFactory.php | 3 --- src/UriFactory/GuzzleUriFactory.php | 3 --- src/UriFactory/SlimUriFactory.php | 3 --- 31 files changed, 7 insertions(+), 123 deletions(-) diff --git a/spec/Encoding/DechunkStreamSpec.php b/spec/Encoding/DechunkStreamSpec.php index 0077f2b..5a57fe0 100644 --- a/spec/Encoding/DechunkStreamSpec.php +++ b/spec/Encoding/DechunkStreamSpec.php @@ -36,11 +36,11 @@ public function it_gets_content() $this->getContents()->shouldReturn('test'); } - public function it_does_not_know_the_content_size() - { - $stream = new MemoryStream("4\r\ntest\r\n4\r\ntest\r\n0\r\n\r\n\0"); - $this->beConstructedWith($stream); + public function it_does_not_know_the_content_size() + { + $stream = new MemoryStream("4\r\ntest\r\n4\r\ntest\r\n0\r\n\r\n\0"); + $this->beConstructedWith($stream); - $this->getSize()->shouldReturn(null); - } + $this->getSize()->shouldReturn(null); + } } diff --git a/src/Authentication/AutoBasicAuth.php b/src/Authentication/AutoBasicAuth.php index 7b6a429..6120016 100644 --- a/src/Authentication/AutoBasicAuth.php +++ b/src/Authentication/AutoBasicAuth.php @@ -27,9 +27,6 @@ public function __construct($shouldRremoveUserInfo = true) $this->shouldRemoveUserInfo = (bool) $shouldRremoveUserInfo; } - /** - * {@inheritdoc} - */ public function authenticate(RequestInterface $request) { $uri = $request->getUri(); diff --git a/src/Authentication/BasicAuth.php b/src/Authentication/BasicAuth.php index 23618a5..85b13a2 100644 --- a/src/Authentication/BasicAuth.php +++ b/src/Authentication/BasicAuth.php @@ -32,9 +32,6 @@ public function __construct($username, $password) $this->password = $password; } - /** - * {@inheritdoc} - */ public function authenticate(RequestInterface $request) { $header = sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->username, $this->password))); diff --git a/src/Authentication/Bearer.php b/src/Authentication/Bearer.php index a8fb21a..287de2d 100644 --- a/src/Authentication/Bearer.php +++ b/src/Authentication/Bearer.php @@ -25,9 +25,6 @@ public function __construct($token) $this->token = $token; } - /** - * {@inheritdoc} - */ public function authenticate(RequestInterface $request) { $header = sprintf('Bearer %s', $this->token); diff --git a/src/Authentication/Chain.php b/src/Authentication/Chain.php index 71002bb..d1d36d5 100644 --- a/src/Authentication/Chain.php +++ b/src/Authentication/Chain.php @@ -33,9 +33,6 @@ public function __construct(array $authenticationChain = []) $this->authenticationChain = $authenticationChain; } - /** - * {@inheritdoc} - */ public function authenticate(RequestInterface $request) { foreach ($this->authenticationChain as $authentication) { diff --git a/src/Authentication/Header.php b/src/Authentication/Header.php index 77f6382..5b1b2e0 100644 --- a/src/Authentication/Header.php +++ b/src/Authentication/Header.php @@ -26,9 +26,6 @@ public function __construct(string $name, $value) $this->value = $value; } - /** - * {@inheritdoc} - */ public function authenticate(RequestInterface $request) { return $request->withHeader($this->name, $this->value); diff --git a/src/Authentication/Matching.php b/src/Authentication/Matching.php index 7a5c247..5c2f0f2 100644 --- a/src/Authentication/Matching.php +++ b/src/Authentication/Matching.php @@ -39,9 +39,6 @@ public function __construct(Authentication $authentication, callable $matcher = $this->matcher = new CallbackRequestMatcher($matcher); } - /** - * {@inheritdoc} - */ public function authenticate(RequestInterface $request) { if ($this->matcher->matches($request)) { diff --git a/src/Authentication/QueryParam.php b/src/Authentication/QueryParam.php index 243efef..bc7b020 100644 --- a/src/Authentication/QueryParam.php +++ b/src/Authentication/QueryParam.php @@ -25,9 +25,6 @@ public function __construct(array $params) $this->params = $params; } - /** - * {@inheritdoc} - */ public function authenticate(RequestInterface $request) { $uri = $request->getUri(); diff --git a/src/Authentication/RequestConditional.php b/src/Authentication/RequestConditional.php index 01062cf..fefe44e 100644 --- a/src/Authentication/RequestConditional.php +++ b/src/Authentication/RequestConditional.php @@ -29,9 +29,6 @@ public function __construct(RequestMatcher $requestMatcher, Authentication $auth $this->authentication = $authentication; } - /** - * {@inheritdoc} - */ public function authenticate(RequestInterface $request) { if ($this->requestMatcher->matches($request)) { diff --git a/src/Authentication/Wsse.php b/src/Authentication/Wsse.php index 88c266b..9191efe 100644 --- a/src/Authentication/Wsse.php +++ b/src/Authentication/Wsse.php @@ -42,9 +42,6 @@ public function __construct($username, $password, $hashAlgorithm = 'sha1') $this->hashAlgorithm = $hashAlgorithm; } - /** - * {@inheritdoc} - */ public function authenticate(RequestInterface $request) { $nonce = substr(md5(uniqid(uniqid().'_', true)), 0, 16); diff --git a/src/CookieJar.php b/src/CookieJar.php index 165084d..159a99f 100644 --- a/src/CookieJar.php +++ b/src/CookieJar.php @@ -192,18 +192,12 @@ public function clear() $this->cookies = new \SplObjectStorage(); } - /** - * {@inheritdoc} - */ #[\ReturnTypeWillChange] public function count() { return $this->cookies->count(); } - /** - * {@inheritdoc} - */ #[\ReturnTypeWillChange] public function getIterator() { diff --git a/src/Encoding/DeflateStream.php b/src/Encoding/DeflateStream.php index d18dd0a..d8d8a8a 100644 --- a/src/Encoding/DeflateStream.php +++ b/src/Encoding/DeflateStream.php @@ -23,17 +23,11 @@ public function __construct(StreamInterface $stream, $level = -1) $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => -15]); } - /** - * {@inheritdoc} - */ protected function readFilter(): string { return 'zlib.deflate'; } - /** - * {@inheritdoc} - */ protected function writeFilter(): string { return 'zlib.inflate'; diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php index d2e0e45..4bc44a6 100644 --- a/src/Encoding/FilteredStream.php +++ b/src/Encoding/FilteredStream.php @@ -120,9 +120,6 @@ protected function fill(): void } } - /** - * {@inheritdoc} - */ public function getContents(): string { $buffer = ''; diff --git a/src/Encoding/GzipDecodeStream.php b/src/Encoding/GzipDecodeStream.php index 9872499..78ecc84 100644 --- a/src/Encoding/GzipDecodeStream.php +++ b/src/Encoding/GzipDecodeStream.php @@ -27,17 +27,11 @@ public function __construct(StreamInterface $stream, $level = -1) $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 31, 'level' => $level]); } - /** - * {@inheritdoc} - */ protected function readFilter(): string { return 'zlib.inflate'; } - /** - * {@inheritdoc} - */ protected function writeFilter(): string { return 'zlib.deflate'; diff --git a/src/Encoding/GzipEncodeStream.php b/src/Encoding/GzipEncodeStream.php index 36018c2..7ffa499 100644 --- a/src/Encoding/GzipEncodeStream.php +++ b/src/Encoding/GzipEncodeStream.php @@ -27,17 +27,11 @@ public function __construct(StreamInterface $stream, $level = -1) $this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 31]); } - /** - * {@inheritdoc} - */ protected function readFilter(): string { return 'zlib.deflate'; } - /** - * {@inheritdoc} - */ protected function writeFilter(): string { return 'zlib.inflate'; diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 80d2971..1878cad 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -13,9 +13,6 @@ */ class CurlCommandFormatter implements Formatter { - /** - * {@inheritdoc} - */ public function formatRequest(RequestInterface $request) { $command = sprintf('curl %s', escapeshellarg((string) $request->getUri()->withFragment(''))); @@ -60,9 +57,6 @@ public function formatRequest(RequestInterface $request) return $command; } - /** - * {@inheritdoc} - */ public function formatResponse(ResponseInterface $response) { return ''; diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index 8b9b126..116b2dd 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -36,9 +36,6 @@ public function __construct($maxBodyLength = 1000, string $binaryDetectionRegex $this->binaryDetectionRegex = $binaryDetectionRegex; } - /** - * {@inheritdoc} - */ public function formatRequest(RequestInterface $request) { $message = sprintf( @@ -55,9 +52,6 @@ public function formatRequest(RequestInterface $request) return $this->addBody($request, $message); } - /** - * {@inheritdoc} - */ public function formatResponse(ResponseInterface $response) { $message = sprintf( diff --git a/src/Formatter/SimpleFormatter.php b/src/Formatter/SimpleFormatter.php index ee99ae3..c8b0450 100644 --- a/src/Formatter/SimpleFormatter.php +++ b/src/Formatter/SimpleFormatter.php @@ -14,9 +14,6 @@ */ class SimpleFormatter implements Formatter { - /** - * {@inheritdoc} - */ public function formatRequest(RequestInterface $request) { return sprintf( @@ -27,9 +24,6 @@ public function formatRequest(RequestInterface $request) ); } - /** - * {@inheritdoc} - */ public function formatResponse(ResponseInterface $response) { return sprintf( diff --git a/src/MessageFactory/DiactorosMessageFactory.php b/src/MessageFactory/DiactorosMessageFactory.php index 51d15a2..c13f573 100644 --- a/src/MessageFactory/DiactorosMessageFactory.php +++ b/src/MessageFactory/DiactorosMessageFactory.php @@ -32,9 +32,6 @@ public function __construct() $this->streamFactory = new DiactorosStreamFactory(); } - /** - * {@inheritdoc} - */ public function createRequest( $method, $uri, @@ -59,9 +56,6 @@ public function createRequest( ))->withProtocolVersion($protocolVersion); } - /** - * {@inheritdoc} - */ public function createResponse( $statusCode = 200, $reasonPhrase = null, diff --git a/src/MessageFactory/GuzzleMessageFactory.php b/src/MessageFactory/GuzzleMessageFactory.php index 65353ff..8844f74 100644 --- a/src/MessageFactory/GuzzleMessageFactory.php +++ b/src/MessageFactory/GuzzleMessageFactory.php @@ -19,9 +19,6 @@ */ final class GuzzleMessageFactory implements MessageFactory { - /** - * {@inheritdoc} - */ public function createRequest( $method, $uri, @@ -38,9 +35,6 @@ public function createRequest( ); } - /** - * {@inheritdoc} - */ public function createResponse( $statusCode = 200, $reasonPhrase = null, diff --git a/src/MessageFactory/SlimMessageFactory.php b/src/MessageFactory/SlimMessageFactory.php index bc59ef5..118799c 100644 --- a/src/MessageFactory/SlimMessageFactory.php +++ b/src/MessageFactory/SlimMessageFactory.php @@ -38,9 +38,6 @@ public function __construct() $this->uriFactory = new SlimUriFactory(); } - /** - * {@inheritdoc} - */ public function createRequest( $method, $uri, @@ -59,9 +56,6 @@ public function createRequest( ))->withProtocolVersion($protocolVersion); } - /** - * {@inheritdoc} - */ public function createResponse( $statusCode = 200, $reasonPhrase = null, diff --git a/src/RequestMatcher/CallbackRequestMatcher.php b/src/RequestMatcher/CallbackRequestMatcher.php index 1197dd9..659e6e3 100644 --- a/src/RequestMatcher/CallbackRequestMatcher.php +++ b/src/RequestMatcher/CallbackRequestMatcher.php @@ -22,9 +22,6 @@ public function __construct(callable $callback) $this->callback = $callback; } - /** - * {@inheritdoc} - */ public function matches(RequestInterface $request) { return (bool) call_user_func($this->callback, $request); diff --git a/src/RequestMatcher/RegexRequestMatcher.php b/src/RequestMatcher/RegexRequestMatcher.php index 91f3729..253d9bc 100644 --- a/src/RequestMatcher/RegexRequestMatcher.php +++ b/src/RequestMatcher/RegexRequestMatcher.php @@ -31,9 +31,6 @@ public function __construct($regex) $this->regex = $regex; } - /** - * {@inheritdoc} - */ public function matches(RequestInterface $request) { return (bool) preg_match($this->regex, (string) $request->getUri()); diff --git a/src/RequestMatcher/RequestMatcher.php b/src/RequestMatcher/RequestMatcher.php index e2aa021..4b28ccc 100644 --- a/src/RequestMatcher/RequestMatcher.php +++ b/src/RequestMatcher/RequestMatcher.php @@ -51,8 +51,6 @@ public function __construct($path = null, $host = null, $methods = [], $schemes } /** - * {@inheritdoc} - * * @api */ public function matches(RequestInterface $request) diff --git a/src/Stream/BufferedStream.php b/src/Stream/BufferedStream.php index cf23fc7..13fc06b 100644 --- a/src/Stream/BufferedStream.php +++ b/src/Stream/BufferedStream.php @@ -209,7 +209,7 @@ public function getContents(): string return $read; } - public function getMetadata(?string $key = null) + public function getMetadata(string $key = null) { if (null === $this->resource) { if (null === $key) { diff --git a/src/StreamFactory/DiactorosStreamFactory.php b/src/StreamFactory/DiactorosStreamFactory.php index 59255d4..1b8c6f4 100644 --- a/src/StreamFactory/DiactorosStreamFactory.php +++ b/src/StreamFactory/DiactorosStreamFactory.php @@ -20,9 +20,6 @@ */ final class DiactorosStreamFactory implements StreamFactory { - /** - * {@inheritdoc} - */ public function createStream($body = null) { if ($body instanceof StreamInterface) { diff --git a/src/StreamFactory/GuzzleStreamFactory.php b/src/StreamFactory/GuzzleStreamFactory.php index fb23ddf..f74bc5b 100644 --- a/src/StreamFactory/GuzzleStreamFactory.php +++ b/src/StreamFactory/GuzzleStreamFactory.php @@ -18,9 +18,6 @@ */ final class GuzzleStreamFactory implements StreamFactory { - /** - * {@inheritdoc} - */ public function createStream($body = null) { if (class_exists(Utils::class)) { diff --git a/src/StreamFactory/SlimStreamFactory.php b/src/StreamFactory/SlimStreamFactory.php index aee112e..4cfa9ae 100644 --- a/src/StreamFactory/SlimStreamFactory.php +++ b/src/StreamFactory/SlimStreamFactory.php @@ -19,9 +19,6 @@ */ final class SlimStreamFactory implements StreamFactory { - /** - * {@inheritdoc} - */ public function createStream($body = null) { if ($body instanceof StreamInterface) { diff --git a/src/UriFactory/DiactorosUriFactory.php b/src/UriFactory/DiactorosUriFactory.php index f67c7b3..84d5397 100644 --- a/src/UriFactory/DiactorosUriFactory.php +++ b/src/UriFactory/DiactorosUriFactory.php @@ -20,9 +20,6 @@ */ final class DiactorosUriFactory implements UriFactory { - /** - * {@inheritdoc} - */ public function createUri($uri) { if ($uri instanceof UriInterface) { diff --git a/src/UriFactory/GuzzleUriFactory.php b/src/UriFactory/GuzzleUriFactory.php index 7256740..deac230 100644 --- a/src/UriFactory/GuzzleUriFactory.php +++ b/src/UriFactory/GuzzleUriFactory.php @@ -20,9 +20,6 @@ */ final class GuzzleUriFactory implements UriFactory { - /** - * {@inheritdoc} - */ public function createUri($uri) { if (class_exists(Utils::class)) { diff --git a/src/UriFactory/SlimUriFactory.php b/src/UriFactory/SlimUriFactory.php index f39d0f6..e4ff079 100644 --- a/src/UriFactory/SlimUriFactory.php +++ b/src/UriFactory/SlimUriFactory.php @@ -19,9 +19,6 @@ */ final class SlimUriFactory implements UriFactory { - /** - * {@inheritdoc} - */ public function createUri($uri) { if ($uri instanceof UriInterface) { From 71c020ab85a3ad9873da6c8ce9c4a63b5621dcc4 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Thu, 7 Mar 2024 12:15:39 +0100 Subject: [PATCH 123/132] Add mixed return type Fixes the following error caught by Symfony's PHPUnit Bridge: ``` 1x: Method "Psr\Http\Message\StreamInterface::getMetadata()" might add "mixed" as a native return type declaration in the future. Do the same in implementation "Http\Message\Encoding\FilteredStream" now to avoid errors or add an explicit @return annotation to suppress this message. ``` --- src/Decorator/StreamDecorator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Decorator/StreamDecorator.php b/src/Decorator/StreamDecorator.php index b1f306d..5a6bb2d 100644 --- a/src/Decorator/StreamDecorator.php +++ b/src/Decorator/StreamDecorator.php @@ -86,6 +86,9 @@ public function getContents(): string return $this->stream->getContents(); } + /** + * @return mixed + */ public function getMetadata(string $key = null) { return $this->stream->getMetadata($key); From 6039d7ea370f42fc071dd6636a743a79c7be04ff Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 7 Mar 2024 14:17:40 +0100 Subject: [PATCH 124/132] adjust to latest cs fixer rules --- spec/Encoding/MemoryStream.php | 2 +- src/Authentication/Matching.php | 2 +- src/Cookie.php | 6 +++--- src/Decorator/StreamDecorator.php | 5 +---- src/Stream/BufferedStream.php | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/spec/Encoding/MemoryStream.php b/spec/Encoding/MemoryStream.php index a751b43..bd61cc3 100644 --- a/spec/Encoding/MemoryStream.php +++ b/spec/Encoding/MemoryStream.php @@ -103,7 +103,7 @@ public function getContents(): string return $this->read($this->size); } - public function getMetadata(string $key = null) + public function getMetadata(?string $key = null) { $metadata = stream_get_meta_data($this->resource); diff --git a/src/Authentication/Matching.php b/src/Authentication/Matching.php index 5c2f0f2..cbef52e 100644 --- a/src/Authentication/Matching.php +++ b/src/Authentication/Matching.php @@ -27,7 +27,7 @@ final class Matching implements Authentication */ private $matcher; - public function __construct(Authentication $authentication, callable $matcher = null) + public function __construct(Authentication $authentication, ?callable $matcher = null) { if (is_null($matcher)) { $matcher = function () { diff --git a/src/Cookie.php b/src/Cookie.php index c6eaf51..ecfbcda 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -73,7 +73,7 @@ public function __construct( $path = null, $secure = false, $httpOnly = false, - \DateTime $expires = null + ?\DateTime $expires = null ) { $this->validateName($name); $this->validateValue($value); @@ -109,7 +109,7 @@ public static function createWithoutValidation( $path = null, $secure = false, $httpOnly = false, - \DateTime $expires = null + ?\DateTime $expires = null ) { $cookie = new self('name', null, null, $domain, $path, $secure, $httpOnly, $expires); $cookie->name = $name; @@ -228,7 +228,7 @@ public function hasExpires() * * @return Cookie */ - public function withExpires(\DateTime $expires = null) + public function withExpires(?\DateTime $expires = null) { $new = clone $this; $new->expires = $expires; diff --git a/src/Decorator/StreamDecorator.php b/src/Decorator/StreamDecorator.php index 5a6bb2d..90d93b4 100644 --- a/src/Decorator/StreamDecorator.php +++ b/src/Decorator/StreamDecorator.php @@ -86,10 +86,7 @@ public function getContents(): string return $this->stream->getContents(); } - /** - * @return mixed - */ - public function getMetadata(string $key = null) + public function getMetadata(?string $key = null) { return $this->stream->getMetadata($key); } diff --git a/src/Stream/BufferedStream.php b/src/Stream/BufferedStream.php index 13fc06b..cf23fc7 100644 --- a/src/Stream/BufferedStream.php +++ b/src/Stream/BufferedStream.php @@ -209,7 +209,7 @@ public function getContents(): string return $read; } - public function getMetadata(string $key = null) + public function getMetadata(?string $key = null) { if (null === $this->resource) { if (null === $key) { From d391078801fa9c3e0f32edaf00cbd126c8eb326a Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sat, 16 Mar 2024 17:17:26 +0100 Subject: [PATCH 125/132] feat: fix deprecation --- src/Cookie.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Cookie.php b/src/Cookie.php index ecfbcda..5e2f8e6 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -511,7 +511,10 @@ private function normalizeDomain($domain) */ private function normalizePath($path) { - $path = rtrim($path, '/'); + if(null !== $path) + { + $path = rtrim($path, '/'); + } if (empty($path) or '/' !== substr($path, 0, 1)) { $path = '/'; From e516a1eb22fd17d38ed656e5044f2e1688fdd953 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sat, 16 Mar 2024 17:21:56 +0100 Subject: [PATCH 126/132] feat: fix deprecation --- phpstan-baseline.neon | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a5cda2b..31bd899 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -60,11 +60,6 @@ parameters: count: 1 path: src/Cookie.php - - - message: "#^Parameter \\#1 \\$string of function rtrim expects string, string\\|null given\\.$#" - count: 1 - path: src/Cookie.php - - message: "#^Class Http\\\\Message\\\\CookieJar implements generic interface IteratorAggregate but does not specify its types\\: TKey, TValue$#" count: 1 From ddaef02f8814bed66553c2937ef3777da3677e2b Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sat, 16 Mar 2024 17:23:51 +0100 Subject: [PATCH 127/132] feat: fix deprecation --- src/Cookie.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Cookie.php b/src/Cookie.php index 5e2f8e6..b79fe0a 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -511,9 +511,8 @@ private function normalizeDomain($domain) */ private function normalizePath($path) { - if(null !== $path) - { - $path = rtrim($path, '/'); + if (null !== $path) { + $path = rtrim($path, '/'); } if (empty($path) or '/' !== substr($path, 0, 1)) { From ba03180f3b4844aea9c2f475978a8b231aef21a5 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 7 Mar 2024 14:22:09 +0100 Subject: [PATCH 128/132] prepare release --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 096ee0c..24575c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.16.1] - 2024-03-07 + +- Adjust phpdoc to avoid warnings about return types. + ## [1.16.0] - 2023-05-17 - Remove direct dependency on `php-http/message-factory` as it is only needed for the deprecated Httplug factories. From 1702819fe5b032442665de72c117ac5d174dddfb Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 30 Sep 2024 09:48:44 +0100 Subject: [PATCH 129/132] Run CI on PHP 8.4 --- .github/workflows/tests.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2b2499b..be2c811 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,12 +12,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout code uses: actions/checkout@v4 + - name: Emulate PHP 8.3 + run: composer config platform.php 8.3.999 + if: matrix.php == '8.4' + - name: Setup PHP uses: shivammathur/setup-php@v2 with: From 0d168d2b13cbcd248ab97ff373083eca6fe81b2a Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 2 Oct 2024 13:29:32 +0200 Subject: [PATCH 130/132] adjust php cs fixer configuration to not want to change the code to be incompatible with PHP 7 --- .php-cs-fixer.dist.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 472cc1e..55bd8ed 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -12,7 +12,8 @@ ->setRiskyAllowed(true) ->setRules([ '@Symfony' => true, - 'single_line_throw' => false, + 'single_line_throw' => false, + 'trailing_comma_in_multiline' => false, // for methods this is incompatible with PHP 7 ]) ->setFinder($finder) ; From e656a72f0ea45aebdbd8424719072ed15633c0fe Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 2 Oct 2024 13:32:24 +0200 Subject: [PATCH 131/132] fix edge case of reading 0 bytes from BufferedStream --- src/Stream/BufferedStream.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Stream/BufferedStream.php b/src/Stream/BufferedStream.php index cf23fc7..289ff8c 100644 --- a/src/Stream/BufferedStream.php +++ b/src/Stream/BufferedStream.php @@ -170,6 +170,9 @@ public function read(int $length): string if ($length < 0) { throw new \InvalidArgumentException('Can not read a negative amount of bytes'); } + if (0 === $length) { + return ''; + } $read = ''; From 8945831d439ace404b6f54ed65d4ef8af087b804 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 15 Feb 2025 11:49:21 +0100 Subject: [PATCH 132/132] docs: remove $ in bash command --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f1d79f7..4038be9 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Via Composer ``` bash -$ composer require php-http/message +composer require php-http/message ``` @@ -37,7 +37,7 @@ Please see the [official documentation](http://docs.php-http.org/en/latest/messa ## Testing ``` bash -$ composer test +composer test ```