diff --git a/cake/console/libs/console.php b/cake/console/libs/console.php index 7f755f7dc..3cd668178 100644 --- a/cake/console/libs/console.php +++ b/cake/console/libs/console.php @@ -58,7 +58,11 @@ class ConsoleShell extends Shell { * @access public */ function initialize() { - $this->models = @loadModels(); + require_once CAKE . 'dispatcher.php'; + $this->Dispatcher = new Dispatcher(); + $this->models = Configure::listObjects('model'); + App::import('Model', $this->models); + foreach ($this->models as $model) { $class = Inflector::camelize(r('.php', '', $model)); $this->models[$model] = $class; @@ -71,22 +75,33 @@ class ConsoleShell extends Shell { $this->out(" - {$model}"); } } +/** + * Prints the help message + * + * @access public + */ + function help() { + $this->main('help'); + } /** * Override main() to handle action * * @access public */ - function main() { + function main($command = null) { while (true) { - $command = trim($this->in('')); + if (empty($command)) { + $command = trim($this->in('')); + } switch($command) { case 'help': $this->out('Console help:'); $this->out('-------------'); - $this->out('The interactive console is a tool for testing models before you commit code'); + $this->out('The interactive console is a tool for testing parts of your app before you commit code'); $this->out(''); - $this->out('To test for results, use the name of your model without a leading $'); + $this->out('Model testing:'); + $this->out('To test model results, use the name of your model without a leading $'); $this->out('e.g. Foo->findAll()'); $this->out(''); $this->out('To dynamically set associations, you can do the following:'); @@ -105,6 +120,16 @@ class ConsoleShell extends Shell { $this->out("To get column information for a model, use the following:"); $this->out("\tModelA columns"); $this->out("which returns a list of columns and their type"); + $this->out(''); + $this->out('Route testing:'); + $this->out('To test URLs against your app\'s route configuration, type:'); + $this->out("\tRoute "); + $this->out("where url is the path to your your action plus any query parameters, minus the"); + $this->out("application's base path"); + $this->out(''); + $this->out('To reload your routes config (config/routes.php), do the following:'); + $this->out("\tRoute reload"); + $this->out(''); break; case 'quit': case 'exit': @@ -249,10 +274,21 @@ class ConsoleShell extends Shell { $this->out("Please verify that you selected a valid model"); } break; + case (preg_match("/^routes\s+reload/i", $command, $tmp) == true): + $router =& Router::getInstance(); + $router->reload(); + if (config('routes') && $router->parse('/')) { + $this->out("Routes configuration reloaded, " . count($router->routes) . " routes connected"); + } + break; + case (preg_match("/^route\s+(.*)/i", $command, $tmp) == true): + $this->out(Debugger::exportVar(Router::parse($tmp[1]))); + break; default: $this->out("Invalid command\n"); break; } + $command = ''; } } /** diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 121fb482d..be1488e4d 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -154,7 +154,7 @@ class Configure extends Object { if (empty($_this->__objects) || !isset($_this->__objects[$type]) || $cache !== true) { $Inflector =& Inflector::getInstance(); $types = array( - 'model' => array('suffix' => '.php', 'base' => 'AppModel'), + 'model' => array('suffix' => '.php', 'base' => 'AppModel', 'core' => false), 'behavior' => array('suffix' => '.php', 'base' => 'ModelBehavior'), 'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'), 'component' => array('suffix' => '.php', 'base' => null), @@ -172,8 +172,10 @@ class Configure extends Object { $objects = array(); if (empty($path)) { - $pathVar = $type . 'Paths'; - $path = $_this->{$pathVar}; + $path = $_this->{$type . 'Paths'}; + if (isset($types[$type]['core']) && $types[$type]['core'] === false) { + array_pop($path); + } } $items = array(); diff --git a/cake/libs/model/schema.php b/cake/libs/model/schema.php index 388abdd46..fabdd61db 100644 --- a/cake/libs/model/schema.php +++ b/cake/libs/model/schema.php @@ -195,8 +195,7 @@ class CakeSchema extends Object { } if (!is_array($models) && $models !== false) { - $appPaths = array_diff(Configure::read('modelPaths'), Configure::corePaths('model')); - $models = Configure::listObjects('model', $appPaths, false); + $models = Configure::listObjects('model'); } if (is_array($models)) { diff --git a/cake/tests/cases/libs/configure.test.php b/cake/tests/cases/libs/configure.test.php index ab6736b19..e2010322f 100644 --- a/cake/tests/cases/libs/configure.test.php +++ b/cake/tests/cases/libs/configure.test.php @@ -45,9 +45,6 @@ class ConfigureTest extends UnitTestCase { $this->assertTrue(in_array('Cache', $result)); $this->assertTrue(in_array('HttpSocket', $result)); - $result = $this->Configure->listObjects('model'); - $this->assertTrue(in_array('Model', $result)); - $result = $this->Configure->listObjects('behavior'); $this->assertTrue(in_array('Tree', $result)); @@ -81,12 +78,15 @@ class ConfigureTest extends UnitTestCase { $notExpected = array('AppModel', 'Behavior', 'ConnectionManager', 'DbAcl', 'Model', 'Schema'); foreach ($notExpected as $class) { - //$this->assertFalse(in_array($class, $result)); + $this->assertFalse(in_array($class, $result)); } } function tearDown() { unset($this->Configure); + if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_core_paths')) { + unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_core_paths'); + } } }