From 58ca7113f3cd3158a8ae1b02853ece0c4dba4eda Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 17 Apr 2019 10:09:50 +0200 Subject: PSR-7: Replaced implementation with `Nyholm\Psr7` --- composer.json | 2 +- src/Http/MessageTrait.php | 5 +++-- src/Http/Psr7ServiceProvider.php | 29 +++++++++++++++------------- src/Http/Request.php | 18 ++++++++--------- tests/Unit/Http/MessageTraitRequestTest.php | 4 ++-- tests/Unit/Http/MessageTraitResponseTest.php | 4 ++-- tests/Unit/Http/RequestTest.php | 4 ++-- 7 files changed, 35 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index d2628534..cd29953f 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "illuminate/database": "5.5.*", "illuminate/support": "5.5.*", "nikic/fast-route": "^1.3", - "php-extended/php-http-message-factory-psr17": "^1.0", + "nyholm/psr7": "^1.1", "psr/container": "^1.0", "psr/http-server-middleware": "^1.0", "psr/log": "^1.0", diff --git a/src/Http/MessageTrait.php b/src/Http/MessageTrait.php index 63ff3682..17fbf5db 100644 --- a/src/Http/MessageTrait.php +++ b/src/Http/MessageTrait.php @@ -3,7 +3,7 @@ namespace Engelsystem\Http; -use PhpExtended\HttpMessage\StringStream; +use Nyholm\Psr7\Stream; use Psr\Http\Message\StreamInterface; /** @@ -213,7 +213,8 @@ trait MessageTrait */ public function getBody() { - $stream = new StringStream($this->getContent()); + $stream = Stream::create($this->getContent()); + $stream->rewind(); return $stream; } diff --git a/src/Http/Psr7ServiceProvider.php b/src/Http/Psr7ServiceProvider.php index fe4449ff..a9194272 100644 --- a/src/Http/Psr7ServiceProvider.php +++ b/src/Http/Psr7ServiceProvider.php @@ -3,10 +3,7 @@ namespace Engelsystem\Http; use Engelsystem\Container\ServiceProvider; -use PhpExtended\HttpMessage\ResponseFactory; -use PhpExtended\HttpMessage\ServerRequestFactory; -use PhpExtended\HttpMessage\StreamFactory; -use PhpExtended\HttpMessage\UploadedFileFactory; +use Nyholm\Psr7\Factory\Psr17Factory; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestFactoryInterface; @@ -21,20 +18,26 @@ class Psr7ServiceProvider extends ServiceProvider { public function register() { + $psr17Factory = Psr17Factory::class; + foreach ( [ - ServerRequestFactory::class => ['psr7.factory.request', ServerRequestFactoryInterface::class], - ResponseFactory::class => ['psr7.factory.response', ResponseFactoryInterface::class], - UploadedFileFactory::class => ['psr7.factory.upload', UploadedFileFactoryInterface::class], - StreamFactory::class => ['psr7.factory.stream', StreamFactoryInterface::class], - PsrHttpFactory::class => ['psr7.factory', HttpMessageFactoryInterface::class], - ] as $class => $aliases + 'psr7.factory.request', + ServerRequestFactoryInterface::class, + 'psr7.factory.response', + ResponseFactoryInterface::class, + 'psr7.factory.upload', + UploadedFileFactoryInterface::class, + 'psr7.factory.stream', + StreamFactoryInterface::class, + ] as $alias ) { - foreach ($aliases as $alias) { - $this->app->bind($alias, $class); - } + $this->app->bind($alias, $psr17Factory); } + $this->app->bind('psr7.factory', PsrHttpFactory::class); + $this->app->bind(HttpMessageFactoryInterface::class, PsrHttpFactory::class); + $this->app->bind('psr7.request', 'request'); $this->app->bind(ServerRequestInterface::class, 'psr7.request'); diff --git a/src/Http/Request.php b/src/Http/Request.php index ee496035..8b5abf2f 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -2,8 +2,8 @@ namespace Engelsystem\Http; -use PhpExtended\HttpMessage\UploadedFile; -use PhpExtended\HttpMessage\Uri; +use Nyholm\Psr7\UploadedFile; +use Nyholm\Psr7\Uri; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\UriInterface; @@ -207,7 +207,7 @@ class Request extends SymfonyRequest implements ServerRequestInterface { $uri = parent::getUri(); - return Uri::parseFromString($uri); + return new Uri($uri); } /** @@ -332,11 +332,11 @@ class Request extends SymfonyRequest implements ServerRequestInterface /** @var SymfonyFile $file */ $files[] = new UploadedFile( - $file->getClientOriginalName(), $file->getRealPath(), - $file->getMimeType(), $file->getSize(), - $file->getError() + $file->getError(), + $file->getClientOriginalName(), + $file->getMimeType() ); } @@ -464,10 +464,10 @@ class Request extends SymfonyRequest implements ServerRequestInterface * This method obviates the need for a hasAttribute() method, as it allows * specifying a default value to return if the attribute is not found. * - * @see getAttributes() * @param string $name The attribute name. * @param mixed $default Default value to return if the attribute does not exist. * @return mixed + * @see getAttributes() */ public function getAttribute($name, $default = null) { @@ -484,10 +484,10 @@ class Request extends SymfonyRequest implements ServerRequestInterface * immutability of the message, and MUST return an instance that has the * updated attribute. * - * @see getAttributes() * @param string $name The attribute name. * @param mixed $value The value of the attribute. * @return static + * @see getAttributes() */ public function withAttribute($name, $value) { @@ -509,9 +509,9 @@ class Request extends SymfonyRequest implements ServerRequestInterface * immutability of the message, and MUST return an instance that removes * the attribute. * - * @see getAttributes() * @param string $name The attribute name. * @return static + * @see getAttributes() */ public function withoutAttribute($name) { diff --git a/tests/Unit/Http/MessageTraitRequestTest.php b/tests/Unit/Http/MessageTraitRequestTest.php index c3d99afb..31ba249f 100644 --- a/tests/Unit/Http/MessageTraitRequestTest.php +++ b/tests/Unit/Http/MessageTraitRequestTest.php @@ -3,7 +3,7 @@ namespace Engelsystem\Test\Unit\Http; use Engelsystem\Test\Unit\Http\Stub\MessageTraitRequestImplementation; -use PhpExtended\HttpMessage\StringStream; +use Nyholm\Psr7\Stream; use PHPUnit\Framework\TestCase; class MessageTraitRequestTest extends TestCase @@ -36,7 +36,7 @@ class MessageTraitRequestTest extends TestCase */ public function testWithBody() { - $stream = new StringStream('Test content'); + $stream = Stream::create('Test content'); $message = new MessageTraitRequestImplementation(); $newMessage = $message->withBody($stream); diff --git a/tests/Unit/Http/MessageTraitResponseTest.php b/tests/Unit/Http/MessageTraitResponseTest.php index 31b529ee..9174eadd 100644 --- a/tests/Unit/Http/MessageTraitResponseTest.php +++ b/tests/Unit/Http/MessageTraitResponseTest.php @@ -3,7 +3,7 @@ namespace Engelsystem\Test\Unit\Http; use Engelsystem\Test\Unit\Http\Stub\MessageTraitResponseImplementation; -use PhpExtended\HttpMessage\StringStream; +use Nyholm\Psr7\Stream; use PHPUnit\Framework\TestCase; use Psr\Http\Message\MessageInterface; use Psr\Http\Message\StreamInterface; @@ -145,7 +145,7 @@ class MessageTraitResponseTest extends TestCase */ public function testWithBody() { - $stream = new StringStream('Test content'); + $stream = Stream::create('Test content'); $message = new MessageTraitResponseImplementation(); $newMessage = $message->withBody($stream); diff --git a/tests/Unit/Http/RequestTest.php b/tests/Unit/Http/RequestTest.php index 8210d583..df171905 100644 --- a/tests/Unit/Http/RequestTest.php +++ b/tests/Unit/Http/RequestTest.php @@ -3,7 +3,7 @@ namespace Engelsystem\Test\Unit\Http; use Engelsystem\Http\Request; -use PhpExtended\HttpMessage\UploadedFile; +use Nyholm\Psr7\UploadedFile; use PHPUnit\Framework\TestCase; use PHPUnit_Framework_MockObject_MockObject as MockObject; use Psr\Http\Message\RequestInterface; @@ -307,7 +307,7 @@ class RequestTest extends TestCase { $filename = tempnam(sys_get_temp_dir(), 'test'); file_put_contents($filename, 'LoremIpsum!'); - $file = new UploadedFile('test.txt', $filename, 'text/plain', 11, UPLOAD_ERR_OK); + $file = new UploadedFile($filename, 11, UPLOAD_ERR_OK, 'test.txt', 'text/plain'); $request = new Request(); $new = $request->withUploadedFiles([$file]); -- cgit v1.2.3-54-g00ecf