Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
41 additions
and
0 deletions.
-
+28
−0
src/Illuminate/Routing/Controller.php
-
+13
−0
tests/Routing/RoutingRouteTest.php
|
@@ -65,6 +65,10 @@ protected function parseFilter($filter, array $options) |
|
|
{ |
|
|
$filter = $this->registerClosureFilter($filter); |
|
|
} |
|
|
elseif ($this->isInstanceFilter($filter)) |
|
|
{ |
|
|
$filter = $this->registerInstanceFilter($filter); |
|
|
} |
|
|
else |
|
|
{ |
|
|
list($filter, $parameters) = Route::parseFilter($filter); |
|
@@ -86,6 +90,30 @@ protected function registerClosureFilter(Closure $filter) |
|
|
return $name; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Check if a filter is a local method |
|
|
* @param mixed $filter |
|
|
* @return boolean |
|
|
*/ |
|
|
protected function isInstanceFilter($filter) |
|
|
{ |
|
|
return is_string($filter) and starts_with($filter, '@'); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Register a controller instance method as a filter. |
|
|
* |
|
|
* @param string $filter |
|
|
* @return string |
|
|
*/ |
|
|
protected function registerInstanceFilter($filter) |
|
|
{ |
|
|
$name = substr($filter, 1); |
|
|
$this->getFilterer()->filter($filter, array($controller = $this, $name)); |
|
|
|
|
|
return $filter; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Get the registered "before" filters. |
|
|
* |
|
|
|
@@ -72,6 +72,10 @@ public function testDispatchingOfControllers() |
|
|
}); |
|
|
$router->get('bar', 'RouteTestControllerDispatchStub@bar'); |
|
|
$this->assertEquals('filter', $router->dispatch(Request::create('bar', 'GET'))->getContent()); |
|
|
|
|
|
$router = $this->getRouter(); |
|
|
$router->get('baz', 'RouteTestControllerDispatchStub@baz'); |
|
|
$this->assertEquals('filtered', $router->dispatch(Request::create('baz', 'GET'))->getContent()); |
|
|
|
|
|
|
|
|
/** |
|
@@ -515,6 +519,7 @@ class RouteTestControllerDispatchStub extends Illuminate\Routing\Controller { |
|
|
public function __construct() |
|
|
{ |
|
|
$this->beforeFilter('foo', array('only' => 'bar')); |
|
|
$this->beforeFilter('@filter', array('only' => 'baz')); |
|
|
} |
|
|
public function foo() |
|
|
{ |
|
@@ -524,6 +529,14 @@ public function bar() |
|
|
{ |
|
|
return 'baz'; |
|
|
} |
|
|
public function filter() |
|
|
{ |
|
|
return 'filtered'; |
|
|
} |
|
|
public function baz() |
|
|
{ |
|
|
return 'baz'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|