New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.0 middleware events #3495
Merged
Merged
3.0 middleware events #3495
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0adf133
Hacky first/incomplete implementation of extending existing filters.
markstory 36066a2
Add docs for features that are coming soon.
markstory 7d9217b
Add very basic test for DispatcherFactory.
markstory 5ad0d6f
Start test cases for middleware.
markstory 7a808d0
Implement matches() and add in progress test cases.
markstory 3c86c3f
Implement remaining tests for DispatcherFilter.
markstory 0c95f47
Mark broken tests as incomplete and remove dead code.
markstory c0666fb
Make priority a configuration value.
markstory 5e7677b
Add tests for RoutingFilter.
markstory 275a4b9
Remove old filter tests, and update asset dispatcher tests.
markstory e6092c1
Move AssetDispatcher tests to correct test file.
markstory a33ee0c
Move CacheDispatcher tests into their own file.
markstory 65f4a12
Clean up remaining dispatcher tests.
markstory 25c5cc3
Add string filter support.
markstory d367c8a
Remove additionalParams and update RequestActionTrait tests.
markstory 2177707
Fix failing tests in ControllerTestCase.
markstory 7db068c
Add a convention for dispatcher filter names.
markstory 9b7c82d
Add missing doc blocks and rename methods to be more consistent.
markstory a9d3a61
Allow an array of options to be passed into a dispatcher filter.
markstory c8baef1
Expand on docs around event priorities.
markstory 4803c4a
Move controller resolution into a separate dispatcher filter.
markstory d2a8a9e
Remove constructor that does nothing other than bad things.
markstory 6fc2fd1
Make RoutingFilter apply after Asset and Cache filters.
markstory 7301b32
CS fix
lorenzo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,103 @@ | ||
<?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\Core\App; | ||
use Cake\Routing\Dispatcher; | ||
use Cake\Routing\Error\MissingDispatcherFilterException; | ||
|
||
/** | ||
* A factory for creating dispatchers with all the desired middleware | ||
* connected. | ||
*/ | ||
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. | ||
* | ||
* Instances of filters will be re-used across all sub-requests | ||
* in a request. | ||
* | ||
* @param string|\Cake\Routing\DispatcherFilter $filter Either the classname of the filter | ||
* or an instance to use. | ||
* @param array $options Constructor arguments/options for the filter if you are using a string name. | ||
* If you are passing an instance, this argument will be ignored. | ||
* @return \Cake\Routing\DispatcherFilter | ||
*/ | ||
public static function add($filter, array $options = []) { | ||
if (is_string($filter)) { | ||
$filter = static::_createFilter($filter, $options); | ||
} | ||
static::$_stack[] = $filter; | ||
return $filter; | ||
} | ||
|
||
/** | ||
* Create an instance of a filter. | ||
* | ||
* @param string $name The name of the filter to build. | ||
* @param array $options Constructor arguments/options for the filter. | ||
* @return \Cake\Routing\DispatcherFilter | ||
* @throws \Cake\Routing\Error\MissingDispatcherFilterException When filters cannot be found. | ||
*/ | ||
protected static function _createFilter($name, $options) { | ||
$className = App::className($name, 'Routing/Filter', 'Filter'); | ||
if (!$className) { | ||
$msg = sprintf('Cannot locate dispatcher filter named "%s".', $name); | ||
throw new MissingDispatcherFilterException($msg); | ||
} | ||
return new $className($options); | ||
} | ||
|
||
/** | ||
* 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->addFilter($middleware); | ||
} | ||
return $dispatcher; | ||
} | ||
|
||
/** | ||
* Get the connected dispatcher filters. | ||
* | ||
* @return array | ||
*/ | ||
public static function filters() { | ||
return static::$_stack; | ||
} | ||
|
||
/** | ||
* Clear the middleware stack. | ||
* | ||
* @return void | ||
*/ | ||
public static function clear() { | ||
static::$_stack = []; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's odd it is called filters here but middleware in the Dispatcher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed my mind halfway through, I will make things use filter consistently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now.