2007-03-09 23:15:03 +00:00
|
|
|
<?php
|
2007-03-27 05:10:42 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2007-03-09 23:15:03 +00:00
|
|
|
/**
|
2007-03-27 05:10:42 +00:00
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2007-03-09 23:15:03 +00:00
|
|
|
*
|
2007-03-27 05:10:42 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
|
|
|
* @package cake
|
2007-05-14 01:14:41 +00:00
|
|
|
* @subpackage cake.cake.console.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5012
|
2007-03-27 05:10:42 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @package cake
|
2007-05-14 01:14:41 +00:00
|
|
|
* @subpackage cake.cake.console.libs
|
2007-03-09 23:15:03 +00:00
|
|
|
*/
|
2007-05-12 21:18:07 +00:00
|
|
|
class ConsoleShell extends Shell {
|
2007-05-24 03:03:15 +00:00
|
|
|
var $associations = array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany');
|
|
|
|
|
2007-05-24 15:26:50 +00:00
|
|
|
function initialize() {
|
|
|
|
$this->models = @loadModels();
|
|
|
|
foreach ($this->models as $model) {
|
2007-03-27 05:10:42 +00:00
|
|
|
$class = Inflector::camelize(r('.php', '', $model));
|
2007-05-24 15:26:50 +00:00
|
|
|
$this->models[$model] = $class;
|
|
|
|
$this->{$class} =& new $class();
|
2007-03-27 05:10:42 +00:00
|
|
|
}
|
2007-05-24 15:26:50 +00:00
|
|
|
$this->out('Model classes:');
|
|
|
|
$this->out('--------------');
|
|
|
|
|
|
|
|
foreach ($this->models as $model) {
|
|
|
|
$this->out(" - {$model}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
2007-03-09 23:15:03 +00:00
|
|
|
|
2007-03-27 05:10:42 +00:00
|
|
|
while (true) {
|
|
|
|
$command = trim($this->in(''));
|
2007-03-23 02:00:10 +00:00
|
|
|
|
2007-03-27 05:10:42 +00:00
|
|
|
switch($command) {
|
2007-05-24 03:03:15 +00:00
|
|
|
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('');
|
|
|
|
$this->out('To test for results, use the name of your model without a leading $');
|
|
|
|
$this->out('e.g. Foo->findAll()');
|
|
|
|
break;
|
2007-03-27 05:10:42 +00:00
|
|
|
case 'quit':
|
|
|
|
case 'exit':
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
case 'models':
|
|
|
|
$this->out('Model classes:');
|
|
|
|
$this->out('--------------');
|
2007-05-24 15:26:50 +00:00
|
|
|
foreach ($this->models as $model) {
|
2007-03-27 05:10:42 +00:00
|
|
|
$this->out(" - {$model}");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2007-05-24 03:03:15 +00:00
|
|
|
// Look to see if we're dynamically binding something
|
|
|
|
$dynamicAssociation = false;
|
|
|
|
|
|
|
|
foreach ($this->associations as $association) {
|
2007-05-24 15:26:50 +00:00
|
|
|
if (preg_match("/^(\w+) $association (\w+)/", $command, $this->models) == TRUE) {
|
|
|
|
$modelA = $this->models[1];
|
|
|
|
$modelB = $this->models[2];
|
2007-05-24 03:03:15 +00:00
|
|
|
loadModel($modelA);
|
|
|
|
$M = new $modelA();
|
|
|
|
$dynamicAssociation = true;
|
|
|
|
$M->bindModel(
|
|
|
|
array("$association" => array(
|
|
|
|
"$modelB" => array(
|
|
|
|
'className' => $modelB))));
|
|
|
|
print "Added association $command\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-03-09 23:15:03 +00:00
|
|
|
|
2007-05-24 03:03:15 +00:00
|
|
|
if ($dynamicAssociation == false) {
|
|
|
|
// let's look for a find statment
|
|
|
|
if (strpos($command, "->find") > 0) {
|
2007-05-24 15:26:50 +00:00
|
|
|
$command = '$data = $this->' . $command . ";";
|
2007-05-24 03:03:15 +00:00
|
|
|
eval($command);
|
|
|
|
|
2007-05-24 15:26:50 +00:00
|
|
|
foreach ($data as $results) {
|
2007-05-24 03:03:15 +00:00
|
|
|
foreach ($results as $modelName => $result) {
|
|
|
|
$this->out("$modelName");
|
|
|
|
foreach ($result as $field => $value) {
|
|
|
|
$this->out("\t$field: $value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->out('----------');
|
|
|
|
}
|
2007-03-27 05:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-24 03:03:15 +00:00
|
|
|
break;
|
2007-03-27 05:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-09 23:15:03 +00:00
|
|
|
}
|
2007-03-27 05:10:42 +00:00
|
|
|
function fatal_error_handler($buffer) {
|
|
|
|
if(ereg("(error</b>:)(.+)(<br)", $buffer, $regs) ) {
|
|
|
|
$err = preg_replace("/<.*?>/", "", $regs[2]);
|
|
|
|
error_log($err);
|
|
|
|
return "ERROR CAUGHT check log file";
|
|
|
|
}
|
|
|
|
return $buffer;
|
|
|
|
}
|
2007-03-09 23:15:03 +00:00
|
|
|
|
2007-03-27 05:10:42 +00:00
|
|
|
function handle_error ($errno, $errstr, $errfile, $errline) {
|
|
|
|
error_log("$errstr in $errfile on line $errline");
|
|
|
|
if($errno == FATAL || $errno == ERROR){
|
|
|
|
ob_end_flush();
|
|
|
|
echo "ERROR CAUGHT check log file";
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|