mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
updating console so shells and tasks do not have to extend Shell, updated error handler params and maintained backwards compatibility closes #3538, updated Object::cakeError to add app_error, closes #3982
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6407 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
cb27bcc21a
commit
f598b58465
3 changed files with 73 additions and 122 deletions
|
@ -274,28 +274,32 @@ class ShellDispatcher {
|
|||
$this->shellCommand = Inflector::variable($command);
|
||||
$shell = new $this->shellClass($this);
|
||||
|
||||
$shell->initialize();
|
||||
$shell->loadTasks();
|
||||
if (get_parent_class($shell) == 'Shell') {
|
||||
$shell->initialize();
|
||||
$shell->loadTasks();
|
||||
|
||||
foreach ($shell->taskNames as $task) {
|
||||
$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();
|
||||
exit();
|
||||
} else {
|
||||
$this->help();
|
||||
foreach ($shell->taskNames as $task) {
|
||||
if (get_parent_class($shell->{$task}) == 'Shell') {
|
||||
$shell->{$task}->initialize();
|
||||
$shell->{$task}->loadTasks();
|
||||
}
|
||||
}
|
||||
$shell->{$task}->execute();
|
||||
return;
|
||||
|
||||
$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();
|
||||
exit();
|
||||
} else {
|
||||
$this->help();
|
||||
}
|
||||
}
|
||||
$shell->{$task}->execute();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$classMethods = get_class_methods($shell);
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
uses('sanitize');
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
|
@ -54,38 +53,51 @@ class ErrorHandler extends Object{
|
|||
parent::__construct();
|
||||
static $__previousError = null;
|
||||
|
||||
if ($__previousError != array($method, $messages)) {
|
||||
$__previousError = array($method, $messages);
|
||||
|
||||
if (!class_exists('dispatcher')) {
|
||||
require CAKE . 'dispatcher.php';
|
||||
}
|
||||
$this->__dispatch =& new Dispatcher();
|
||||
$this->__dispatch->base = $this->__dispatch->baseUrl();
|
||||
|
||||
if (!class_exists('appcontroller')) {
|
||||
App::import('Controller', 'App');
|
||||
}
|
||||
|
||||
$this->controller =& new AppController();
|
||||
$this->controller->base = $this->__dispatch->base;
|
||||
$this->controller->webroot = $this->__dispatch->webroot;
|
||||
$this->controller->params = Router::getParams();
|
||||
$this->controller->here = $this->controller->params['url']['url'];
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->cacheAction = false;
|
||||
|
||||
$this->controller->constructClasses();
|
||||
$this->__dispatch->start($this->controller);
|
||||
}
|
||||
|
||||
$allow = array('.', '/', '_', ' ', '-', '~');
|
||||
if (substr(PHP_OS,0,3) == "WIN") {
|
||||
$allow = array_merge($allow, array('\\', ':') );
|
||||
}
|
||||
$clean = new Sanitize();
|
||||
$messages = $clean->paranoid($messages, $allow);
|
||||
if (!class_exists('dispatcher')) {
|
||||
require CAKE . 'dispatcher.php';
|
||||
}
|
||||
$this->__dispatch =& new Dispatcher();
|
||||
if (!class_exists('appcontroller')) {
|
||||
App::import('Controller', 'App');
|
||||
|
||||
App::import('Core', 'Sanitize');
|
||||
$messages = Sanitize::paranoid($messages, $allow);
|
||||
|
||||
if (!isset($messages[0])) {
|
||||
$messages = array($messages);
|
||||
}
|
||||
|
||||
if ($__previousError != array($method, $messages)) {
|
||||
$__previousError = array($method, $messages);
|
||||
|
||||
$this->controller =& new AppController();
|
||||
if (!empty($this->controller->uses)) {
|
||||
$this->controller->constructClasses();
|
||||
}
|
||||
$this->controller->_initComponents();
|
||||
$this->controller->cacheAction = false;
|
||||
$this->__dispatch->start($this->controller);
|
||||
|
||||
if (method_exists($this->controller, 'apperror')) {
|
||||
return $this->controller->appError($method, $messages);
|
||||
}
|
||||
} else {
|
||||
$this->controller =& new AppController();
|
||||
$this->controller->cacheAction = false;
|
||||
if (method_exists($this->controller, 'apperror')) {
|
||||
return $this->controller->appError($method, $messages);
|
||||
}
|
||||
|
||||
if (!in_array($method, get_class_methods($this))) {
|
||||
$method = 'error';
|
||||
}
|
||||
|
||||
if (Configure::read() > 0 || $method == 'error') {
|
||||
call_user_func_array(array(&$this, $method), $messages);
|
||||
} else {
|
||||
|
@ -99,10 +111,7 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function error($params) {
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->viewPath = 'errors';
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
$this->controller->set(array('code' => $code,
|
||||
'name' => $name,
|
||||
'message' => $message,
|
||||
|
@ -117,23 +126,17 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function error404($params) {
|
||||
extract($params);
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
if (!isset($url)) {
|
||||
$url = $action;
|
||||
$url = $this->controller->here;
|
||||
}
|
||||
if (!isset($message)) {
|
||||
$message = '';
|
||||
}
|
||||
if (!isset($base)) {
|
||||
$base = '';
|
||||
}
|
||||
|
||||
$url = Router::normalize($url);
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
$this->error(array('code' => '404',
|
||||
'name' => __('Not Found', true),
|
||||
'message' => sprintf(__("The requested address %s was not found on this server.", true), "<strong>'{$url}'</strong>", $message),
|
||||
'base' => $base));
|
||||
'message' => sprintf(__("The requested address %s was not found on this server.", true), "<strong>'{$url}'</strong>"),
|
||||
'base' => $this->controller->base));
|
||||
exit();
|
||||
}
|
||||
/**
|
||||
|
@ -143,12 +146,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingController($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->webroot = $webroot;
|
||||
$this->controller->viewPath ='errors';
|
||||
$controllerName = str_replace('Controller', '', $className);
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'controllerName' => $controllerName,
|
||||
|
@ -163,12 +162,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingAction($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->webroot = $webroot;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$controllerName = str_replace('Controller', '', $className);
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'controllerName' => $controllerName,
|
||||
|
@ -184,12 +179,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function privateAction($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->webroot = $webroot;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'action' => $action,
|
||||
'title' => __('Trying to access private method in class', true)));
|
||||
|
@ -203,11 +194,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingTable($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('model' => $className,
|
||||
'table' => $table,
|
||||
'title' => __('Missing Database Table', true)));
|
||||
|
@ -221,11 +209,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingDatabase($params = array()) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('title' => __('Scaffold Missing Database Connection', true)));
|
||||
$this->controller->render('missingScaffolddb');
|
||||
exit();
|
||||
|
@ -237,12 +222,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingView($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'action' => $action,
|
||||
'file' => $file,
|
||||
|
@ -257,12 +238,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingLayout($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->layout = 'default';
|
||||
$this->controller->set(array('file' => $file,
|
||||
'title' => __('Missing Layout', true)));
|
||||
|
@ -276,11 +253,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingConnection($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('model' => $className,
|
||||
'title' => __('Missing Database Connection', true)));
|
||||
$this->controller->render('missingConnection');
|
||||
|
@ -293,12 +267,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingHelperFile($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
|
||||
'file' => $file,
|
||||
'title' => __('Missing Helper File', true)));
|
||||
|
@ -312,12 +282,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingHelperClass($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
|
||||
'file' => $file,
|
||||
'title' => __('Missing Helper Class', true)));
|
||||
|
@ -331,12 +297,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingComponentFile($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'component' => $component,
|
||||
'file' => $file,
|
||||
|
@ -351,12 +313,8 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingComponentClass($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'component' => $component,
|
||||
'file' => $file,
|
||||
|
@ -371,26 +329,12 @@ class ErrorHandler extends Object{
|
|||
* @access public
|
||||
*/
|
||||
function missingModel($params) {
|
||||
extract(Router::getPaths());
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('model' => $className,
|
||||
'title' => __('Missing Model', true)));
|
||||
$this->controller->render('missingModel');
|
||||
exit();
|
||||
}
|
||||
/**
|
||||
* Path to the web root.
|
||||
*
|
||||
* @return string full web root path
|
||||
* @access private
|
||||
*/
|
||||
function _webroot() {
|
||||
$this->__dispatch->baseUrl();
|
||||
return $this->__dispatch->webroot;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -157,9 +157,12 @@ class Object {
|
|||
*/
|
||||
function cakeError($method, $messages) {
|
||||
if (!class_exists('ErrorHandler')) {
|
||||
uses('error');
|
||||
if (file_exists(APP . 'error.php')) {
|
||||
include_once (APP . 'error.php');
|
||||
} elseif (file_exists(APP . 'app_error.php')) {
|
||||
include_once (APP . 'app_error.php');
|
||||
} else {
|
||||
App::import('Core', 'Error');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,9 +237,9 @@ class Object {
|
|||
$vars = unserialize(${$name});
|
||||
foreach ($vars['0'] as $key => $value) {
|
||||
if(strpos($key, '_behavior')) {
|
||||
loadBehavior(Inflector::classify(str_replace('_behavior', '', $key)));
|
||||
App::import('Behavior', Inflector::classify(str_replace('_behavior', '', $key)));
|
||||
} else {
|
||||
loadModel(Inflector::classify($key));
|
||||
App::import('Model', Inflector::classify($key));
|
||||
}
|
||||
}
|
||||
unset($vars);
|
||||
|
|
Loading…
Reference in a new issue