diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Http/MessageTrait.php | 6 | ||||
-rw-r--r-- | src/Http/Psr7ServiceProvider.php | 35 | ||||
-rw-r--r-- | src/Http/Request.php | 14 |
3 files changed, 34 insertions, 21 deletions
diff --git a/src/Http/MessageTrait.php b/src/Http/MessageTrait.php index e46d291e..63ff3682 100644 --- a/src/Http/MessageTrait.php +++ b/src/Http/MessageTrait.php @@ -3,8 +3,8 @@ namespace Engelsystem\Http; +use PhpExtended\HttpMessage\StringStream; use Psr\Http\Message\StreamInterface; -use Zend\Diactoros\Stream; /** * @implements \Psr\Http\Message\MessageInterface @@ -213,9 +213,7 @@ trait MessageTrait */ public function getBody() { - $stream = new Stream('php://memory', 'wb+'); - $stream->write($this->getContent()); - $stream->rewind(); + $stream = new StringStream($this->getContent()); return $stream; } diff --git a/src/Http/Psr7ServiceProvider.php b/src/Http/Psr7ServiceProvider.php index 72fdef8e..fe4449ff 100644 --- a/src/Http/Psr7ServiceProvider.php +++ b/src/Http/Psr7ServiceProvider.php @@ -3,27 +3,42 @@ namespace Engelsystem\Http; use Engelsystem\Container\ServiceProvider; +use PhpExtended\HttpMessage\ResponseFactory; +use PhpExtended\HttpMessage\ServerRequestFactory; +use PhpExtended\HttpMessage\StreamFactory; +use PhpExtended\HttpMessage\UploadedFileFactory; +use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestFactoryInterface; use Psr\Http\Message\ServerRequestInterface; -use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; +use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\UploadedFileFactoryInterface; +use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; +use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface; class Psr7ServiceProvider extends ServiceProvider { public function register() { - /** @var DiactorosFactory $psr7Factory */ - $psr7Factory = $this->app->make(DiactorosFactory::class); - $this->app->instance('psr7.factory', $psr7Factory); + 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 + ) { + foreach ($aliases as $alias) { + $this->app->bind($alias, $class); + } + } - /** @var Request $request */ - $request = $this->app->get('request'); - $this->app->instance('psr7.request', $request); + $this->app->bind('psr7.request', 'request'); $this->app->bind(ServerRequestInterface::class, 'psr7.request'); - /** @var Response $response */ - $response = $this->app->get('response'); - $this->app->instance('psr7.response', $response); + $this->app->bind('psr7.response', 'response'); $this->app->bind(ResponseInterface::class, 'psr7.response'); } } diff --git a/src/Http/Request.php b/src/Http/Request.php index 06900a18..ee496035 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -2,13 +2,13 @@ namespace Engelsystem\Http; +use PhpExtended\HttpMessage\UploadedFile; +use PhpExtended\HttpMessage\Uri; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\UriInterface; use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyFile; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; -use Zend\Diactoros\UploadedFile; -use Zend\Diactoros\Uri; class Request extends SymfonyRequest implements ServerRequestInterface { @@ -207,7 +207,7 @@ class Request extends SymfonyRequest implements ServerRequestInterface { $uri = parent::getUri(); - return new Uri($uri); + return Uri::parseFromString($uri); } /** @@ -332,11 +332,11 @@ class Request extends SymfonyRequest implements ServerRequestInterface /** @var SymfonyFile $file */ $files[] = new UploadedFile( - $file->getPath(), - $file->getSize(), - $file->getError(), $file->getClientOriginalName(), - $file->getClientMimeType() + $file->getRealPath(), + $file->getMimeType(), + $file->getSize(), + $file->getError() ); } |