Permalink
Browse files

Making plugin routes load after app routes, closes #1722

  • Loading branch information...
1 parent 95a5b99 commit 5b8865a3a71bb29df38fcad61b32322705556e00 @lorenzo lorenzo committed May 23, 2011
@@ -53,10 +53,10 @@ class ConsoleShell extends Shell {
public function initialize() {
App::uses('Dispatcher', 'Routing');
$this->Dispatcher = new Dispatcher();
- $this->models = App::objects('model');
+ $this->models = App::objects('Model');
foreach ($this->models as $model) {
- $class = Inflector::camelize(str_replace('.php', '', $model));
+ $class = $model;
$this->models[$model] = $class;
App::uses($class, 'Model');
$this->{$class} = new $class();
@@ -123,7 +123,7 @@ public function help() {
$out .= "\t)";
$out .= "\n";
$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 .= "\tRoutes reload";
$out .= "\n";
@@ -342,6 +342,8 @@ protected function _loadRoutes() {
if (!@include(APP . 'Config' . DS . 'routes.php')) {
return false;
}
+ CakePlugin::routes();
+
Router::parse('/');
foreach (array_keys(Router::getNamedExpressions()) as $var) {
@@ -74,9 +74,6 @@ public static function load($plugin, $config = array()) {
if (!empty(self::$_plugins[$plugin]['bootstrap'])) {
self::bootstrap($plugin);
}
- if (!empty(self::$_plugins[$plugin]['routes'])) {
- self::routes($plugin);
- }
}
/**
@@ -149,12 +146,19 @@ public static function bootstrap($plugin) {
}
/**
- * 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
*/
- 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];
if ($config['routes'] === false) {
return false;
@@ -237,6 +237,7 @@ protected function _loadController($request) {
*/
protected function _loadRoutes() {
include APP . 'Config' . DS . 'routes.php';
+ CakePlugin::routes();
}
/**
@@ -183,7 +183,7 @@ protected static function _setPrefixes() {
}
/**
- * 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
* @see Router::$__namedExpressions
@@ -85,6 +85,8 @@ public function testLoadSingleWithBootstrapAndRoutes() {
CakePlugin::load('TestPlugin', array('bootstrap' => true, 'routes' => true));
$this->assertTrue(CakePlugin::loaded('TestPlugin'));
$this->assertEquals('loaded plugin bootstrap', Configure::read('CakePluginTest.test_plugin.bootstrap'));
+
+ CakePlugin::routes();
$this->assertEquals('loaded plugin routes', Configure::read('CakePluginTest.test_plugin.routes'));
}
@@ -159,6 +161,7 @@ public function testCallbackBootstrap() {
*/
public function testLoadMultipleWithDefaultsMissingFile() {
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'), array('bootstrap' => true, 'routes' => true));
+ CakePlugin::routes();
}
/**
@@ -229,6 +232,8 @@ public function testLoadAllWithDefaults() {
*/
public function testLoadAllWithDefaultsAndOverride() {
CakePlugin::loadAll(array('bootstrap' => true, 'TestPlugin' => array('routes' => true)));
+ CakePlugin::routes();
+
$expected = array('PluginJs', 'TestPlugin', 'TestPluginTwo');
$this->assertEquals($expected, CakePlugin::loaded());
$this->assertEquals('loaded js plugin bootstrap', Configure::read('CakePluginTest.js_plugin.bootstrap'));

0 comments on commit 5b8865a

Please sign in to comment.