mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Making plugin routes load after app routes, closes #1722
This commit is contained in:
parent
95a5b99b0e
commit
5b8865a3a7
5 changed files with 22 additions and 10 deletions
|
@ -53,10 +53,10 @@ class ConsoleShell extends Shell {
|
||||||
public function initialize() {
|
public function initialize() {
|
||||||
App::uses('Dispatcher', 'Routing');
|
App::uses('Dispatcher', 'Routing');
|
||||||
$this->Dispatcher = new Dispatcher();
|
$this->Dispatcher = new Dispatcher();
|
||||||
$this->models = App::objects('model');
|
$this->models = App::objects('Model');
|
||||||
|
|
||||||
foreach ($this->models as $model) {
|
foreach ($this->models as $model) {
|
||||||
$class = Inflector::camelize(str_replace('.php', '', $model));
|
$class = $model;
|
||||||
$this->models[$model] = $class;
|
$this->models[$model] = $class;
|
||||||
App::uses($class, 'Model');
|
App::uses($class, 'Model');
|
||||||
$this->{$class} = new $class();
|
$this->{$class} = new $class();
|
||||||
|
@ -123,7 +123,7 @@ class ConsoleShell extends Shell {
|
||||||
$out .= "\t)";
|
$out .= "\t)";
|
||||||
$out .= "\n";
|
$out .= "\n";
|
||||||
$out .= 'Alternatively, you can use simple array syntax to test reverse';
|
$out .= 'Alternatively, you can use simple array syntax to test reverse';
|
||||||
$out .= 'To reload your routes config (config/routes.php), do the following:';
|
$out .= 'To reload your routes config (Config/routes.php), do the following:';
|
||||||
$out .= "\n";
|
$out .= "\n";
|
||||||
$out .= "\tRoutes reload";
|
$out .= "\tRoutes reload";
|
||||||
$out .= "\n";
|
$out .= "\n";
|
||||||
|
@ -342,6 +342,8 @@ class ConsoleShell extends Shell {
|
||||||
if (!@include(APP . 'Config' . DS . 'routes.php')) {
|
if (!@include(APP . 'Config' . DS . 'routes.php')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
CakePlugin::routes();
|
||||||
|
|
||||||
Router::parse('/');
|
Router::parse('/');
|
||||||
|
|
||||||
foreach (array_keys(Router::getNamedExpressions()) as $var) {
|
foreach (array_keys(Router::getNamedExpressions()) as $var) {
|
||||||
|
|
|
@ -74,9 +74,6 @@ class CakePlugin {
|
||||||
if (!empty(self::$_plugins[$plugin]['bootstrap'])) {
|
if (!empty(self::$_plugins[$plugin]['bootstrap'])) {
|
||||||
self::bootstrap($plugin);
|
self::bootstrap($plugin);
|
||||||
}
|
}
|
||||||
if (!empty(self::$_plugins[$plugin]['routes'])) {
|
|
||||||
self::routes($plugin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,12 +146,19 @@ class CakePlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the routes file for a plugin
|
* Loads the routes file for a plugin, or all plugins configured to load their respective routes file
|
||||||
*
|
*
|
||||||
* @param string $plugin name of the plugin
|
* @param string $plugin name of the plugin, if null will operate on all plugins having enabled the
|
||||||
|
* loading of routes files
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function routes($plugin) {
|
public static function routes($plugin = null) {
|
||||||
|
if ($plugin === null) {
|
||||||
|
foreach (self::loaded() as $p) {
|
||||||
|
self::routes($p);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
$config = self::$_plugins[$plugin];
|
$config = self::$_plugins[$plugin];
|
||||||
if ($config['routes'] === false) {
|
if ($config['routes'] === false) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -237,6 +237,7 @@ class Dispatcher {
|
||||||
*/
|
*/
|
||||||
protected function _loadRoutes() {
|
protected function _loadRoutes() {
|
||||||
include APP . 'Config' . DS . 'routes.php';
|
include APP . 'Config' . DS . 'routes.php';
|
||||||
|
CakePlugin::routes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -183,7 +183,7 @@ class Router {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the named route elements for use in app/config/routes.php
|
* Gets the named route elements for use in app/Config/routes.php
|
||||||
*
|
*
|
||||||
* @return array Named route elements
|
* @return array Named route elements
|
||||||
* @see Router::$__namedExpressions
|
* @see Router::$__namedExpressions
|
||||||
|
|
|
@ -85,6 +85,8 @@ class CakePluginTest extends CakeTestCase {
|
||||||
CakePlugin::load('TestPlugin', array('bootstrap' => true, 'routes' => true));
|
CakePlugin::load('TestPlugin', array('bootstrap' => true, 'routes' => true));
|
||||||
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
|
||||||
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
|
||||||
|
|
||||||
|
CakePlugin::routes();
|
||||||
$this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
|
$this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +161,7 @@ class CakePluginTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testLoadMultipleWithDefaultsMissingFile() {
|
public function testLoadMultipleWithDefaultsMissingFile() {
|
||||||
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'), array('bootstrap' => true, 'routes' => true));
|
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'), array('bootstrap' => true, 'routes' => true));
|
||||||
|
CakePlugin::routes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,6 +232,8 @@ class CakePluginTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testLoadAllWithDefaultsAndOverride() {
|
public function testLoadAllWithDefaultsAndOverride() {
|
||||||
CakePlugin::loadAll(array('bootstrap' => true, 'TestPlugin' => array('routes' => true)));
|
CakePlugin::loadAll(array('bootstrap' => true, 'TestPlugin' => array('routes' => true)));
|
||||||
|
CakePlugin::routes();
|
||||||
|
|
||||||
$expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo');
|
$expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo');
|
||||||
$this->assertEquals($expected, CakePlugin::loaded());
|
$this->assertEquals($expected, CakePlugin::loaded());
|
||||||
$this->assertEquals('loaded js plugin bootstrap', Configure::read('CakePluginTest.js_plugin.bootstrap'));
|
$this->assertEquals('loaded js plugin bootstrap', Configure::read('CakePluginTest.js_plugin.bootstrap'));
|
||||||
|
|
Loading…
Reference in a new issue