Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix duplicate route errors when using loadPlugin()
Use the plugin object to load plugin routes. This allows us to disable the hook method so that it is not triggered again. There is still a scenario where a plugin loads routes from another plugin after that plugin's routes() hook has already been called. I'm going to count that as an unlikely scenario. Refs #12130
- Loading branch information
Showing
5 changed files
with
110 additions
and
17 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
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,48 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org) | ||
* @link https://cakephp.org CakePHP(tm) Project | ||
* @since 3.6.6 | ||
* @license https://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace TestApp; | ||
|
||
use Cake\Http\BaseApplication; | ||
use Cake\Routing\Middleware\RoutingMiddleware; | ||
|
||
class ApplicationWithPluginRoutes extends BaseApplication | ||
{ | ||
public function bootstrap() | ||
{ | ||
parent::bootstrap(); | ||
$this->addPlugin('TestPlugin'); | ||
} | ||
|
||
public function middleware($middleware) | ||
{ | ||
$middleware->add(new RoutingMiddleware($this)); | ||
|
||
return $middleware; | ||
} | ||
|
||
/** | ||
* Routes hook, used for testing with RoutingMiddleware. | ||
* | ||
* @param \Cake\Routing\RouteBuilder $routes | ||
* @return void | ||
*/ | ||
public function routes($routes) | ||
{ | ||
$routes->scope('/app', function ($routes) { | ||
$routes->connect('/articles', ['controller' => 'Articles']); | ||
}); | ||
$routes->loadPlugin('TestPlugin'); | ||
} | ||
} |