mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 19:38:26 +00:00
20c0a87876
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5162 3807eeeb-6ff5-0310-8944-8be069107fe0
128 lines
No EOL
3.4 KiB
PHP
128 lines
No EOL
3.4 KiB
PHP
<?php
|
|
/* SVN FILE: $Id$ */
|
|
/**
|
|
* 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
|
|
*
|
|
* 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
|
|
* @subpackage cake.cake.console.libs
|
|
* @since CakePHP(tm) v 1.2.0.5012
|
|
* @version $Revision$
|
|
* @modifiedby $LastChangedBy$
|
|
* @lastmodified $Date$
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
*/
|
|
/**
|
|
* @package cake
|
|
* @subpackage cake.cake.console.libs
|
|
*/
|
|
class ConsoleShell extends Shell {
|
|
var $associations = array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany');
|
|
|
|
function main() {
|
|
$models = @loadModels();
|
|
foreach ($models as $model) {
|
|
$class = Inflector::camelize(r('.php', '', $model));
|
|
$models[$model] = $class;
|
|
@${$class} =& new $class();
|
|
}
|
|
|
|
while (true) {
|
|
$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('');
|
|
$this->out('To test for results, use the name of your model without a leading $');
|
|
$this->out('e.g. Foo->findAll()');
|
|
break;
|
|
case 'quit':
|
|
case 'exit':
|
|
return true;
|
|
break;
|
|
case 'models':
|
|
$this->out('Model classes:');
|
|
$this->out('--------------');
|
|
|
|
foreach ($models as $model) {
|
|
$this->out(" - {$model}");
|
|
}
|
|
break;
|
|
default:
|
|
// Look to see if we're dynamically binding something
|
|
$dynamicAssociation = false;
|
|
|
|
foreach ($this->associations as $association) {
|
|
if (preg_match("/^(\w+) $association (\w+)/", $command, $models) == TRUE) {
|
|
$modelA = $models[1];
|
|
$modelB = $models[2];
|
|
loadModel($modelA);
|
|
$M = new $modelA();
|
|
$dynamicAssociation = true;
|
|
$M->bindModel(
|
|
array("$association" => array(
|
|
"$modelB" => array(
|
|
'className' => $modelB))));
|
|
print "Added association $command\n";
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($dynamicAssociation == false) {
|
|
// let's look for a find statment
|
|
if (strpos($command, "->find") > 0) {
|
|
$command = '$modelResults = $' . $command . ";";
|
|
eval($command);
|
|
|
|
foreach ($modelResults as $results) {
|
|
foreach ($results as $modelName => $result) {
|
|
$this->out("$modelName");
|
|
foreach ($result as $field => $value) {
|
|
$this->out("\t$field: $value");
|
|
}
|
|
}
|
|
|
|
$this->out('----------');
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
?>
|