Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Illuminate/Routing/Contracts/ControllerDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Illuminate\Routing\Contracts;

use Illuminate\Routing\Route;

interface ControllerDispatcher
{
/**
* Dispatch a request to a given controller and method.
*
* @param Route $route
* @param mixed $controller
* @param string $method
* @return mixed
*/
public function dispatch(Route $route, $controller, $method);

/**
* Get the middleware for the controller instance.
*
* @param \Illuminate\Routing\Controller $controller
* @param string $method
* @return array
*/
public function getMiddleware($controller, $method);
}
5 changes: 3 additions & 2 deletions src/Illuminate/Routing/ControllerDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Illuminate\Routing;

use Illuminate\Container\Container;
use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract;

class ControllerDispatcher
class ControllerDispatcher implements ControllerDispatcherContract
{
use RouteDependencyResolverTrait;

Expand Down Expand Up @@ -54,7 +55,7 @@ public function dispatch(Route $route, $controller, $method)
* @param string $method
* @return array
*/
public static function getMiddleware($controller, $method)
public function getMiddleware($controller, $method)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make it a breaking change, should probably target 5.5 instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appears to have been changed to laravel:master

{
if (! method_exists($controller, 'getMiddleware')) {
return [];
Expand Down
19 changes: 17 additions & 2 deletions src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Routing\Matching\MethodValidator;
use Illuminate\Routing\Matching\SchemeValidator;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract;

class Route
{
Expand Down Expand Up @@ -199,7 +200,7 @@ protected function runCallable()
*/
protected function runController()
{
return (new ControllerDispatcher($this->container))->dispatch(
return $this->controllerDispatcher()->dispatch(
$this, $this->getController(), $this->getControllerMethod()
);
}
Expand Down Expand Up @@ -743,11 +744,25 @@ public function controllerMiddleware()
return [];
}

return ControllerDispatcher::getMiddleware(
return $this->controllerDispatcher()->getMiddleware(
$this->getController(), $this->getControllerMethod()
);
}

/**
* Get the dispatcher for the route's controller.
*
* @return ControllerDispatcherContract
*/
public function controllerDispatcher()
{
if ($this->container->bound(ControllerDispatcherContract::class)) {
return $this->container->make(ControllerDispatcherContract::class);
}

return new ControllerDispatcher($this->container);
}

/**
* Get the route validators for the instance.
*
Expand Down
15 changes: 15 additions & 0 deletions src/Illuminate/Routing/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Illuminate\Contracts\View\Factory as ViewFactoryContract;
use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract;
use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract;

class RoutingServiceProvider extends ServiceProvider
{
Expand All @@ -30,6 +31,8 @@ public function register()
$this->registerPsrResponse();

$this->registerResponseFactory();

$this->registerControllerDispatcher();
}

/**
Expand Down Expand Up @@ -148,4 +151,16 @@ protected function registerResponseFactory()
return new ResponseFactory($app[ViewFactoryContract::class], $app['redirect']);
});
}

/**
* Register the controller dispatcher.
*
* @return void
*/
protected function registerControllerDispatcher()
{
$this->app->singleton(ControllerDispatcherContract::class, function ($app) {
return new ControllerDispatcher($app);
});
}
}