Skip to content
Permalink
Browse files

Deprecate Plugin::routes()

I missed this earlier as I had updated my applications and removed this
line. With this method undeprecated plugins will have their routes
loaded twice. Once by Application::pluginRoutes() and again by
Plugin::routes(). Because we're trending away from static APIs, and the
`BasePlugin::route()`` gives more control/flexibility I'm deprecating
this method.

Refs #12130
  • Loading branch information...
markstory committed May 26, 2018
1 parent 5c6ba95 commit d339699a1c701ea01db954dfe5859a35e080a595
Showing with 48 additions and 32 deletions.
  1. +7 −0 src/Core/Plugin.php
  2. +41 −32 tests/TestCase/Core/PluginTest.php
@@ -337,9 +337,16 @@ public static function bootstrap($name)
* @param string|null $name name of the plugin, if null will operate on all
* plugins having enabled the loading of routes files.
* @return bool
* @deprecated 3.6.5 This method is no longer needed when using HttpApplicationInterface based applications.
* This method will be removed in 4.0.0
*/
public static function routes($name = null)
{
deprecationWarning(
'You no longer need to call `Plugin::routes()` after upgrading to use Http\Server. ' .
'See https://book.cakephp.org/3.0/en/development/application.html#adding-the-new-http-stack-to-an-existing-application ' .
'for upgrade information.'
);
if ($name === null) {
foreach (static::loaded() as $p) {
static::routes($p);
@@ -177,16 +177,19 @@ public function testLoadWithBootstrapDisableBootstrapHook()
/**
* Tests loading a plugin with bootstrap file and routes file
*
* @deprecated
* @return void
*/
public function testLoadSingleWithBootstrapAndRoutes()
{
Plugin::load('TestPlugin', ['bootstrap' => true, 'routes' => true]);
$this->assertTrue(Plugin::loaded('TestPlugin'));
$this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
Plugin::routes();
$this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes'));
$this->deprecated(function () {
Plugin::load('TestPlugin', ['bootstrap' => true, 'routes' => true]);
$this->assertTrue(Plugin::loaded('TestPlugin'));
$this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
Plugin::routes();
$this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes'));
});
}
/**
@@ -247,16 +250,19 @@ public function testLoadMultipleWithDefaultsAndOverride()
/**
* Test ignoring missing bootstrap/routes file
*
* @deprecated
* @return void
*/
public function testIgnoreMissingFiles()
{
Plugin::loadAll([[
'bootstrap' => true,
'routes' => true,
'ignoreMissing' => true
]]);
$this->assertTrue(Plugin::routes());
$this->deprecated(function () {
Plugin::loadAll([[
'bootstrap' => true,
'routes' => true,
'ignoreMissing' => true
]]);
$this->assertTrue(Plugin::routes());
});
}
/**
@@ -390,29 +396,32 @@ public function testLoadAllWithDefaults()
* Tests that Plugin::loadAll() will load all plugins in the configured folder wit defaults
* and overrides for a plugin
*
* @deprecated
* @return void
*/
public function testLoadAllWithDefaultsAndOverride()
{
Plugin::loadAll([
['bootstrap' => true, 'ignoreMissing' => true],
'TestPlugin' => ['routes' => true],
'TestPluginFour' => ['bootstrap' => true, 'classBase' => '']
]);
Plugin::routes();
$expected = [
'Company', 'ParentPlugin', 'PluginJs', 'TestPlugin',
'TestPluginFour', 'TestPluginTwo', 'TestTheme'
];
$this->assertEquals($expected, Plugin::loaded());
$this->assertEquals('loaded js plugin bootstrap', Configure::read('PluginTest.js_plugin.bootstrap'));
$this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes'));
$this->assertNull(Configure::read('PluginTest.test_plugin.bootstrap'));
$this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
$this->assertEquals('loaded plugin four bootstrap', Configure::read('PluginTest.test_plugin_four.bootstrap'));
// TestPluginThree won't get loaded by loadAll() since it's in a sub directory.
$this->assertNull(Configure::read('PluginTest.test_plugin_three.bootstrap'));
$this->deprecated(function () {
Plugin::loadAll([
['bootstrap' => true, 'ignoreMissing' => true],
'TestPlugin' => ['routes' => true],
'TestPluginFour' => ['bootstrap' => true, 'classBase' => '']
]);
Plugin::routes();
$expected = [
'Company', 'ParentPlugin', 'PluginJs', 'TestPlugin',
'TestPluginFour', 'TestPluginTwo', 'TestTheme'
];
$this->assertEquals($expected, Plugin::loaded());
$this->assertEquals('loaded js plugin bootstrap', Configure::read('PluginTest.js_plugin.bootstrap'));
$this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes'));
$this->assertNull(Configure::read('PluginTest.test_plugin.bootstrap'));
$this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
$this->assertEquals('loaded plugin four bootstrap', Configure::read('PluginTest.test_plugin_four.bootstrap'));
// TestPluginThree won't get loaded by loadAll() since it's in a sub directory.
$this->assertNull(Configure::read('PluginTest.test_plugin_three.bootstrap'));
});
}
}

0 comments on commit d339699

Please sign in to comment.
You can’t perform that action at this time.