Permalink
Browse files

Merge branch '1.3' into 1.3-console

  • Loading branch information...
2 parents 99fc645 + 7847044 commit f658f17b7e40550d8a606ac29a39fcce049b0cfa @markstory markstory committed Aug 1, 2009
Showing with 1,403 additions and 357 deletions.
  1. +5 −0 app/config/core.php
  2. +8 −1 app/webroot/test.php
  3. +5 −0 cake/bootstrap.php
  4. +131 −112 cake/console/cake.php
  5. +1 −1 cake/console/libs/bake.php
  6. +2 −2 cake/console/libs/schema.php
  7. +48 −39 cake/console/libs/shell.php
  8. +2 −2 cake/console/libs/tasks/fixture.php
  9. +1 −2 cake/console/libs/tasks/model.php
  10. +3 −3 cake/console/libs/tasks/project.php
  11. +1 −1 cake/console/libs/tasks/view.php
  12. +3 −3 cake/console/libs/templates/default/views/form.ctp
  13. +1 −1 cake/console/libs/templates/default/views/home.ctp
  14. +2 −2 cake/console/libs/templates/default/views/index.ctp
  15. +9 −9 cake/console/libs/templates/default/views/view.ctp
  16. +1 −1 cake/console/libs/templates/skel/app_helper.php
  17. +5 −0 cake/console/libs/templates/skel/config/core.php
  18. +8 −1 cake/console/libs/templates/skel/webroot/test.php
  19. +1 −1 cake/dispatcher.php
  20. +8 −8 cake/libs/configure.php
  21. +7 −7 cake/libs/controller/components/cookie.php
  22. +1 −1 cake/libs/debugger.php
  23. +3 −3 cake/libs/http_socket.php
  24. +2 −1 cake/libs/inflector.php
  25. +2 −2 cake/libs/model/cake_schema.php
  26. +17 −19 cake/libs/model/datasources/dbo/dbo_mysqli.php
  27. +9 −10 cake/libs/router.php
  28. +3 −3 cake/libs/view/errors/missing_action.ctp
  29. +3 −3 cake/libs/view/errors/missing_component_class.ctp
  30. +2 −2 cake/libs/view/errors/missing_component_file.ctp
  31. +3 −3 cake/libs/view/errors/missing_controller.ctp
  32. +2 −2 cake/libs/view/errors/missing_helper_class.ctp
  33. +4 −5 cake/libs/view/errors/missing_helper_file.ctp
  34. +3 −3 cake/libs/view/errors/missing_layout.ctp
  35. +2 −2 cake/libs/view/errors/missing_model.ctp
  36. +2 −2 cake/libs/view/errors/missing_scaffolddb.ctp
  37. +2 −2 cake/libs/view/errors/missing_table.ctp
  38. +2 −2 cake/libs/view/errors/missing_view.ctp
  39. +2 −2 cake/libs/view/errors/private_action.ctp
  40. +1 −1 cake/libs/view/errors/scaffold_error.ctp
  41. +12 −18 cake/libs/view/helpers/paginator.php
  42. +2 −2 cake/libs/view/scaffolds/edit.ctp
  43. +2 −2 cake/libs/view/scaffolds/index.ctp
  44. +8 −8 cake/libs/view/scaffolds/view.ctp
  45. +460 −10 cake/tests/cases/console/cake.test.php
  46. +105 −14 cake/tests/cases/console/libs/shell.test.php
  47. +2 −2 cake/tests/cases/libs/http_socket.test.php
  48. +12 −0 cake/tests/cases/libs/inflector.test.php
  49. +69 −0 cake/tests/cases/libs/router.test.php
  50. +2 −2 cake/tests/cases/libs/sanitize.test.php
  51. +20 −0 cake/tests/cases/libs/view/helpers/cache.test.php
  52. +392 −34 cake/tests/cases/libs/view/helpers/paginator.test.php
  53. +0 −1 cake/tests/lib/cake_reporter.php
View
@@ -185,6 +185,11 @@
Configure::write('Acl.classname', 'DbAcl');
Configure::write('Acl.database', 'default');
/**
+ * If you are on PHP 5.3 uncomment this line and correct your server timezone
+ * to fix the date & time related errors.
+ */
+ //date_default_timezone_set('UTC');
+/**
*
* Cache Engine Configuration
* Default settings provided below
View
@@ -24,7 +24,14 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
-error_reporting(E_ALL);
+/**
+ * PHP 5.3 raises many notices in bootstrap.
+ */
+if (!defined('E_DEPRECATED')) {
+ define('E_DEPRECATED', 8192);
+}
+error_reporting(E_ALL & ~E_DEPRECATED);
+
set_time_limit(0);
ini_set('memory_limit','128M');
ini_set('display_errors', 1);
View
@@ -22,6 +22,11 @@
if (!defined('PHP5')) {
define('PHP5', (PHP_VERSION >= 5));
}
+if (!defined('E_DEPRECATED')) {
+ define('E_DEPRECATED', 8192);
+}
+error_reporting(E_ALL & ~E_DEPRECATED);
+
require CORE_PATH . 'cake' . DS . 'basics.php';
$TIME_START = getMicrotime();
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
View
@@ -135,15 +135,21 @@ function ShellDispatcher($args = array()) {
/**
* Constructor
*
- * @param array $args the argv.
+ * The execution of the script is stopped after dispatching the request with
+ * a status code of either 0 or 1 according to the result of the dispatch.
+ *
+ * @param array $args the argv
+ * @return void
+ * @access public
*/
function __construct($args = array()) {
set_time_limit(0);
+
$this->__initConstants();
$this->parseParams($args);
$this->_initEnvironment();
$this->__buildPaths();
- $this->_stop($this->dispatch());
+ $this->_stop($this->dispatch() === false ? 1 : 0);
}
/**
@@ -305,118 +311,134 @@ function clear() {
/**
* Dispatches a CLI request
*
+ * @return boolean
* @access public
*/
function dispatch() {
- if (isset($this->args[0])) {
+ $arg = $this->shiftArgs();
+
+ if (!$arg) {
+ $this->help();
+ return false;
+ }
+ if ($arg == 'help') {
+ $this->help();
+ return true;
+ }
+
+ if (strpos($arg, '.') !== false) {
+ list($plugin, $shell) = explode('.', $arg);
+ } else {
$plugin = null;
- $shell = $this->args[0];
- if (strpos($shell, '.') !== false) {
- list($plugin, $shell) = explode('.', $this->args[0]);
- }
+ $shell = $arg;
+ }
+ $this->shell = $shell;
+ $this->shellName = Inflector::camelize($shell);
+ $this->shellClass = $this->shellName . 'Shell';
- $this->shell = $shell;
- $this->shiftArgs();
- $this->shellName = Inflector::camelize($this->shell);
- $this->shellClass = $this->shellName . 'Shell';
+ $arg = null;
- if ($this->shell === 'help') {
- $this->help();
- } else {
- $loaded = false;
- foreach ($this->shellPaths as $path) {
- $this->shellPath = $path . $this->shell . '.php';
-
- $isPlugin = ($plugin && strpos($path, DS . $plugin . DS . 'vendors' . DS . 'shells' . DS) !== false);
- if (($isPlugin && file_exists($this->shellPath)) || (!$plugin && file_exists($this->shellPath))) {
- $loaded = true;
- break;
- }
- }
+ if (isset($this->args[0])) {
+ $arg = $this->args[0];
+ $this->shellCommand = Inflector::variable($arg);
+ }
- if ($loaded) {
- if (!class_exists('Shell')) {
- require CONSOLE_LIBS . 'shell.php';
- }
- require $this->shellPath;
- if (class_exists($this->shellClass)) {
- $command = null;
- if (isset($this->args[0])) {
- $command = $this->args[0];
- }
- $this->shellCommand = Inflector::variable($command);
- $shell = new $this->shellClass($this);
-
- if (strtolower(get_parent_class($shell)) == 'shell') {
- $shell->initialize();
- $shell->loadTasks();
-
- foreach ($shell->taskNames as $task) {
- if (strtolower(get_parent_class($shell)) == 'shell') {
- $shell->{$task}->initialize();
- $shell->{$task}->loadTasks();
- }
- }
-
- $task = Inflector::camelize($command);
- if (in_array($task, $shell->taskNames)) {
- $this->shiftArgs();
- $shell->{$task}->startup();
- if (isset($this->args[0]) && $this->args[0] == 'help') {
- if (method_exists($shell->{$task}, 'help')) {
- $shell->{$task}->help();
- $this->_stop();
- } else {
- $this->help();
- }
- }
- return $shell->{$task}->execute();
- }
- }
+ $Shell = $this->_getShell($plugin);
- $classMethods = get_class_methods($shell);
+ if (!$Shell) {
+ $title = sprintf(__('Error: Class %s could not be loaded.', true), $this->shellClass);
+ $this->stderr($title . "\n");
+ return false;
+ }
- $privateMethod = $missingCommand = false;
- if ((in_array($command, $classMethods) || in_array(strtolower($command), $classMethods)) && strpos($command, '_', 0) === 0) {
- $privateMethod = true;
- }
+ $methods = array();
- if (!in_array($command, $classMethods) && !in_array(strtolower($command), $classMethods)) {
- $missingCommand = true;
- }
+ if (is_a($Shell, 'Shell')) {
+ $Shell->initialize();
+ $Shell->loadTasks();
- $protectedCommands = array(
- 'initialize','in','out','err','hr',
- 'createfile', 'isdir','copydir','object','tostring',
- 'requestaction','log','cakeerror', 'shelldispatcher',
- '__initconstants','__initenvironment','__construct',
- 'dispatch','__bootstrap','getinput','stdout','stderr','parseparams','shiftargs'
- );
+ foreach ($Shell->taskNames as $task) {
+ if (is_a($Shell->{$task}, 'Shell')) {
+ $Shell->{$task}->initialize();
+ $Shell->{$task}->loadTasks();
+ }
+ }
- if (in_array(strtolower($command), $protectedCommands)) {
- $missingCommand = true;
- }
+ $task = Inflector::camelize($arg);
- if ($missingCommand && method_exists($shell, 'main')) {
- $shell->startup();
- return $shell->main();
- } elseif (!$privateMethod && method_exists($shell, $command)) {
- $this->shiftArgs();
- $shell->startup();
- return $shell->{$command}();
- } else {
- $this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'cake {$this->shell} help'.\n\n");
- }
+ if (in_array($task, $Shell->taskNames)) {
+ $this->shiftArgs();
+ $Shell->{$task}->startup();
+
+ if (isset($this->args[0]) && $this->args[0] == 'help') {
+ if (method_exists($Shell->{$task}, 'help')) {
+ $Shell->{$task}->help();
} else {
- $this->stderr('Class '.$this->shellClass.' could not be loaded');
+ $this->help();
}
- } else {
- $this->help();
+ return true;
}
+ return $Shell->{$task}->execute();
}
- } else {
- $this->help();
+ $methods = array_diff(get_class_methods('Shell'), array('help'));
+ }
+ $methods = array_diff(get_class_methods($Shell), $methods);
+ $added = in_array(strtolower($arg), array_map('strtolower', $methods));
+ $private = $arg[0] == '_' && method_exists($Shell, $arg);
+
+ if (!$private) {
+ if ($added) {
+ $this->shiftArgs();
+ $Shell->startup();
+ return $Shell->{$arg}();
+ }
+ if (method_exists($Shell, 'main')) {
+ $Shell->startup();
+ return $Shell->main();
+ }
+ }
+
+ $title = sprintf(__('Error: Unknown %1$s command %2$s.', true), $this->shellName, $arg);
+ $message = sprintf(__('For usage try `cake %s help`', true), $this->shell);
+ $this->stderr($title . "\n" . $message . "\n");
+ return false;
+ }
+/**
+ * Get shell to use, either plugin shell or application shell
+ *
+ * All paths in the shellPaths property are searched.
+ * shell, shellPath and shellClass properties are taken into account.
+ *
+ * @param string $plugin Optionally the name of a plugin
+ * @return mixed False if no shell could be found or an object on success
+ * @access protected
+ */
+ function _getShell($plugin = null) {
+ foreach ($this->shellPaths as $path) {
+ $this->shellPath = $path . $this->shell . '.php';
+ $pluginShellPath = DS . $plugin . DS . 'vendors' . DS . 'shells' . DS;
+
+ if ((strpos($path, $pluginShellPath) !== false || !$plugin) && file_exists($this->shellPath)) {
+ $loaded = true;
+ break;
+ }
+ }
+ if (!isset($loaded)) {
+ return false;
+ }
+
+ if (!class_exists('Shell')) {
+ require CONSOLE_LIBS . 'shell.php';
+ }
+
+ if (!class_exists($this->shellClass)) {
+ require $this->shellPath;
}
+ if (!class_exists($this->shellClass)) {
+ return false;
+ }
+ $Shell = new $this->shellClass($this);
+ return $Shell;
}
/**
@@ -475,7 +497,7 @@ function stdout($string, $newline = true) {
* @access public
*/
function stderr($string) {
- fwrite($this->stderr, 'Error: '. $string);
+ fwrite($this->stderr, $string);
}
/**
@@ -486,13 +508,15 @@ function stderr($string) {
*/
function parseParams($params) {
$this->__parseParams($params);
-
$defaults = array('app' => 'app', 'root' => dirname(dirname(dirname(__FILE__))), 'working' => null, 'webroot' => 'webroot');
-
$params = array_merge($defaults, array_intersect_key($this->params, $defaults));
-
- $isWin = array_filter(array_map('strpos', $params, array('\\')));
-
+ $isWin = false;
+ foreach ($defaults as $default => $value) {
+ if (strpos($params[$default], '\\') !== false) {
+ $isWin = true;
+ break;
+ }
+ }
$params = str_replace('\\', '/', $params);
if (!empty($params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0]{0} !== '.')) {
@@ -504,7 +528,7 @@ function parseParams($params) {
}
}
- if ($params['app'][0] == '/' || preg_match('/([a-zA-Z])(:)/i', $params['app'], $matches)) {
+ if ($params['app'][0] == '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) {
$params['root'] = dirname($params['app']);
} elseif (strpos($params['app'], '/')) {
$params['root'] .= '/' . dirname($params['app']);
@@ -521,7 +545,7 @@ function parseParams($params) {
}
/**
- * Helper for recursively paraing params
+ * Helper for recursively parsing params
*
* @return array params
* @access private
@@ -555,16 +579,11 @@ function __parseParams($params) {
/**
* Removes first argument and shifts other arguments up
*
- * @return boolean False if there are no arguments
+ * @return mixed Null if there are no arguments otherwise the shifted argument
* @access public
*/
function shiftArgs() {
- if (empty($this->args)) {
- return false;
- }
- unset($this->args[0]);
- $this->args = array_values($this->args);
- return true;
+ return array_shift($this->args);
}
/**
@@ -603,6 +622,7 @@ function help() {
} else {
sort($shells);
foreach ($shells as $shell) {
+
if ($shell !== 'shell.php') {
$this->stdout("\t " . str_replace('.php', '', $shell));
}
@@ -612,7 +632,6 @@ function help() {
}
$this->stdout("\nTo run a command, type 'cake shell_name [args]'");
$this->stdout("To get help on a specific command, type 'cake shell_name help'");
- $this->_stop();
}
/**
@@ -157,7 +157,7 @@ function all() {
$object = new $model();
$modelExists = true;
} else {
- App::import('Model');
+ App::import('Model', 'Model', false);
$object = new Model(array('name' => $name, 'ds' => $this->connection));
}
Oops, something went wrong.

0 comments on commit f658f17

Please sign in to comment.