diff --git a/composer.json b/composer.json index 0c52879ab4f1..bcaaed20348c 100644 --- a/composer.json +++ b/composer.json @@ -128,6 +128,7 @@ "league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).", "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).", "moontoast/math": "Required to use ordered UUIDs (^1.1).", + "nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).", "pda/pheanstalk": "Required to use the beanstalk queue driver (^4.0).", "psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).", "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0).", diff --git a/src/Illuminate/Routing/RoutingServiceProvider.php b/src/Illuminate/Routing/RoutingServiceProvider.php index 573143d83a08..2406bdc2540f 100755 --- a/src/Illuminate/Routing/RoutingServiceProvider.php +++ b/src/Illuminate/Routing/RoutingServiceProvider.php @@ -2,15 +2,19 @@ namespace Illuminate\Routing; +use Exception; use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract; use Illuminate\Contracts\Routing\UrlGenerator as UrlGeneratorContract; use Illuminate\Contracts\View\Factory as ViewFactoryContract; use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract; use Illuminate\Support\ServiceProvider; +use Nyholm\Psr7\Factory\Psr17Factory; +use Nyholm\Psr7\Response as NyholmPsrResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; -use Zend\Diactoros\Response as PsrResponse; +use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; +use Zend\Diactoros\Response as ZendPsrResponse; class RoutingServiceProvider extends ServiceProvider { @@ -128,7 +132,18 @@ protected function registerRedirector() protected function registerPsrRequest() { $this->app->bind(ServerRequestInterface::class, function ($app) { - return (new DiactorosFactory)->createRequest($app->make('request')); + if (class_exists(PsrHttpFactory::class)) { + $psr17Factory = new Psr17Factory; + + return (new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory)) + ->createRequest($app->make('request')); + } + + if (class_exists(DiactorosFactory::class)) { + return (new DiactorosFactory)->createRequest($app->make('request')); + } + + throw new Exception('Unable to resolve PSR request. Please install symfony/psr-http-message-bridge and nyholm/psr7.'); }); } @@ -140,7 +155,15 @@ protected function registerPsrRequest() protected function registerPsrResponse() { $this->app->bind(ResponseInterface::class, function () { - return new PsrResponse; + if (class_exists(NyholmPsrResponse::class)) { + return new NyholmPsrResponse; + } + + if (class_exists(ZendPsrResponse::class)) { + return new ZendPsrResponse; + } + + throw new Exception('Unable to resolve PSR response. Please install nyholm/psr7.'); }); } diff --git a/src/Illuminate/Routing/composer.json b/src/Illuminate/Routing/composer.json index 0ef281706f5c..2bb1cadb3e67 100644 --- a/src/Illuminate/Routing/composer.json +++ b/src/Illuminate/Routing/composer.json @@ -39,7 +39,8 @@ }, "suggest": { "illuminate/console": "Required to use the make commands (^6.0).", - "symfony/psr-http-message-bridge": "Required to psr7 bridging features (^1.2)." + "nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).", + "symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^1.2)." }, "config": { "sort-packages": true