Permalink
Browse files

Merge branch 'localfilters4.1' of https://github.com/adamwathan/frame…

…work into local-filter
  • Loading branch information...
taylorotwell committed Oct 24, 2013
2 parents d1175f9 + 6b1215a commit d0e0c632e2b3ff15746e48ec7bd57c5cc51d0ae0
Showing with 41 additions and 0 deletions.
  1. +28 −0 src/Illuminate/Routing/Controller.php
  2. +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';
}
}

0 comments on commit d0e0c63

Please sign in to comment.