Fixing Configure::listObjects() to not return incorrect core classes, closes #3954. Adding route testing support to cake console.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6404 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-01-23 04:14:58 +00:00
parent 38c705a06b
commit 074cfeb75d
4 changed files with 51 additions and 14 deletions

View file

@ -58,7 +58,11 @@ class ConsoleShell extends Shell {
* @access public * @access public
*/ */
function initialize() { 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) { foreach ($this->models as $model) {
$class = Inflector::camelize(r('.php', '', $model)); $class = Inflector::camelize(r('.php', '', $model));
$this->models[$model] = $class; $this->models[$model] = $class;
@ -71,22 +75,33 @@ class ConsoleShell extends Shell {
$this->out(" - {$model}"); $this->out(" - {$model}");
} }
} }
/**
* Prints the help message
*
* @access public
*/
function help() {
$this->main('help');
}
/** /**
* Override main() to handle action * Override main() to handle action
* *
* @access public * @access public
*/ */
function main() { function main($command = null) {
while (true) { while (true) {
$command = trim($this->in('')); if (empty($command)) {
$command = trim($this->in(''));
}
switch($command) { switch($command) {
case 'help': case 'help':
$this->out('Console help:'); $this->out('Console help:');
$this->out('-------------'); $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('');
$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('e.g. Foo->findAll()');
$this->out(''); $this->out('');
$this->out('To dynamically set associations, you can do the following:'); $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("To get column information for a model, use the following:");
$this->out("\tModelA columns"); $this->out("\tModelA columns");
$this->out("which returns a list of columns and their type"); $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 <url>");
$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; break;
case 'quit': case 'quit':
case 'exit': case 'exit':
@ -249,10 +274,21 @@ class ConsoleShell extends Shell {
$this->out("Please verify that you selected a valid model"); $this->out("Please verify that you selected a valid model");
} }
break; 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: default:
$this->out("Invalid command\n"); $this->out("Invalid command\n");
break; break;
} }
$command = '';
} }
} }
/** /**

View file

@ -154,7 +154,7 @@ class Configure extends Object {
if (empty($_this->__objects) || !isset($_this->__objects[$type]) || $cache !== true) { if (empty($_this->__objects) || !isset($_this->__objects[$type]) || $cache !== true) {
$Inflector =& Inflector::getInstance(); $Inflector =& Inflector::getInstance();
$types = array( $types = array(
'model' => array('suffix' => '.php', 'base' => 'AppModel'), 'model' => array('suffix' => '.php', 'base' => 'AppModel', 'core' => false),
'behavior' => array('suffix' => '.php', 'base' => 'ModelBehavior'), 'behavior' => array('suffix' => '.php', 'base' => 'ModelBehavior'),
'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'), 'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'),
'component' => array('suffix' => '.php', 'base' => null), 'component' => array('suffix' => '.php', 'base' => null),
@ -172,8 +172,10 @@ class Configure extends Object {
$objects = array(); $objects = array();
if (empty($path)) { if (empty($path)) {
$pathVar = $type . 'Paths'; $path = $_this->{$type . 'Paths'};
$path = $_this->{$pathVar}; if (isset($types[$type]['core']) && $types[$type]['core'] === false) {
array_pop($path);
}
} }
$items = array(); $items = array();

View file

@ -195,8 +195,7 @@ class CakeSchema extends Object {
} }
if (!is_array($models) && $models !== false) { if (!is_array($models) && $models !== false) {
$appPaths = array_diff(Configure::read('modelPaths'), Configure::corePaths('model')); $models = Configure::listObjects('model');
$models = Configure::listObjects('model', $appPaths, false);
} }
if (is_array($models)) { if (is_array($models)) {

View file

@ -45,9 +45,6 @@ class ConfigureTest extends UnitTestCase {
$this->assertTrue(in_array('Cache', $result)); $this->assertTrue(in_array('Cache', $result));
$this->assertTrue(in_array('HttpSocket', $result)); $this->assertTrue(in_array('HttpSocket', $result));
$result = $this->Configure->listObjects('model');
$this->assertTrue(in_array('Model', $result));
$result = $this->Configure->listObjects('behavior'); $result = $this->Configure->listObjects('behavior');
$this->assertTrue(in_array('Tree', $result)); $this->assertTrue(in_array('Tree', $result));
@ -81,12 +78,15 @@ class ConfigureTest extends UnitTestCase {
$notExpected = array('AppModel', 'Behavior', 'ConnectionManager', 'DbAcl', 'Model', 'Schema'); $notExpected = array('AppModel', 'Behavior', 'ConnectionManager', 'DbAcl', 'Model', 'Schema');
foreach ($notExpected as $class) { foreach ($notExpected as $class) {
//$this->assertFalse(in_array($class, $result)); $this->assertFalse(in_array($class, $result));
} }
} }
function tearDown() { function tearDown() {
unset($this->Configure); 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');
}
} }
} }