Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 75af35c

Browse files
committed
Merge branch 'feature/diactoros-dev' into release-3.0.0
Close #580
2 parents 5f46ce4 + aefcb3d commit 75af35c

File tree

6 files changed

+84
-4
lines changed

6 files changed

+84
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Removed
2424

25-
- Nothing.
25+
- [#580](https://github.com/zendframework/zend-expressive/pull/580) removes
26+
zend-diactoros as a requirement; all usages of it within the package are
27+
currently conditional on it being installed, and can be replaced easily with
28+
any other PSR-7 implementation at this time.
2629

2730
### Fixed
2831

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"psr/container": "^1.0",
2828
"psr/http-message": "^1.0.1",
2929
"psr/http-server-middleware": "^1.0",
30-
"zendframework/zend-diactoros": "^1.3.10",
3130
"zendframework/zend-expressive-router": "^3.0.0rc4",
3231
"zendframework/zend-expressive-template": "^2.0.0alpha1",
3332
"zendframework/zend-httphandlerrunner": "^1.0.1",
@@ -41,17 +40,20 @@
4140
"phpstan/phpstan-strict-rules": "^0.9",
4241
"phpunit/phpunit": "^7.0.1",
4342
"zendframework/zend-coding-standard": "~1.0.0",
43+
"zendframework/zend-diactoros": "^1.7.1",
4444
"zendframework/zend-expressive-aurarouter": "^3.0.0rc3",
4545
"zendframework/zend-expressive-fastroute": "^3.0.0rc4",
4646
"zendframework/zend-expressive-zendrouter": "^3.0.0rc3",
4747
"zendframework/zend-servicemanager": "^2.7.8 || ^3.3"
4848
},
4949
"conflict": {
50-
"container-interop/container-interop": "<1.2.0"
50+
"container-interop/container-interop": "<1.2.0",
51+
"zendframework/zend-diactoros": "<1.7.1"
5152
},
5253
"suggest": {
5354
"filp/whoops": "^2.1 to use the Whoops error handler",
5455
"zendframework/zend-auradi-config": "^1.0 to use Aura.Di dependency injection container",
56+
"zendframework/zend-diactoros": "^1.7.1 to use diactoros with default Response, ServerRequest and Stream factories",
5557
"zendframework/zend-expressive-helpers": "^3.0 for its UrlHelper, ServerUrlHelper, and BodyParseMiddleware",
5658
"zendframework/zend-expressive-tooling": "For migration and development tools; require it with the --dev flag",
5759
"zendframework/zend-pimple-config": "^1.0 to use Pimple for dependency injection container",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
<testsuites>
77
<testsuite name="zend-expressive-response-factory">
88
<file>./test/Container/ResponseFactoryFactoryWithoutDiactorosTest.php</file>
9+
<file>./test/Container/ServerRequestFactoryFactoryWithoutDiactorosTest.php</file>
910
<file>./test/Container/StreamFactoryFactoryWithoutDiactorosTest.php</file>
1011
</testsuite>
1112
<testsuite name="zend-expressive">
1213
<directory>./test</directory>
1314
<exclude>./test/Container/ResponseFactoryFactoryWithoutDiactorosTest.php</exclude>
15+
<exclude>./test/Container/ServerRequestFactoryFactoryWithoutDiactorosTest.php</exclude>
1416
<exclude>./test/Container/StreamFactoryFactoryWithoutDiactorosTest.php</exclude>
1517
</testsuite>
1618
</testsuites>

src/Container/ServerRequestFactoryFactory.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Zend\Expressive\Container;
1111

1212
use Psr\Container\ContainerInterface;
13+
use Psr\Http\Message\ServerRequestInterface;
1314
use Zend\Diactoros\ServerRequestFactory;
1415

1516
/**
@@ -25,6 +26,18 @@ class ServerRequestFactoryFactory
2526
{
2627
public function __invoke(ContainerInterface $container) : callable
2728
{
29+
if (! class_exists(ServerRequestFactory::class)) {
30+
throw new Exception\InvalidServiceException(sprintf(
31+
'The %1$s service must map to a factory capable of returning an'
32+
. ' implementation instance. By default, we assume usage of'
33+
. ' zend-diactoros for PSR-7, but it does not appear to be'
34+
. ' present on your system. Please install zendframework/zend-diactoros'
35+
. ' or provide an alternate factory for the %1$s service that'
36+
. ' can produce an appropriate %1$s instance.',
37+
ServerRequestInterface::class
38+
));
39+
}
40+
2841
return function () {
2942
return ServerRequestFactory::fromGlobals();
3043
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Container;
11+
12+
use PHPUnit\Framework\TestCase;
13+
use Prophecy\Prophecy\ObjectProphecy;
14+
use Psr\Container\ContainerInterface;
15+
use Zend\Expressive\Container\Exception\InvalidServiceException;
16+
use Zend\Expressive\Container\ServerRequestFactoryFactory;
17+
18+
class ServerRequestFactoryFactoryWithoutDiactorosTest extends TestCase
19+
{
20+
/** @var ContainerInterface|ObjectProphecy */
21+
private $container;
22+
23+
/** @var ServerRequestFactoryFactory */
24+
private $factory;
25+
26+
/** @var array */
27+
private $autoloadFunctions = [];
28+
29+
protected function setUp()
30+
{
31+
class_exists(InvalidServiceException::class);
32+
33+
$this->container = $this->prophesize(ContainerInterface::class)->reveal();
34+
$this->factory = new ServerRequestFactoryFactory();
35+
36+
$this->autoloadFunctions = spl_autoload_functions();
37+
foreach ($this->autoloadFunctions as $autoloader) {
38+
spl_autoload_unregister($autoloader);
39+
}
40+
}
41+
42+
private function reloadAutoloaders()
43+
{
44+
foreach ($this->autoloadFunctions as $autoloader) {
45+
spl_autoload_register($autoloader);
46+
}
47+
}
48+
49+
public function testFactoryRaisesAnExceptionIfDiactorosIsNotLoaded()
50+
{
51+
$this->expectException(InvalidServiceException::class);
52+
$this->expectExceptionMessage('zendframework/zend-diactoros');
53+
54+
try {
55+
($this->factory)($this->container);
56+
} finally {
57+
$this->reloadAutoloaders();
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)