PSR-7: Replaced implementation with `Nyholm\Psr7`
This commit is contained in:
parent
d7ad7b0b13
commit
58ca7113f3
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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]);
|
||||
|
|
Loading…
Reference in New Issue