Skip to content

Commit

Permalink
Merge pull request #31018 from ivannovak/respond-to-symfony-message-b…
Browse files Browse the repository at this point in the history
…ridge-diactoros-removal

[6.x] Utilize Symfony’s PSR Factory
  • Loading branch information
taylorotwell committed Jan 4, 2020
2 parents 81be835 + 3e25c98 commit 15d6744
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -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).",
Expand Down
29 changes: 26 additions & 3 deletions src/Illuminate/Routing/RoutingServiceProvider.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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.');
});
}

Expand All @@ -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.');
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Routing/composer.json
Expand Up @@ -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
Expand Down

0 comments on commit 15d6744

Please sign in to comment.