Skip to content

Commit

Permalink
Making plugin routes load after app routes, closes #1722
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 23, 2011
1 parent 95a5b99 commit 5b8865a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
8 changes: 5 additions & 3 deletions lib/Cake/Console/Command/ConsoleShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 10 additions & 6 deletions lib/Cake/Core/CakePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Routing/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ protected function _loadController($request) {
*/
protected function _loadRoutes() {
include APP . 'Config' . DS . 'routes.php';
CakePlugin::routes();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/Cake/Test/Case/Core/CakePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand Down Expand Up @@ -159,6 +161,7 @@ public function testCallbackBootstrap() {
*/
public function testLoadMultipleWithDefaultsMissingFile() {
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'), array('bootstrap' => true, 'routes' => true));
CakePlugin::routes();
}

/**
Expand Down Expand Up @@ -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'));
Expand Down

0 comments on commit 5b8865a

Please sign in to comment.