Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hacky first/incomplete implementation of extending existing filters.
The renames to middleware still need to happen, but my gut feeling is that there isn't anything seriously broken with how filters work right now beyond the configration bits.
- Loading branch information
Showing
3 changed files
with
125 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @since 3.0.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Cake\Routing; | ||
|
||
use Cake\Routing\Dispatcher; | ||
|
||
/** | ||
* A factory for creating dispatchers with all the desired middleware | ||
* connected. | ||
* | ||
* ### Adding middleware | ||
* | ||
* ### Adding lazy middleware | ||
*/ | ||
class DispatcherFactory { | ||
|
||
/** | ||
* Stack of middleware to apply to dispatchers. | ||
* | ||
* @var array | ||
*/ | ||
protected static $_stack = []; | ||
|
||
/** | ||
* Add a new middleware object to the stack of middleware | ||
* that will be executed. | ||
* | ||
* @param \Cake\Routing\Middleware $middleware | ||
* @return void | ||
*/ | ||
public static function add($middleware) { | ||
if (is_string($middleware)) { | ||
$middleware = static::_createMiddleware($middleware); | ||
} | ||
static::$_stack[] = $middleware; | ||
} | ||
|
||
/** | ||
* Create a dispatcher that has all the configured middleware applied. | ||
* | ||
* @return \Cake\Routing\Dispatcher | ||
*/ | ||
public static function create() { | ||
$dispatcher = new Dispatcher(); | ||
foreach (static::$_stack as $middleware) { | ||
$dispatcher->add($middleware); | ||
} | ||
return $dispatcher; | ||
} | ||
|
||
/** | ||
* Clear the middleware stack. | ||
* | ||
* @return void | ||
*/ | ||
public static function clear() { | ||
static::$_stack = []; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Cake\Routing\Filter; | ||
|
||
use Cake\Event\Event; | ||
use Cake\Routing\DispatcherFilter; | ||
use Cake\Routing\Router; | ||
|
||
class RoutingFilter extends DispatcherFilter { | ||
|
||
public $priority = -10; | ||
|
||
/** | ||
* Applies Routing and additionalParameters to the request to be dispatched. | ||
* If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run. | ||
* | ||
* @param \Cake\Event\Event $event containing the request, response and additional params | ||
* @return void | ||
*/ | ||
public function beforeDispatch(Event $event) { | ||
$request = $event->data['request']; | ||
Router::setRequestInfo($request); | ||
|
||
if (empty($request->params['controller'])) { | ||
$params = Router::parse($request->url); | ||
$request->addParams($params); | ||
} | ||
} | ||
|
||
} |