diff --git a/build/subsplitt/viserio-split-full.sh b/build/subsplitt/viserio-split-full.sh
index 39f0056fa..bbd8b12a9 100644
--- a/build/subsplitt/viserio-split-full.sh
+++ b/build/subsplitt/viserio-split-full.sh
@@ -13,6 +13,7 @@ git subsplit publish src/Viserio/Exception:git@github.com:viserio/exception.git
git subsplit publish src/Viserio/Filesystem:git@github.com:viserio/filesystem.git
git subsplit publish src/Viserio/Hashing:git@github.com:viserio/hashing.git
git subsplit publish src/Viserio/Http:git@github.com:viserio/http.git
+git subsplit publish src/Viserio/HttpFactory:git@github.com:viserio/http-factory.git
git subsplit publish src/Viserio/Log:git@github.com:viserio/log.git
git subsplit publish src/Viserio/Mail:git@github.com:viserio/mail.git
git subsplit publish src/Viserio/Middleware:git@github.com:viserio/middleware.git
diff --git a/build/subsplitt/viserio-split.sh b/build/subsplitt/viserio-split.sh
index f0d925cf7..04e9cd45d 100644
--- a/build/subsplitt/viserio-split.sh
+++ b/build/subsplitt/viserio-split.sh
@@ -13,6 +13,7 @@ git subsplit publish --heads="master 0.10.0-dev" --no-tags src/Viserio/Exception
git subsplit publish --heads="master 0.10.0-dev" --no-tags src/Viserio/Filesystem:git@github.com:viserio/filesystem.git
git subsplit publish --heads="master 0.10.0-dev" --no-tags src/Viserio/Hashing:git@github.com:viserio/hashing.git
git subsplit publish --heads="master 0.10.0-dev" --no-tags src/Viserio/Http:git@github.com:viserio/http.git
+git subsplit publish --heads="master 0.10.0-dev" --no-tags src/Viserio/HttpFactory:git@github.com:viserio/http-factory.git
git subsplit publish --heads="master 0.10.0-dev" --no-tags src/Viserio/Log:git@github.com:viserio/log.git
git subsplit publish --heads="master 0.10.0-dev" --no-tags src/Viserio/Mail:git@github.com:viserio/mail.git
git subsplit publish --heads="master 0.10.0-dev" --no-tags src/Viserio/Middleware:git@github.com:viserio/middleware.git
diff --git a/composer.json b/composer.json
index 34ea12780..bbe400589 100644
--- a/composer.json
+++ b/composer.json
@@ -40,6 +40,7 @@
"danielstjules/stringy" : "^2.3",
"defuse/php-encryption" : "^2.0",
"filp/whoops" : "^2.0",
+ "http-interop/http-factory" : "dev-master",
"league/flysystem" : "^1.0",
"jeremeamia/SuperClosure" : "^2.2",
"monolog/monolog" : "^1.17",
@@ -82,6 +83,7 @@
"viserio/filessystem" : "self.version",
"viserio/hashing" : "self.version",
"viserio/http" : "self.version",
+ "viserio/http-factory" : "self.version",
"viserio/log" : "self.version",
"viserio/mail" : "self.version",
"viserio/middleware" : "self.version",
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 4279064dc..65149ba0b 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -72,6 +72,9 @@
./src/Viserio/Http/Tests
+
+ ./src/Viserio/HttpFactory/Tests
+
./src/Viserio/Log/Tests
diff --git a/src/Viserio/Http/AbstractMessage.php b/src/Viserio/Http/AbstractMessage.php
index 7f3650b74..ad54b3a66 100644
--- a/src/Viserio/Http/AbstractMessage.php
+++ b/src/Viserio/Http/AbstractMessage.php
@@ -186,7 +186,7 @@ public function withoutHeader($header)
public function getBody()
{
if (! $this->stream) {
- $this->stream = (new StreamFactory())->createStreamFromString('');
+ $this->stream = new Stream(fopen('php://temp', 'r+'));
}
return $this->stream;
@@ -247,17 +247,23 @@ protected function setHeaders(array $headers)
*/
protected function createStream($body): StreamInterface
{
- $stream = new StreamFactory();
$type = gettype($body);
if ($body instanceof StreamInterface) {
return $body;
} elseif (is_string($body)) {
- return $stream->createStreamFromString($body);
+ $stream = fopen('php://temp', 'r+');
+
+ if ($body !== '') {
+ fwrite($stream, $body);
+ fseek($stream, 0);
+ }
+
+ return new Stream($stream);
} elseif ($type === 'NULL') {
return new Stream(fopen('php://temp', 'r+'));
} elseif ($type === 'resource') {
- return $stream->createStreamFromResource($body);
+ return new Stream($body);
}
throw new InvalidArgumentException('Invalid resource type: ' . gettype($body));
diff --git a/src/Viserio/Http/RequestFactory.php b/src/Viserio/Http/RequestFactory.php
deleted file mode 100644
index d7398497c..000000000
--- a/src/Viserio/Http/RequestFactory.php
+++ /dev/null
@@ -1,24 +0,0 @@
-createStream());
+ parent::__construct($status, $headers, new Stream(fopen('php://temp', 'r+')));
}
}
diff --git a/src/Viserio/Http/ResponseFactory.php b/src/Viserio/Http/ResponseFactory.php
deleted file mode 100644
index 65b890260..000000000
--- a/src/Viserio/Http/ResponseFactory.php
+++ /dev/null
@@ -1,22 +0,0 @@
-createStreamFromResource(Util::tryFopen($this->filename, $this->mode));
+ return new Stream(Util::tryFopen($this->filename, $this->mode));
}
}
diff --git a/src/Viserio/Http/StreamFactory.php b/src/Viserio/Http/StreamFactory.php
deleted file mode 100644
index a58d0f5c8..000000000
--- a/src/Viserio/Http/StreamFactory.php
+++ /dev/null
@@ -1,54 +0,0 @@
-createStreamFromString(''), [
+ $body = FnStream::decorate(new Stream(fopen('php://temp', 'r+')), [
'__toString' => function () use (&$streamIsRead) {
$streamIsRead = true;
diff --git a/src/Viserio/Http/Tests/ResponseTest.php b/src/Viserio/Http/Tests/ResponseTest.php
index 4b8527716..b27ad1ca4 100644
--- a/src/Viserio/Http/Tests/ResponseTest.php
+++ b/src/Viserio/Http/Tests/ResponseTest.php
@@ -5,8 +5,8 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Viserio\Http\Response;
+use Viserio\Http\Stream;
use Viserio\Http\Stream\FnStream;
-use Viserio\Http\StreamFactory;
class ResponseTest extends AbstractMessageTest
{
@@ -96,7 +96,7 @@ public function testCanConstructWithStatusCode()
public function testConstructorDoesNotReadStreamBody()
{
$streamIsRead = false;
- $body = FnStream::decorate((new StreamFactory())->createStreamFromString(''), [
+ $body = FnStream::decorate(new Stream(fopen('php://temp', 'r+')), [
'__toString' => function () use (&$streamIsRead) {
$streamIsRead = true;
@@ -193,8 +193,13 @@ public function testSameInstanceWhenSameProtocol()
public function testWithBody()
{
- $body = (new StreamFactory())->createStreamFromString('0');
- $response = (new Response())->withBody($body);
+ $body = '0';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $response = (new Response())->withBody(new Stream($stream));
$this->assertInstanceOf(StreamInterface::class, $response->getBody());
$this->assertSame('0', (string) $response->getBody());
diff --git a/src/Viserio/Http/Tests/Stream/ByteCountingStreamTest.php b/src/Viserio/Http/Tests/Stream/ByteCountingStreamTest.php
index 9e96c6c57..5fa480b4e 100644
--- a/src/Viserio/Http/Tests/Stream/ByteCountingStreamTest.php
+++ b/src/Viserio/Http/Tests/Stream/ByteCountingStreamTest.php
@@ -2,8 +2,8 @@
declare(strict_types=1);
namespace Viserio\Http\Tests\Stream;
+use Viserio\Http\Stream;
use Viserio\Http\Stream\ByteCountingStream;
-use Viserio\Http\StreamFactory;
class ByteCountingStreamTest extends \PHPUnit_Framework_TestCase
{
@@ -13,7 +13,13 @@ class ByteCountingStreamTest extends \PHPUnit_Framework_TestCase
*/
public function testEnsureNonNegativeByteCount()
{
- new ByteCountingStream((new StreamFactory())->createStreamFromString('testing'), -2);
+ $body = 'testing';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ new ByteCountingStream(new Stream($stream), -2);
}
/**
@@ -22,19 +28,37 @@ public function testEnsureNonNegativeByteCount()
*/
public function testEnsureValidByteCountNumber()
{
- new ByteCountingStream((new StreamFactory())->createStreamFromString('testing'), 10);
+ $body = 'testing';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ new ByteCountingStream(new Stream($stream), 10);
}
public function testByteCountingReadWhenAvailable()
{
- $testStream = new ByteCountingStream((new StreamFactory())->createStreamFromString('foo bar test'), 8);
+ $body = 'foo bar test';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $testStream = new ByteCountingStream(new Stream($stream), 8);
$this->assertEquals('foo ', $testStream->read(4));
$this->assertEquals('bar ', $testStream->read(4));
$this->assertEquals('', $testStream->read(4));
+ $body = 'testing';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
$testStream->close();
- $testStream = new ByteCountingStream((new StreamFactory())->createStreamFromString('testing'), 5);
+ $testStream = new ByteCountingStream(new Stream($stream), 5);
$testStream->seek(4);
$this->assertEquals('ing', $testStream->read(5));
@@ -48,7 +72,13 @@ public function testByteCountingReadWhenAvailable()
*/
public function testEnsureStopReadWhenHitEof()
{
- $testStream = new ByteCountingStream((new StreamFactory())->createStreamFromString('abc'), 3);
+ $body = 'abc';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $testStream = new ByteCountingStream(new Stream($stream), 3);
$testStream->seek(3);
$testStream->read(3);
}
@@ -59,7 +89,13 @@ public function testEnsureStopReadWhenHitEof()
*/
public function testEnsureReadUnclosedStream()
{
- $body = (new StreamFactory())->createStreamFromString('closed');
+ $body = 'closed';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $body = new Stream($stream);
$closedStream = new ByteCountingStream($body, 5);
$body->close();
$closedStream->read(3);
diff --git a/src/Viserio/Http/Tests/Stream/FnStreamTest.php b/src/Viserio/Http/Tests/Stream/FnStreamTest.php
index 0acbdcc4f..594751893 100644
--- a/src/Viserio/Http/Tests/Stream/FnStreamTest.php
+++ b/src/Viserio/Http/Tests/Stream/FnStreamTest.php
@@ -2,8 +2,8 @@
declare(strict_types=1);
namespace Viserio\Http\Tests\Stream;
+use Viserio\Http\Stream;
use Viserio\Http\Stream\FnStream;
-use Viserio\Http\StreamFactory;
class FnStreamTest extends \PHPUnit_Framework_TestCase
{
@@ -51,7 +51,12 @@ public function doesNotRequireClose()
public function testDecoratesStream()
{
- $stream1 = (new StreamFactory())->createStreamFromString('foo');
+ $body = 'foo';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+ $stream1 = new Stream($stream);
$stream2 = FnStream::decorate($stream1, []);
$this->assertEquals(3, $stream2->getSize());
@@ -80,7 +85,13 @@ public function testDecoratesWithCustomizations()
{
$called = false;
- $stream1 = (new StreamFactory())->createStreamFromString('foo');
+ $body = 'foo';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $stream1 = new Stream($stream);
$stream2 = FnStream::decorate($stream1, [
'read' => function ($len) use (&$called, $stream1) {
$called = true;
diff --git a/src/Viserio/Http/Tests/Stream/LimitStreamTest.php b/src/Viserio/Http/Tests/Stream/LimitStreamTest.php
index 84f25582b..30de6954d 100644
--- a/src/Viserio/Http/Tests/Stream/LimitStreamTest.php
+++ b/src/Viserio/Http/Tests/Stream/LimitStreamTest.php
@@ -7,7 +7,6 @@
use Viserio\Http\Stream\FnStream;
use Viserio\Http\Stream\LimitStream;
use Viserio\Http\Stream\NoSeekStream;
-use Viserio\Http\StreamFactory;
class LimitStreamTest extends \PHPUnit_Framework_TestCase
{
@@ -19,13 +18,19 @@ class LimitStreamTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
- $this->decorated = (new StreamFactory())->createStreamFromResource(fopen(__FILE__, 'r'));
+ $this->decorated = new Stream(fopen(__FILE__, 'r'));
$this->body = new LimitStream($this->decorated, 10, 3);
}
public function testReturnsSubset()
{
- $body = new LimitStream((new StreamFactory())->createStreamFromString('foo'), -1, 1);
+ $body = 'foo';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $body = new LimitStream(new Stream($stream), -1, 1);
$this->assertEquals('oo', (string) $body);
$this->assertTrue($body->eof());
@@ -40,8 +45,13 @@ public function testReturnsSubset()
public function testReturnsSubsetWhenCastToString()
{
- $body = (new StreamFactory())->createStreamFromString('foo_baz_bar');
- $limited = new LimitStream($body, 3, 4);
+ $body = 'foo_baz_bar';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $limited = new LimitStream(new Stream($stream), 3, 4);
$this->assertEquals('baz', (string) $limited);
}
@@ -52,21 +62,31 @@ public function testReturnsSubsetWhenCastToString()
*/
public function testEnsuresPositionCanBeekSeekedTo()
{
- new LimitStream((new StreamFactory())->createStreamFromString(''), 0, 10);
+ new LimitStream(new Stream(fopen('php://temp', 'r+')), 0, 10);
}
public function testReturnsSubsetOfEmptyBodyWhenCastToString()
{
- $body = (new StreamFactory())->createStreamFromString('01234567891234');
- $limited = new LimitStream($body, 0, 10);
+ $body = '01234567891234';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $limited = new LimitStream(new Stream($stream), 0, 10);
$this->assertEquals('', (string) $limited);
}
public function testReturnsSpecificSubsetOBodyWhenCastToString()
{
- $body = (new StreamFactory())->createStreamFromString('0123456789abcdef');
- $limited = new LimitStream($body, 3, 10);
+ $body = '0123456789abcdef';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $limited = new LimitStream(new Stream($stream), 3, 10);
$this->assertEquals('abc', (string) $limited);
}
@@ -126,7 +146,13 @@ public function testReadsOnlySubsetOfData()
*/
public function testThrowsWhenCurrentGreaterThanOffsetSeek()
{
- $stream1 = (new StreamFactory())->createStreamFromString('foo_bar');
+ $body = 'foo_bar';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $stream1 = new Stream($stream);
$stream2 = new NoSeekStream($stream1);
$stream3 = new LimitStream($stream2);
@@ -136,7 +162,13 @@ public function testThrowsWhenCurrentGreaterThanOffsetSeek()
public function testCanGetContentsWithoutSeeking()
{
- $stream1 = (new StreamFactory())->createStreamFromString('foo_bar');
+ $body = 'foo_bar';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $stream1 = new Stream($stream);
$stream2 = new NoSeekStream($stream1);
$stream3 = new LimitStream($stream2);
@@ -159,7 +191,13 @@ public function testContentLengthIsBounded()
public function testGetContentsIsBasedOnSubset()
{
- $body = new LimitStream((new StreamFactory())->createStreamFromString('foobazbar'), 3, 3);
+ $body = 'foobazbar';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $body = new LimitStream(new Stream($stream), 3, 3);
$this->assertEquals('baz', $body->getContents());
}
@@ -180,7 +218,13 @@ public function testReturnsNullIfSizeCannotBeDetermined()
public function testLengthLessOffsetWhenNoLimitSize()
{
- $a = (new StreamFactory())->createStreamFromString('foo_bar');
+ $body = 'foo_bar';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $a = new Stream($stream);
$b = new LimitStream($a, -1, 4);
$this->assertEquals(3, $b->getSize());
diff --git a/src/Viserio/Http/Tests/Stream/NoSeekStreamTest.php b/src/Viserio/Http/Tests/Stream/NoSeekStreamTest.php
index 55b756983..0a5cfd208 100644
--- a/src/Viserio/Http/Tests/Stream/NoSeekStreamTest.php
+++ b/src/Viserio/Http/Tests/Stream/NoSeekStreamTest.php
@@ -3,8 +3,8 @@
namespace Viserio\Http\Tests\Stream;
use Psr\Http\Message\StreamInterface;
+use Viserio\Http\Stream;
use Viserio\Http\Stream\NoSeekStream;
-use Viserio\Http\StreamFactory;
class NoSeekStreamTest extends \PHPUnit_Framework_TestCase
{
@@ -32,7 +32,13 @@ public function testCannotSeek()
*/
public function testHandlesClose()
{
- $s = (new StreamFactory())->createStreamFromString('foo');
+ $body = 'foo';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $s = new Stream($stream);
$wrapped = new NoSeekStream($s);
$wrapped->close();
$wrapped->write('foo');
diff --git a/src/Viserio/Http/Tests/Stream/PumpStreamTest.php b/src/Viserio/Http/Tests/Stream/PumpStreamTest.php
index ee0810e05..57d12ee02 100644
--- a/src/Viserio/Http/Tests/Stream/PumpStreamTest.php
+++ b/src/Viserio/Http/Tests/Stream/PumpStreamTest.php
@@ -2,10 +2,10 @@
declare(strict_types=1);
namespace Viserio\Http\Tests\Stream;
+use ArrayIterator;
use RuntimeException;
use Viserio\Http\Stream\LimitStream;
use Viserio\Http\Stream\PumpStream;
-use Viserio\Http\StreamFactory;
class PumpStreamTest extends \PHPUnit_Framework_TestCase
{
@@ -24,7 +24,7 @@ public function testHasMetadataAndSize()
public function testCanReadFromCallable()
{
- $pump = (new StreamFactory())->createStreamFromCallback(function ($size) {
+ $pump = new PumpStream(function ($size) {
return 'a';
});
@@ -38,7 +38,7 @@ public function testStoresExcessDataInBuffer()
{
$called = [];
- $pump = (new StreamFactory())->createStreamFromCallback(function ($size) use (&$called) {
+ $pump = new PumpStream(function ($size) use (&$called) {
$called[] = $size;
return 'abcdef';
@@ -53,7 +53,7 @@ public function testStoresExcessDataInBuffer()
public function testInifiniteStreamWrappedInLimitStream()
{
- $pump = (new StreamFactory())->createStreamFromCallback(function () {
+ $pump = new PumpStream(function () {
return 'a';
});
$s = new LimitStream($pump, 5);
@@ -63,7 +63,7 @@ public function testInifiniteStreamWrappedInLimitStream()
public function testDescribesCapabilities()
{
- $pump = (new StreamFactory())->createStreamFromCallback(function () {
+ $pump = new PumpStream(function () {
});
$this->assertTrue($pump->isReadable());
@@ -84,4 +84,31 @@ public function testDescribesCapabilities()
} catch (RuntimeException $e) {
}
}
+
+ public function testCanCreateCallableBasedStream()
+ {
+ $resource = new ArrayIterator(['foo', 'bar', '123']);
+
+ $stream = new PumpStream(function () use ($resource) {
+ if (! $resource->valid()) {
+ return false;
+ }
+
+ $result = $resource->current();
+ $resource->next();
+
+ return $result;
+ });
+
+ $this->assertInstanceOf(PumpStream::class, $stream);
+ $this->assertEquals('foo', $stream->read(3));
+ $this->assertFalse($stream->eof());
+ $this->assertEquals('b', $stream->read(1));
+ $this->assertEquals('a', $stream->read(1));
+ $this->assertEquals('r12', $stream->read(3));
+ $this->assertFalse($stream->eof());
+ $this->assertEquals('3', $stream->getContents());
+ $this->assertTrue($stream->eof());
+ $this->assertEquals(9, $stream->tell());
+ }
}
diff --git a/src/Viserio/Http/Tests/StreamFactoryTest.php b/src/Viserio/Http/Tests/StreamFactoryTest.php
deleted file mode 100644
index c14e1b875..000000000
--- a/src/Viserio/Http/Tests/StreamFactoryTest.php
+++ /dev/null
@@ -1,89 +0,0 @@
-createStreamFromResource($resource);
-
- $this->assertEquals(10, $stream->tell());
-
- $stream->close();
- }
-
- public function testCreatesWithFactory()
- {
- $streamFactory = new StreamFactory();
- $stream = $streamFactory->createStreamFromString('foo');
-
- $this->assertInstanceOf(Stream::class, $stream);
- $this->assertEquals('foo', $stream->getContents());
-
- $stream->close();
- }
-
- public function testFactoryCreatesFromEmptyString()
- {
- $streamFactory = new StreamFactory();
- $this->assertInstanceOf(Stream::class, $streamFactory->createStream());
- }
-
- public function testFactoryCreatesFromResource()
- {
- $resource = fopen(__FILE__, 'r');
- $streamFactory = new StreamFactory();
- $stream = $streamFactory->createStreamFromResource($resource);
-
- $this->assertInstanceOf(Stream::class, $stream);
- $this->assertSame(file_get_contents(__FILE__), (string) $stream);
- }
-
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Invalid resource type: string.
- */
- public function testFactoryCreatesFromResourceToThorwException()
- {
- $streamFactory = new StreamFactory();
- $stream = $streamFactory->createStreamFromResource('foo');
- }
-
- public function testCanCreateCallableBasedStream()
- {
- $resource = new ArrayIterator(['foo', 'bar', '123']);
-
- $streamFactory = new StreamFactory();
- $stream = $streamFactory->createStreamFromCallback(function () use ($resource) {
- if (! $resource->valid()) {
- return false;
- }
-
- $result = $resource->current();
- $resource->next();
-
- return $result;
- });
-
- $this->assertInstanceOf(PumpStream::class, $stream);
- $this->assertEquals('foo', $stream->read(3));
- $this->assertFalse($stream->eof());
- $this->assertEquals('b', $stream->read(1));
- $this->assertEquals('a', $stream->read(1));
- $this->assertEquals('r12', $stream->read(3));
- $this->assertFalse($stream->eof());
- $this->assertEquals('3', $stream->getContents());
- $this->assertTrue($stream->eof());
- $this->assertEquals(9, $stream->tell());
- }
-}
diff --git a/src/Viserio/Http/Tests/StreamTest.php b/src/Viserio/Http/Tests/StreamTest.php
index 51b3c0d1c..8d0426410 100644
--- a/src/Viserio/Http/Tests/StreamTest.php
+++ b/src/Viserio/Http/Tests/StreamTest.php
@@ -5,7 +5,6 @@
use Exception;
use Viserio\Http\Stream;
use Viserio\Http\Stream\NoSeekStream;
-use Viserio\Http\StreamFactory;
class StreamTest extends \PHPUnit_Framework_TestCase
{
@@ -179,9 +178,15 @@ public function testCloseClearProperties()
public function testDoesNotThrowInToString()
{
- $s = (new StreamFactory())->createStreamFromString('foo');
- $s = new NoSeekStream($s);
+ $body = 'foo';
+ $stream = fopen('php://temp', 'r+');
- $this->assertEquals('foo', (string) $s);
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $stream = new Stream($stream);
+ $stream = new NoSeekStream($stream);
+
+ $this->assertEquals('foo', (string) $stream);
}
}
diff --git a/src/Viserio/Http/Tests/UploadedFileTest.php b/src/Viserio/Http/Tests/UploadedFileTest.php
index a05ea9e42..2f00f9653 100644
--- a/src/Viserio/Http/Tests/UploadedFileTest.php
+++ b/src/Viserio/Http/Tests/UploadedFileTest.php
@@ -4,7 +4,6 @@
use ReflectionProperty;
use Viserio\Http\Stream;
-use Viserio\Http\StreamFactory;
use Viserio\Http\UploadedFile;
class UploadedFileTest extends \PHPUnit_Framework_TestCase
@@ -158,7 +157,13 @@ public function testGetStreamReturnsStreamForFile()
public function testSuccessful()
{
- $stream = (new StreamFactory())->createStreamFromString('Foo bar!');
+ $body = 'Foo bar!';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $stream = new Stream($stream);
$upload = new UploadedFile($stream, $stream->getSize(), UPLOAD_ERR_OK, 'filename.txt', 'text/plain');
$this->assertEquals($stream->getSize(), $upload->getSize());
@@ -194,7 +199,13 @@ public function invalidMovePaths()
*/
public function testMoveRaisesExceptionForInvalidPath($path)
{
- $stream = (new StreamFactory())->createStreamFromString('Foo bar!');
+ $body = 'Foo bar!';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $stream = new Stream($stream);
$upload = new UploadedFile($stream, 0, UPLOAD_ERR_OK);
$this->cleanup[] = $path;
@@ -208,7 +219,13 @@ public function testMoveRaisesExceptionForInvalidPath($path)
*/
public function testMoveCannotBeCalledMoreThanOnce()
{
- $stream = (new StreamFactory())->createStreamFromString('Foo bar!');
+ $body = 'Foo bar!';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $stream = new Stream($stream);
$upload = new UploadedFile($stream, 0, UPLOAD_ERR_OK);
$this->cleanup[] = $to = tempnam(sys_get_temp_dir(), 'diac');
@@ -226,7 +243,13 @@ public function testMoveCannotBeCalledMoreThanOnce()
*/
public function testCannotRetrieveStreamAfterMove()
{
- $stream = (new StreamFactory())->createStreamFromString('Foo bar!');
+ $body = 'Foo bar!';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $stream = new Stream($stream);
$upload = new UploadedFile($stream, 0, UPLOAD_ERR_OK);
$this->cleanup[] = $to = tempnam(sys_get_temp_dir(), 'diac');
diff --git a/src/Viserio/Http/Tests/UtilTest.php b/src/Viserio/Http/Tests/UtilTest.php
index 127ff390f..79e88d843 100644
--- a/src/Viserio/Http/Tests/UtilTest.php
+++ b/src/Viserio/Http/Tests/UtilTest.php
@@ -2,8 +2,8 @@
declare(strict_types=1);
namespace Viserio\Http\Tests;
+use Viserio\Http\Stream;
use Viserio\Http\Stream\FnStream;
-use Viserio\Http\StreamFactory;
use Viserio\Http\UploadedFile;
use Viserio\Http\Util;
@@ -11,7 +11,13 @@ class UtilTest extends \PHPUnit_Framework_TestCase
{
public function testCopiesToString()
{
- $s = (new StreamFactory())->createStreamFromString('foobaz');
+ $body = 'foobaz';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $s = new Stream($stream);
$this->assertEquals('foobaz', Util::copyToString($s));
$s->seek(0);
@@ -22,7 +28,13 @@ public function testCopiesToString()
public function testCopiesToStringStopsWhenReadFails()
{
- $s1 = (new StreamFactory())->createStreamFromString('foobaz');
+ $body = 'foobaz';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $s1 = new Stream($stream);
$s1 = FnStream::decorate($s1, [
'read' => function () {
return '';
@@ -35,12 +47,18 @@ public function testCopiesToStringStopsWhenReadFails()
public function testCopiesToStream()
{
- $s1 = (new StreamFactory())->createStreamFromString('foobaz');
- $s2 = (new StreamFactory())->createStreamFromString('');
+ $body = 'foobaz';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $s1 = new Stream($stream);
+ $s2 = new Stream(fopen('php://temp', 'r+'));
Util::copyToStream($s1, $s2);
$this->assertEquals('foobaz', (string) $s2);
- $s2 = (new StreamFactory())->createStreamFromString('');
+ $s2 = new Stream(fopen('php://temp', 'r+'));
$s1->seek(0);
Util::copyToStream($s1, $s2, 3);
@@ -65,7 +83,7 @@ public function testCopyToStreamReadsInChunksInsteadOfAllInMemory()
},
]);
- $s2 = (new StreamFactory())->createStreamFromString('');
+ $s2 = new Stream(fopen('php://temp', 'r+'));
Util::copyToStream($s1, $s2, 16394);
$s2->seek(0);
@@ -78,8 +96,14 @@ public function testCopyToStreamReadsInChunksInsteadOfAllInMemory()
public function testStopsCopyToStreamWhenWriteFails()
{
- $s1 = (new StreamFactory())->createStreamFromString('foobaz');
- $s2 = (new StreamFactory())->createStreamFromString('');
+ $body = 'foobaz';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $s1 = new Stream($stream);
+ $s2 = new Stream(fopen('php://temp', 'r+'));
$s2 = FnStream::decorate($s2, ['write' => function () {
return 0;
}]);
@@ -90,8 +114,14 @@ public function testStopsCopyToStreamWhenWriteFails()
public function testStopsCopyToSteamWhenWriteFailsWithMaxLen()
{
- $s1 = (new StreamFactory())->createStreamFromString('foobaz');
- $s2 = (new StreamFactory())->createStreamFromString('');
+ $body = 'foobaz';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $s1 = new Stream($stream);
+ $s2 = new Stream(fopen('php://temp', 'r+'));
$s2 = FnStream::decorate($s2, ['write' => function () {
return 0;
}]);
@@ -102,11 +132,17 @@ public function testStopsCopyToSteamWhenWriteFailsWithMaxLen()
public function testStopsCopyToSteamWhenReadFailsWithMaxLen()
{
- $s1 = (new StreamFactory())->createStreamFromString('foobaz');
+ $body = 'foobaz';
+ $stream = fopen('php://temp', 'r+');
+
+ fwrite($stream, $body);
+ fseek($stream, 0);
+
+ $s1 = new Stream($stream);
$s1 = FnStream::decorate($s1, ['read' => function () {
return '';
}]);
- $s2 = (new StreamFactory())->createStreamFromString('');
+ $s2 = new Stream(fopen('php://temp', 'r+'));
Util::copyToStream($s1, $s2, 10);
$this->assertEquals('', (string) $s2);
diff --git a/src/Viserio/Http/UploadedFileFactory.php b/src/Viserio/Http/UploadedFileFactory.php
deleted file mode 100644
index 91f78c1f1..000000000
--- a/src/Viserio/Http/UploadedFileFactory.php
+++ /dev/null
@@ -1,24 +0,0 @@
- **Note:** If you want to build an application using Narrowspark, visit the main [![Source Code](http://img.shields.io/badge/source-narrowspark/narrowspark-blue.svg?style=flat-square)](https://github.com/narrowspark/narrowspark).
+
+## Contributing
+
+Issues for this package shall be posted on [Narrowspark framework issues](http://github.com/narrowspark/framework/issues).
+Thank you for considering contributing to the Narrowspark framework! The contribution guide can be found in the [Narrowspark documentation](http://narrowspark.de/docs/contributions).
+
+## Installation
+
+Use [Composer](https://getcomposer.org/) to install this package:
+
+```sh
+composer require viserio/http-factory
+```
+
+## Official Documentation
+
+Documentation for the framework can be found on the [Narrowspark website](http://narrowspark.de/docs).
+
+### License
+
+The Narrowspark framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
diff --git a/src/Viserio/HttpFactory/RequestFactory.php b/src/Viserio/HttpFactory/RequestFactory.php
new file mode 100644
index 000000000..1b52d0859
--- /dev/null
+++ b/src/Viserio/HttpFactory/RequestFactory.php
@@ -0,0 +1,21 @@
+factory = new RequestFactory();
+ }
+
+ public function dataMethods()
+ {
+ return [
+ ['GET'],
+ ['POST'],
+ ['PUT'],
+ ['DELETE'],
+ ['OPTIONS'],
+ ['HEAD'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataMethods
+ */
+ public function testCreateRequest($method)
+ {
+ $uri = 'http://example.com/';
+ $request = $this->factory->createRequest($method, $uri);
+
+ $this->assertRequest($request, $method, $uri);
+ }
+
+ public function testCreateRequestWithUri()
+ {
+ $uriFactory = new UriFactory();
+ $method = 'GET';
+ $uri = 'http://example.com/';
+ $request = $this->factory->createRequest($method, $uriFactory->createUri($uri));
+
+ $this->assertRequest($request, $method, $uri);
+ }
+
+ private function assertRequest($request, $method, $uri)
+ {
+ $this->assertInstanceOf(RequestInterface::class, $request);
+ $this->assertSame($method, $request->getMethod());
+ $this->assertSame($uri, (string) $request->getUri());
+ }
+}
diff --git a/src/Viserio/HttpFactory/Tests/ResponseFactoryTest.php b/src/Viserio/HttpFactory/Tests/ResponseFactoryTest.php
new file mode 100644
index 000000000..18bdde84a
--- /dev/null
+++ b/src/Viserio/HttpFactory/Tests/ResponseFactoryTest.php
@@ -0,0 +1,43 @@
+factory = new ResponseFactory();
+ }
+
+ public function dataCodes()
+ {
+ return [
+ [200],
+ [301],
+ [404],
+ [500],
+ ];
+ }
+
+ /**
+ * @dataProvider dataCodes
+ */
+ public function testCreateResponse($code)
+ {
+ $response = $this->factory->createResponse($code);
+
+ $this->assertResponse($response, $code);
+ }
+
+ private function assertResponse($response, $code)
+ {
+ $this->assertInstanceOf(ResponseInterface::class, $response);
+
+ $this->assertSame($code, $response->getStatusCode());
+ }
+}
diff --git a/src/Viserio/Http/Tests/ServerRequestFactoryTest.php b/src/Viserio/HttpFactory/Tests/ServerRequestFactoryTest.php
similarity index 93%
rename from src/Viserio/Http/Tests/ServerRequestFactoryTest.php
rename to src/Viserio/HttpFactory/Tests/ServerRequestFactoryTest.php
index 2b52cde03..2103fc1a0 100644
--- a/src/Viserio/Http/Tests/ServerRequestFactoryTest.php
+++ b/src/Viserio/HttpFactory/Tests/ServerRequestFactoryTest.php
@@ -1,13 +1,22 @@
factory = new ServerRequestFactory();
+ }
+
public function dataGetUriFromGlobals()
{
$server = [
@@ -78,7 +87,7 @@ public function dataGetUriFromGlobals()
public function testGetUriFromGlobals($expected, $serverParams)
{
$_SERVER = $serverParams;
- $serverRequest = (new ServerRequestFactory())->createServerRequestFromGlobals();
+ $serverRequest = $this->factory->createServerRequestFromGlobals();
$this->assertEquals(new Uri($expected), $serverRequest->getUri());
}
@@ -136,7 +145,7 @@ public function testFromGlobals()
],
];
- $server = (new ServerRequestFactory())->createServerRequestFromGlobals();
+ $server = $this->factory->createServerRequestFromGlobals();
$this->assertEquals('POST', $server->getMethod());
$this->assertEquals(['Host' => ['www.narrowspark.com']], $server->getHeaders());
diff --git a/src/Viserio/HttpFactory/Tests/StreamFactoryTest.php b/src/Viserio/HttpFactory/Tests/StreamFactoryTest.php
new file mode 100644
index 000000000..5c5beb698
--- /dev/null
+++ b/src/Viserio/HttpFactory/Tests/StreamFactoryTest.php
@@ -0,0 +1,67 @@
+factory = new StreamFactory();
+ }
+
+ public function testCreateStream()
+ {
+ $resource = tmpfile();
+ $stream = $this->factory->createStream($resource);
+ $this->assertStream($stream, '');
+ }
+
+ private function assertStream($stream, $content)
+ {
+ $this->assertInstanceOf(StreamInterface::class, $stream);
+ $this->assertSame($content, (string) $stream);
+ }
+
+ public function testKeepsPositionOfResource()
+ {
+ $resource = fopen(__FILE__, 'r');
+ fseek($resource, 10);
+
+ $stream = $this->factory->createStream($resource);
+
+ $this->assertEquals(10, $stream->tell());
+
+ $stream->close();
+ }
+
+ public function testCreatesWithFactory()
+ {
+ $stream = $this->factory->createStream('foo');
+
+ $this->assertInstanceOf(Stream::class, $stream);
+ $this->assertEquals('foo', $stream->getContents());
+
+ $stream->close();
+ }
+
+ public function testFactoryCreatesFromEmptyString()
+ {
+ $this->assertInstanceOf(Stream::class, $this->factory->createStream(''));
+ }
+
+ public function testFactoryCreatesFromResource()
+ {
+ $resource = fopen(__FILE__, 'r');
+ $stream = $this->factory->createStream($resource);
+
+ $this->assertInstanceOf(Stream::class, $stream);
+ $this->assertSame(file_get_contents(__FILE__), (string) $stream);
+ }
+}
diff --git a/src/Viserio/HttpFactory/Tests/UploadedFileFactoryTest.php b/src/Viserio/HttpFactory/Tests/UploadedFileFactoryTest.php
new file mode 100644
index 000000000..e6a696d9b
--- /dev/null
+++ b/src/Viserio/HttpFactory/Tests/UploadedFileFactoryTest.php
@@ -0,0 +1,79 @@
+factory = new UploadedFileFactory();
+ }
+
+ public function testCreateUploadedFileWithString()
+ {
+ $filename = tempnam(sys_get_temp_dir(), 'http-factory-test');
+ $content = 'i made this!';
+ $size = strlen($content);
+
+ file_put_contents($filename, $content);
+
+ $file = $this->factory->createUploadedFile($filename);
+
+ $this->assertUploadedFile($file, $content, $size);
+
+ unlink($filename);
+ }
+
+ public function testCreateUploadedFileWithClientFilenameAndMediaType()
+ {
+ $tmpfname = tempnam('/tmp', 'foo');
+ $upload = fopen($tmpfname, 'w+');
+ $content = 'this is your capitan speaking';
+ $error = \UPLOAD_ERR_OK;
+ $clientFilename = 'test.txt';
+ $clientMediaType = 'text/plain';
+ fwrite($upload, $content);
+ $file = $this->factory->createUploadedFile(
+ $tmpfname,
+ strlen($content),
+ $error,
+ $clientFilename,
+ $clientMediaType
+ );
+
+ $this->assertUploadedFile($file, $content, null, $error, $clientFilename, $clientMediaType);
+ }
+
+ public function testCreateUploadedFileWithError()
+ {
+ $upload = tmpfile();
+ $error = \UPLOAD_ERR_NO_FILE;
+ $file = $this->factory->createUploadedFile($upload, null, $error);
+
+ // Cannot use assertUploadedFile() here because the error prevents
+ // fetching the content stream.
+ $this->assertInstanceOf(UploadedFileInterface::class, $file);
+ $this->assertSame($error, $file->getError());
+ }
+
+ private function assertUploadedFile(
+ $file,
+ $content,
+ $size = null,
+ $error = null,
+ $clientFilename = null,
+ $clientMediaType = null
+ ) {
+ $this->assertInstanceOf(UploadedFileInterface::class, $file);
+ $this->assertSame($content, (string) $file->getStream());
+ $this->assertSame($size ?: strlen($content), $file->getSize());
+ $this->assertSame($error ?: UPLOAD_ERR_OK, $file->getError());
+ $this->assertSame($clientFilename, $file->getClientFilename());
+ $this->assertSame($clientMediaType, $file->getClientMediaType());
+ }
+}
diff --git a/src/Viserio/HttpFactory/UploadedFileFactory.php b/src/Viserio/HttpFactory/UploadedFileFactory.php
new file mode 100644
index 000000000..2b1d3913a
--- /dev/null
+++ b/src/Viserio/HttpFactory/UploadedFileFactory.php
@@ -0,0 +1,50 @@
+getSize($file, $size),
+ $error,
+ $clientFilename,
+ $clientMediaType
+ );
+ }
+
+ /**
+ * Detect the Uploaded file size
+ *
+ * @param mixed $file
+ * @param int|null $size
+ *
+ * @return int
+ */
+ protected function getSize($file, $size): int
+ {
+ if (null !== $size) {
+ return $size;
+ }
+
+ if (is_string($file)) {
+ return filesize($file);
+ }
+
+ return fstat($file)['size'];
+ }
+}
diff --git a/src/Viserio/HttpFactory/UriFactory.php b/src/Viserio/HttpFactory/UriFactory.php
new file mode 100644
index 000000000..dab67d9a0
--- /dev/null
+++ b/src/Viserio/HttpFactory/UriFactory.php
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+ ./Tests/
+
+
+
+
+
+ ./
+
+ ./vendor
+ ./Tests
+
+
+
+
+
diff --git a/src/Viserio/Routing/Tests/Fixture/ControllerClosureMiddleware.php b/src/Viserio/Routing/Tests/Fixture/ControllerClosureMiddleware.php
index ae7ffa7ed..c1366213d 100644
--- a/src/Viserio/Routing/Tests/Fixture/ControllerClosureMiddleware.php
+++ b/src/Viserio/Routing/Tests/Fixture/ControllerClosureMiddleware.php
@@ -6,7 +6,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Viserio\Contracts\Middleware\Delegate as DelegateContract;
use Viserio\Contracts\Middleware\ServerMiddleware as ServerMiddlewareContract;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\StreamFactory;
class ControllerClosureMiddleware implements ServerMiddlewareContract
{
@@ -16,7 +16,7 @@ public function process(
): ResponseInterface {
$response = $frame->next($request);
- $response = $response->withBody((new StreamFactory())->createStreamFromString(
+ $response = $response->withBody((new StreamFactory())->createStream(
$response->getBody() . '-' . $request->getAttribute('foo-middleware') . '-controller-closure'
));
diff --git a/src/Viserio/Routing/Tests/Fixture/FakeMiddleware.php b/src/Viserio/Routing/Tests/Fixture/FakeMiddleware.php
index 2718d83ec..76d2196f2 100644
--- a/src/Viserio/Routing/Tests/Fixture/FakeMiddleware.php
+++ b/src/Viserio/Routing/Tests/Fixture/FakeMiddleware.php
@@ -6,7 +6,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Viserio\Contracts\Middleware\Delegate as DelegateContract;
use Viserio\Contracts\Middleware\ServerMiddleware as ServerMiddlewareContract;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\StreamFactory;
class FakeMiddleware implements ServerMiddlewareContract
{
@@ -18,7 +18,7 @@ public function process(
return $response->withBody(
(new StreamFactory())
- ->createStreamFromString('caught')
+ ->createStream('caught')
);
}
}
diff --git a/src/Viserio/Routing/Tests/Fixture/FooMiddleware.php b/src/Viserio/Routing/Tests/Fixture/FooMiddleware.php
index 8b052e6ac..1268976e4 100644
--- a/src/Viserio/Routing/Tests/Fixture/FooMiddleware.php
+++ b/src/Viserio/Routing/Tests/Fixture/FooMiddleware.php
@@ -6,7 +6,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Viserio\Contracts\Middleware\Delegate as DelegateContract;
use Viserio\Contracts\Middleware\ServerMiddleware as ServerMiddlewareContract;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\StreamFactory;
class FooMiddleware implements ServerMiddlewareContract
{
diff --git a/src/Viserio/Routing/Tests/Fixture/RouteTestClosureMiddlewareController.php b/src/Viserio/Routing/Tests/Fixture/RouteTestClosureMiddlewareController.php
index d7dd99cbd..352f98aeb 100644
--- a/src/Viserio/Routing/Tests/Fixture/RouteTestClosureMiddlewareController.php
+++ b/src/Viserio/Routing/Tests/Fixture/RouteTestClosureMiddlewareController.php
@@ -2,8 +2,8 @@
declare(strict_types=1);
namespace Viserio\Routing\Tests\Fixture;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
use Viserio\Routing\AbstractController;
class RouteTestClosureMiddlewareController extends AbstractController
@@ -19,7 +19,7 @@ public function index()
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('index')
+ ->createStream('index')
);
}
}
diff --git a/src/Viserio/Routing/Tests/Router/BasicParameterPatternsRouterTest.php b/src/Viserio/Routing/Tests/Router/BasicParameterPatternsRouterTest.php
index d41732fe4..45b13e2c2 100644
--- a/src/Viserio/Routing/Tests/Router/BasicParameterPatternsRouterTest.php
+++ b/src/Viserio/Routing/Tests/Router/BasicParameterPatternsRouterTest.php
@@ -3,8 +3,8 @@
namespace Viserio\Routing\Tests\Router;
use Viserio\Contracts\Routing\Pattern;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
class BasicParameterPatternsRouterTest extends RouteRouterBaseTest
{
@@ -111,7 +111,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['param'] . ' | ' . $args['name'])
+ ->createStream($args['param'] . ' | ' . $args['name'])
);
})->where('param', Pattern::DIGITS)->setParameter('name', 'digits');
@@ -120,7 +120,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['param'] . ' | ' . $args['name'])
+ ->createStream($args['param'] . ' | ' . $args['name'])
);
})->where('param', Pattern::ALPHA)->setParameter('name', 'alpha');
@@ -129,7 +129,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['param'] . ' | ' . $args['name'])
+ ->createStream($args['param'] . ' | ' . $args['name'])
);
})->where('param', Pattern::ALPHA_LOWER)->setParameter('name', 'alpha_low');
@@ -138,7 +138,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['param'] . ' | ' . $args['name'])
+ ->createStream($args['param'] . ' | ' . $args['name'])
);
})->where('param', Pattern::ALPHA_UPPER)->setParameter('name', 'alpha_up');
@@ -147,7 +147,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['param'] . ' | ' . $args['name'])
+ ->createStream($args['param'] . ' | ' . $args['name'])
);
})->where('param', Pattern::ALPHA_NUM)->setParameter('name', 'alpha_num');
@@ -156,7 +156,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['param'] . ' | ' . $args['name'])
+ ->createStream($args['param'] . ' | ' . $args['name'])
);
})->where('param', Pattern::ALPHA_NUM_DASH)->setParameter('name', 'alpha_num_dash');
@@ -165,7 +165,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['param'] . ' | ' . $args['name'])
+ ->createStream($args['param'] . ' | ' . $args['name'])
);
})->where('param', Pattern::ANY)->setParameter('name', 'any');
@@ -174,7 +174,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['param'] . ' | ' . $args['name'])
+ ->createStream($args['param'] . ' | ' . $args['name'])
);
})->where('param', '[\!]{3,5}')->setParameter('name', 'custom');
}
diff --git a/src/Viserio/Routing/Tests/Router/BasicRestfulRouterTest.php b/src/Viserio/Routing/Tests/Router/BasicRestfulRouterTest.php
index b153daadb..1cd550918 100644
--- a/src/Viserio/Routing/Tests/Router/BasicRestfulRouterTest.php
+++ b/src/Viserio/Routing/Tests/Router/BasicRestfulRouterTest.php
@@ -3,8 +3,8 @@
namespace Viserio\Routing\Tests\Router;
use Viserio\Contracts\Routing\Pattern;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
class BasicRestfulRouterTest extends RouteRouterBaseTest
{
@@ -68,7 +68,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | ' . ($args['id'] ?? ''))
+ ->createStream($args['name'] . ' | ' . ($args['id'] ?? ''))
);
})->setParameter('name', 'user.index');
$router->get('/user/create', function ($request, $args) {
@@ -76,7 +76,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | ' . ($args['id'] ?? ''))
+ ->createStream($args['name'] . ' | ' . ($args['id'] ?? ''))
);
})->setParameter('name', 'user.create');
$router->post('/user', function ($request, $args) {
@@ -84,7 +84,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | ' . ($args['id'] ?? ''))
+ ->createStream($args['name'] . ' | ' . ($args['id'] ?? ''))
);
})->setParameter('name', 'user.save');
$router->get('/user/{id}', function ($request, $args) {
@@ -92,7 +92,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | ' . ($args['id'] ?? ''))
+ ->createStream($args['name'] . ' | ' . ($args['id'] ?? ''))
);
})->setParameter('name', 'user.show');
$router->get('/user/{id}/edit', function ($request, $args) {
@@ -100,7 +100,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | ' . ($args['id'] ?? ''))
+ ->createStream($args['name'] . ' | ' . ($args['id'] ?? ''))
);
})->setParameter('name', 'user.edit');
$router->put('/user/{id}', function ($request, $args) {
@@ -108,7 +108,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | ' . ($args['id'] ?? ''))
+ ->createStream($args['name'] . ' | ' . ($args['id'] ?? ''))
);
})->setParameter('name', 'user.update');
$router->delete('/user/{id}', function ($request, $args) {
@@ -116,7 +116,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | ' . ($args['id'] ?? ''))
+ ->createStream($args['name'] . ' | ' . ($args['id'] ?? ''))
);
})->setParameter('name', 'user.delete');
$router->patch('/admin/{id}', function ($request, $args) {
@@ -124,7 +124,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | ' . ($args['id'] ?? ''))
+ ->createStream($args['name'] . ' | ' . ($args['id'] ?? ''))
);
})->setParameter('name', 'admin.patch');
$router->options('/options', function ($request, $args) {
@@ -132,7 +132,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | ' . $args['digits'])
+ ->createStream($args['name'] . ' | ' . $args['digits'])
);
})->setParameter('name', 'options');
}
diff --git a/src/Viserio/Routing/Tests/Router/CommonRouteSegmentRouterTest.php b/src/Viserio/Routing/Tests/Router/CommonRouteSegmentRouterTest.php
index 730e025b5..b56075e73 100644
--- a/src/Viserio/Routing/Tests/Router/CommonRouteSegmentRouterTest.php
+++ b/src/Viserio/Routing/Tests/Router/CommonRouteSegmentRouterTest.php
@@ -3,8 +3,8 @@
namespace Viserio\Routing\Tests\Router;
use Viserio\Contracts\Routing\Pattern;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
class CommonrouteregmentRouterTest extends RouteRouterBaseTest
{
@@ -37,7 +37,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | p1 = ' . $args['p1'] . ' | p2 = ' . $args['p2'] . ' | p3 = ' . $args['p3'])
+ ->createStream($args['name'] . ' | p1 = ' . $args['p1'] . ' | p2 = ' . $args['p2'] . ' | p3 = ' . $args['p3'])
);
})->setParameter('name', 'route1');
$router->get('/route2/{p1}/{p2}/{p3}', function ($request, $args) {
@@ -45,7 +45,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | p1 = ' . $args['p1'] . ' | p2 = ' . $args['p2'] . ' | p3 = ' . $args['p3'])
+ ->createStream($args['name'] . ' | p1 = ' . $args['p1'] . ' | p2 = ' . $args['p2'] . ' | p3 = ' . $args['p3'])
);
})->setParameter('name', 'route2');
$router->get('/route3/{p1}/{p2}/{p3}', function ($request, $args) {
@@ -53,7 +53,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | p1 = ' . $args['p1'] . ' | p2 = ' . $args['p2'] . ' | p3 = ' . $args['p3'])
+ ->createStream($args['name'] . ' | p1 = ' . $args['p1'] . ' | p2 = ' . $args['p2'] . ' | p3 = ' . $args['p3'])
);
})->setParameter('name', 'route3');
$router->get('/route4/{p1}/{p2}/{p3}', function ($request, $args) {
@@ -61,7 +61,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | p1 = ' . $args['p1'] . ' | p2 = ' . $args['p2'] . ' | p3 = ' . $args['p3'])
+ ->createStream($args['name'] . ' | p1 = ' . $args['p1'] . ' | p2 = ' . $args['p2'] . ' | p3 = ' . $args['p3'])
);
})->setParameter('name', 'route4');
$router->get('/route5/{p_1}/{p_2}/{p_3}', function ($request, $args) {
@@ -69,7 +69,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | p_1 = ' . $args['p_1'] . ' | p_2 = ' . $args['p_2'] . ' | p_3 = ' . $args['p_3'])
+ ->createStream($args['name'] . ' | p_1 = ' . $args['p_1'] . ' | p_2 = ' . $args['p_2'] . ' | p_3 = ' . $args['p_3'])
);
})->setParameter('name', 'route5');
$router->get('/route6/{p_1}/{p2}/{p_3}', function ($request, $args) {
@@ -77,7 +77,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | p_1 = ' . $args['p_1'] . ' | p2 = ' . $args['p2'] . ' | p_3 = ' . $args['p_3'])
+ ->createStream($args['name'] . ' | p_1 = ' . $args['p_1'] . ' | p2 = ' . $args['p2'] . ' | p_3 = ' . $args['p_3'])
);
})->setParameter('name', 'route6');
}
diff --git a/src/Viserio/Routing/Tests/Router/ComplexParameterPatternsRouterTest.php b/src/Viserio/Routing/Tests/Router/ComplexParameterPatternsRouterTest.php
index dca8ff28c..d3195d434 100644
--- a/src/Viserio/Routing/Tests/Router/ComplexParameterPatternsRouterTest.php
+++ b/src/Viserio/Routing/Tests/Router/ComplexParameterPatternsRouterTest.php
@@ -3,8 +3,8 @@
namespace Viserio\Routing\Tests\Router;
use Viserio\Contracts\Routing\Pattern;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
class ComplexParameterPatternsRouterTest extends RouteRouterBaseTest
{
@@ -77,7 +77,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | param = ' . $args['param'])
+ ->createStream($args['name'] . ' | param = ' . $args['param'])
);
})->setParameter('name', 'prefix');
$router->get('/b/{param}:suffix', function ($request, $args) {
@@ -85,7 +85,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | param = ' . $args['param'])
+ ->createStream($args['name'] . ' | param = ' . $args['param'])
);
})->setParameter('name', 'suffix');
$router->get('/c/prefix:{param}:suffix', function ($request, $args) {
@@ -93,7 +93,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | param = ' . $args['param'])
+ ->createStream($args['name'] . ' | param = ' . $args['param'])
);
})->setParameter('name', 'prefix-and-suffix');
$router->get('/d/{param1}-{param2}:{param3}', function ($request, $args) {
@@ -101,7 +101,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['name'] . ' | param1 = ' . $args['param1'] . ' | param2 = ' . $args['param2'] . ' | param3 = ' . $args['param3'])
+ ->createStream($args['name'] . ' | param1 = ' . $args['param1'] . ' | param2 = ' . $args['param2'] . ' | param3 = ' . $args['param3'])
);
})->setParameter('name', 'multi-param');
$router->get('/e/{digits}-{alpha}:{exclaim}', function ($request, $args) {
@@ -109,7 +109,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['routename'] . ' | digits = ' . $args['digits'] . ' | alpha = ' . $args['alpha'] . ' | exclaim = ' . $args['exclaim'])
+ ->createStream($args['routename'] . ' | digits = ' . $args['digits'] . ' | alpha = ' . $args['alpha'] . ' | exclaim = ' . $args['exclaim'])
);
})
->where('digits', Pattern::DIGITS)
@@ -121,7 +121,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString($args['routename'] . ' | name = ' . $args['name'] . ' | thing = ' . $args['thing'])
+ ->createStream($args['routename'] . ' | name = ' . $args['name'] . ' | thing = ' . $args['thing'])
);
})->where('name', '[A-Z]?[a-z]+')
->where('thing', Pattern::ALPHA_LOWER)
diff --git a/src/Viserio/Routing/Tests/Router/ComplexShopRouterTest.php b/src/Viserio/Routing/Tests/Router/ComplexShopRouterTest.php
index 8aaddc4de..69526da02 100644
--- a/src/Viserio/Routing/Tests/Router/ComplexShopRouterTest.php
+++ b/src/Viserio/Routing/Tests/Router/ComplexShopRouterTest.php
@@ -3,8 +3,8 @@
namespace Viserio\Routing\Tests\Router;
use Viserio\Contracts\Routing\Pattern;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
class ComplexShopRouterTest extends RouteRouterBaseTest
{
@@ -122,7 +122,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'home');
$router->get('/about-us', function ($request, $args) {
@@ -130,7 +130,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'about-us');
$router->get('/contact-us', function ($request, $args) {
@@ -138,7 +138,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'contact-us');
$router->post('/contact-us', function ($request, $args) {
@@ -146,7 +146,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'contact-us.submit');
@@ -155,7 +155,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'blog.index');
$router->get('/blog/recent', function ($request, $args) {
@@ -163,7 +163,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'blog.recent');
$router->get('/blog/post/{post_slug}', function ($request, $args) {
@@ -171,7 +171,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'])
+ ->createStream('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'])
);
})->setParameter('name', 'blog.post.show');
$router->post('/blog/post/{post_slug}/comment', function ($request, $args) {
@@ -179,7 +179,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'])
+ ->createStream('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'])
);
})->setParameter('name', 'blog.post.comment');
@@ -188,7 +188,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'shop.index');
@@ -197,7 +197,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'shop.category.index');
$router->get('/shop/category/search/{filter_by}:{filter_value}', function ($request, $args) {
@@ -205,7 +205,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | filter_by = ' . $args['filter_by'] . ' | filter_value = ' . $args['filter_value'])
+ ->createStream('name = ' . $args['name'] . ' | filter_by = ' . $args['filter_by'] . ' | filter_value = ' . $args['filter_value'])
);
})->setParameter('name', 'shop.category.search');
$router->get('/shop/category/{category_id}', function ($request, $args) {
@@ -213,7 +213,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
+ ->createStream('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
);
})->setParameter('name', 'shop.category.show');
$router->get('/shop/category/{category_id}/product', function ($request, $args) {
@@ -221,7 +221,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
+ ->createStream('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
);
})->setParameter('name', 'shop.category.product.index');
$router->get('/shop/category/{category_id}/product/search/{filter_by}:{filter_value}', function ($request, $args) {
@@ -229,7 +229,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'] . ' | filter_by = ' . $args['filter_by'] . ' | filter_value = ' . $args['filter_value'])
+ ->createStream('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'] . ' | filter_by = ' . $args['filter_by'] . ' | filter_value = ' . $args['filter_value'])
);
})->setParameter('name', 'shop.category.product.search');
@@ -238,7 +238,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'shop.product.index');
$router->get('/shop/product/search/{filter_by}:{filter_value}', function ($request, $args) {
@@ -246,7 +246,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | filter_by = ' . $args['filter_by'] . ' | filter_value = ' . $args['filter_value'])
+ ->createStream('name = ' . $args['name'] . ' | filter_by = ' . $args['filter_by'] . ' | filter_value = ' . $args['filter_value'])
);
})->setParameter('name', 'shop.product.search');
$router->get('/shop/product/{product_id}', function ($request, $args) {
@@ -254,7 +254,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
+ ->createStream('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
);
})->setParameter('name', 'shop.product.show');
@@ -263,7 +263,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'shop.cart.show');
$router->put('/shop/cart', function ($request, $args) {
@@ -271,7 +271,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'shop.cart.add');
$router->delete('/shop/cart', function ($request, $args) {
@@ -279,7 +279,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'shop.cart.empty');
$router->get('/shop/cart/checkout', function ($request, $args) {
@@ -287,7 +287,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'shop.cart.checkout.show');
$router->post('/shop/cart/checkout', function ($request, $args) {
@@ -295,7 +295,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'shop.cart.checkout.process');
@@ -304,7 +304,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.login');
$router->post('/admin/login', function ($request, $args) {
@@ -312,7 +312,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.login.submit');
$router->get('/admin/logout', function ($request, $args) {
@@ -320,7 +320,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.logout');
$router->get('/admin', function ($request, $args) {
@@ -328,7 +328,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.index');
@@ -337,7 +337,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.product.index');
$router->get('/admin/product/create', function ($request, $args) {
@@ -345,7 +345,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.product.create');
$router->post('/admin/product', function ($request, $args) {
@@ -353,7 +353,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.product.store');
$router->get('/admin/product/{product_id}', function ($request, $args) {
@@ -361,7 +361,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
+ ->createStream('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
);
})->setParameter('name', 'admin.product.show');
$router->get('/admin/product/{product_id}/edit', function ($request, $args) {
@@ -369,7 +369,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
+ ->createStream('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
);
})->setParameter('name', 'admin.product.edit');
$router->match(['PUT', 'PATCH'], '/admin/product/{product_id}', function ($request, $args) {
@@ -377,7 +377,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
+ ->createStream('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
);
})->setParameter('name', 'admin.product.update');
$router->delete('/admin/product/{product_id}', function ($request, $args) {
@@ -385,7 +385,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
+ ->createStream('name = ' . $args['name'] . ' | product_id = ' . $args['product_id'])
);
})->setParameter('name', 'admin.product.destroy');
@@ -394,7 +394,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.category.index');
$router->get('/admin/category/create', function ($request, $args) {
@@ -402,7 +402,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.category.create');
$router->post('/admin/category', function ($request, $args) {
@@ -410,7 +410,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'admin.category.store');
$router->get('/admin/category/{category_id}', function ($request, $args) {
@@ -418,7 +418,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
+ ->createStream('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
);
})->setParameter('name', 'admin.category.show');
$router->get('/admin/category/{category_id}/edit', function ($request, $args) {
@@ -426,7 +426,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
+ ->createStream('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
);
})->setParameter('name', 'admin.category.edit');
$router->match(['PUT', 'PATCH'], '/admin/category/{category_id}', function ($request, $args) {
@@ -434,7 +434,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
+ ->createStream('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
);
})->setParameter('name', 'admin.category.update');
$router->delete('/admin/category/{category_id}', function ($request, $args) {
@@ -442,7 +442,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
+ ->createStream('name = ' . $args['name'] . ' | category_id = ' . $args['category_id'])
);
})->setParameter('name', 'admin.category.destroy');
}
diff --git a/src/Viserio/Routing/Tests/Router/EdgeCasesRouterTest.php b/src/Viserio/Routing/Tests/Router/EdgeCasesRouterTest.php
index 537be3d06..27169e0ba 100644
--- a/src/Viserio/Routing/Tests/Router/EdgeCasesRouterTest.php
+++ b/src/Viserio/Routing/Tests/Router/EdgeCasesRouterTest.php
@@ -3,8 +3,8 @@
namespace Viserio\Routing\Tests\Router;
use Viserio\Contracts\Routing\Pattern;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
class EdgeCasesRouterTest extends RouteRouterBaseTest
{
@@ -52,7 +52,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | param = ' . $args['param'])
+ ->createStream('name = ' . $args['name'] . ' | param = ' . $args['param'])
);
})->setParameter('name', 'middle-param');
$router->get('/123/{param}/bar', function ($request, $args) {
@@ -60,7 +60,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | param = ' . $args['param'])
+ ->createStream('name = ' . $args['name'] . ' | param = ' . $args['param'])
);
})->where('param', '.*')->setParameter('name', 'all-middle-param');
$router->get('/string', function ($request, $args) {
@@ -68,7 +68,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('some-string'));
+ ->createStream('some-string'));
});
// Order of precedence:
@@ -81,7 +81,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'http-method-fallback.static');
$router->any('/http/method/fallback', function ($request, $args) {
@@ -89,7 +89,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'http-method-fallback.static.fallback');
$router->post('/http/method/{parameter}', function ($request, $args) {
@@ -97,7 +97,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | parameter = ' . $args['parameter'])
+ ->createStream('name = ' . $args['name'] . ' | parameter = ' . $args['parameter'])
);
})->setParameter('name', 'http-method-fallback.dynamic');
$router->any('/http/method/{parameter}', function ($request, $args) {
@@ -105,7 +105,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | parameter = ' . $args['parameter'])
+ ->createStream('name = ' . $args['name'] . ' | parameter = ' . $args['parameter'])
);
})->setParameter('name', 'http-method-fallback.dynamic.fallback');
@@ -115,7 +115,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'allowed-methods.static');
$router->post('/allowed-methods/{parameter}', function ($request, $args) {
@@ -123,7 +123,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | parameter = ' . $args['parameter'])
+ ->createStream('name = ' . $args['name'] . ' | parameter = ' . $args['parameter'])
);
})->setParameter('name', 'allowed-methods.dynamic');
$router->get('/complex-methods/{param}/foo/bar', function ($request, $args) {
@@ -131,7 +131,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | param = ' . $args['param'])
+ ->createStream('name = ' . $args['name'] . ' | param = ' . $args['param'])
);
})->where('param', Pattern::DIGITS)->setParameter('name', 'complex-methods.first');
$router->post('/complex-methods/{param}/foo/{param2}', function ($request, $args) {
@@ -139,7 +139,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | param = ' . $args['param'] . ' | param2 = ' . $args['param2'])
+ ->createStream('name = ' . $args['name'] . ' | param = ' . $args['param'] . ' | param2 = ' . $args['param2'])
);
})->where('param', Pattern::ALPHA_NUM)->setParameter('name', 'complex-methods.second');
$router->post('/complex-methods/{param}/{param2}', function ($request, $args) {
@@ -147,7 +147,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | param = ' . $args['param'] . ' | param2 = ' . $args['param2'])
+ ->createStream('name = ' . $args['name'] . ' | param = ' . $args['param'] . ' | param2 = ' . $args['param2'])
);
})->where('param', Pattern::ALPHA_NUM)->setParameter('name', 'complex-methods.second');
}
diff --git a/src/Viserio/Routing/Tests/Router/HttpMethodRouterTest.php b/src/Viserio/Routing/Tests/Router/HttpMethodRouterTest.php
index 6206f0569..c591f4381 100644
--- a/src/Viserio/Routing/Tests/Router/HttpMethodRouterTest.php
+++ b/src/Viserio/Routing/Tests/Router/HttpMethodRouterTest.php
@@ -2,8 +2,8 @@
declare(strict_types=1);
namespace Viserio\Routing\Tests\Router;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
class HttpMethodRouterTest extends RouteRouterBaseTest
{
@@ -28,7 +28,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'home.get');
@@ -37,7 +37,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'home.post-or-patch');
@@ -46,7 +46,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'home.delete');
@@ -55,7 +55,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'home.fallback');
}
diff --git a/src/Viserio/Routing/Tests/Router/InlineParameterRouterTest.php b/src/Viserio/Routing/Tests/Router/InlineParameterRouterTest.php
index fd33e5924..6d3c2769d 100644
--- a/src/Viserio/Routing/Tests/Router/InlineParameterRouterTest.php
+++ b/src/Viserio/Routing/Tests/Router/InlineParameterRouterTest.php
@@ -2,8 +2,8 @@
declare(strict_types=1);
namespace Viserio\Routing\Tests\Router;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
class InlineParameterRouterTest extends RouteRouterBaseTest
{
@@ -49,7 +49,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'home');
@@ -58,7 +58,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'])
+ ->createStream('name = ' . $args['name'])
);
})->setParameter('name', 'blog.index');
$router->get('/blog/post/{post_slug:[a-z0-9\-]+}', function ($request, $args) {
@@ -66,7 +66,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'])
+ ->createStream('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'])
);
})->setParameter('name', 'blog.post.show');
$router->post('/blog/post/{post_slug:[a-z0-9\-]+}/comment', function ($request, $args) {
@@ -74,7 +74,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'])
+ ->createStream('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'])
);
})->setParameter('name', 'blog.post.comment');
$router->get('/blog/post/{post_slug:[a-z0-9\-]+}/comment/{comment_id:[0-9]+}', function ($request, $args) {
@@ -82,7 +82,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'] . ' | comment_id = ' . $args['comment_id'])
+ ->createStream('name = ' . $args['name'] . ' | post_slug = ' . $args['post_slug'] . ' | comment_id = ' . $args['comment_id'])
);
})->setParameter('name', 'blog.post.comment.show');
}
diff --git a/src/Viserio/Routing/Tests/Router/RootRoutesRouterTest.php b/src/Viserio/Routing/Tests/Router/RootRoutesRouterTest.php
index 40930f109..719ac466f 100644
--- a/src/Viserio/Routing/Tests/Router/RootRoutesRouterTest.php
+++ b/src/Viserio/Routing/Tests/Router/RootRoutesRouterTest.php
@@ -2,8 +2,8 @@
declare(strict_types=1);
namespace Viserio\Routing\Tests\Router;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\StreamFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\StreamFactory;
use Viserio\Routing\Tests\Fixture\FakeMiddleware;
use Viserio\Routing\Tests\Fixture\FooMiddleware;
use Viserio\Routing\Tests\Fixture\RouteTestClosureMiddlewareController;
@@ -38,7 +38,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('Hello')
+ ->createStream('Hello')
);
})->setParameter('name', 'root');
@@ -47,7 +47,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('Hello')
+ ->createStream('Hello')
);
})->setParameter('name', 'root');
@@ -56,7 +56,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('Hello')
+ ->createStream('Hello')
);
})->setParameter('name', 'root-slash');
@@ -65,7 +65,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('Hello')
+ ->createStream('Hello')
);
})->setParameter('name', 'root-slash');
@@ -75,7 +75,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('Middleware')
+ ->createStream('Middleware')
);
}])->setParameter('name', 'middleware');
$router->get('/middleware2', ['middleware.with' => new FakeMiddleware(), 'uses' => function ($request, $args) {
@@ -83,7 +83,7 @@ protected function definitions($router)
->createResponse()
->withBody(
(new StreamFactory())
- ->createStreamFromString('Middleware')
+ ->createStream('Middleware')
);
}])->setParameter('name', 'middleware2');
diff --git a/src/Viserio/Routing/Tests/Router/RouteRouterBaseTest.php b/src/Viserio/Routing/Tests/Router/RouteRouterBaseTest.php
index 70666e23c..d79a78b5b 100644
--- a/src/Viserio/Routing/Tests/Router/RouteRouterBaseTest.php
+++ b/src/Viserio/Routing/Tests/Router/RouteRouterBaseTest.php
@@ -5,8 +5,8 @@
use Interop\Container\ContainerInterface;
use Narrowspark\TestingHelper\Traits\MockeryTrait;
use ReflectionClass;
-use Viserio\Http\ResponseFactory;
-use Viserio\Http\ServerRequestFactory;
+use Viserio\HttpFactory\ResponseFactory;
+use Viserio\HttpFactory\ServerRequestFactory;
use Viserio\Routing\Router;
abstract class RouteRouterBaseTest extends \PHPUnit_Framework_TestCase
diff --git a/src/Viserio/Routing/composer.json b/src/Viserio/Routing/composer.json
index ec591ba95..628007527 100644
--- a/src/Viserio/Routing/composer.json
+++ b/src/Viserio/Routing/composer.json
@@ -32,7 +32,7 @@
"narrowspark/testing-helper" : "^1.5",
"mockery/mockery" : "^0.9.5",
"phpunit/phpunit" : "^5.1",
- "viserio/http" : "self.version"
+ "viserio/http-factory" : "self.version"
},
"autoload": {
"psr-4": {