Skip to content

Commit 86d53df

Browse files
authored
Add support for PSR17 (#24)
* Add support for PSR17 * minor
1 parent 2e32e2a commit 86d53df

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"phpunit/phpunit": "^5.4 || ^6.0 || ^7.0"
1717
},
1818
"require-dev": {
19-
"zendframework/zend-diactoros": "^1.0",
20-
"guzzlehttp/psr7": "^1.0",
19+
"zendframework/zend-diactoros": "^1.8",
20+
"guzzlehttp/psr7": "^1.4",
2121
"slim/http": "^0.3",
2222
"nyholm/psr7": "dev-master"
2323
},

src/BaseTest.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use GuzzleHttp\Psr7\UploadedFile as GuzzleUploadedFile;
77
use GuzzleHttp\Psr7\Uri as GuzzleUri;
88
use PHPUnit\Framework\TestCase;
9+
use Psr\Http\Message\UriInterface;
910
use Slim\Http\Uri as SlimUri;
1011
use Zend\Diactoros\Stream as ZendStream;
1112
use Zend\Diactoros\Uri as ZendUri;
@@ -26,11 +27,18 @@ protected function buildUri($uri)
2627
if (defined('URI_FACTORY')) {
2728
$factoryClass = URI_FACTORY;
2829
$factory = new $factoryClass();
29-
if (!$factory instanceof \Http\Message\UriFactory) {
30-
throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a Http\Message\UriFactory');
30+
if ($factory instanceof \Http\Message\UriFactory) {
31+
return $factory->createUri($uri);
3132
}
33+
if ($factory instanceof \Interop\Http\Factory\UriFactoryInterface) {
34+
if ($uri instanceof UriInterface) {
35+
return $uri;
36+
}
3237

33-
return $factory->createUri($uri);
38+
return $factory->createUri($uri);
39+
}
40+
41+
throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a Http\Message\UriFactory or \Interop\Http\Factory\UriFactoryInterface');
3442
}
3543

3644
if (class_exists(GuzzleUri::class)) {
@@ -53,11 +61,18 @@ protected function buildStream($data)
5361
if (defined('STREAM_FACTORY')) {
5462
$factoryClass = STREAM_FACTORY;
5563
$factory = new $factoryClass();
56-
if (!$factory instanceof \Http\Message\StreamFactory) {
57-
throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a Http\Message\StreamFactory');
64+
if ($factory instanceof \Http\Message\StreamFactory) {
65+
return $factory->createStream($data);
66+
}
67+
if ($factory instanceof \Interop\Http\Factory\StreamFactoryInterface) {
68+
if (is_string($data)) {
69+
return $factory->createStream($data);
70+
} else {
71+
return $factory->createStreamFromResource($data);
72+
}
5873
}
5974

60-
return $factory->createStream($data);
75+
throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a Http\Message\StreamFactory or \Interop\Http\Factory\StreamFactoryInterface');
6176
}
6277

6378
if (class_exists(GuzzleStream::class)) {
@@ -80,7 +95,9 @@ protected function buildUploadableFile($data)
8095
throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Interop\Http\Factory\UploadedFileFactoryInterface');
8196
}
8297

83-
return $factory->createUploadedFile($data);
98+
$stream = $this->buildStream($data);
99+
100+
return $factory->createUploadedFile($stream);
84101
}
85102

86103
if (class_exists(GuzzleUploadedFile::class)) {

0 commit comments

Comments
 (0)