Skip to content

Commit

Permalink
Making App/Console/cake work again.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 18, 2012
1 parent 701cf08 commit 4bbc3c8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 52 deletions.
4 changes: 4 additions & 0 deletions App/Config/error.php
Expand Up @@ -12,13 +12,16 @@
*
* - `handler` - callback - The callback to handle errors. You can set this to any callable type,
* including anonymous functions.
* - `consoleHandler` - callback - The callback to handle errors. You can set this to any callable type,
* including anonymous functions.
* - `level` - int - The level of errors you are interested in capturing.
* - `trace` - boolean - Include stack traces for errors in log files.
*
* @see ErrorHandler for more information on error handling and configuration.
*/
$error = array(
'handler' => 'Cake\Error\ErrorHandler::handleError',
'consoleHandler' => 'Cake\Console\ConsoleErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
);
Expand All @@ -41,6 +44,7 @@
*/
$exception = array(
'handler' => 'Cake\Error\ErrorHandler::handleException',
'consoleHandler' => 'Cake\Console\ConsoleErrorHandler::handleException',
'renderer' => 'Cake\Error\ExceptionRenderer',
'log' => true
);
Expand Down
14 changes: 1 addition & 13 deletions App/Console/cake.php
Expand Up @@ -17,17 +17,5 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
$ds = DIRECTORY_SEPARATOR;
$dispatcher = 'Cake' . $ds . 'Console' . $ds . 'ShellDispatcher.php';

if (function_exists('ini_set')) {
$root = dirname(dirname(__DIR__));
ini_set('include_path', $root . $ds . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}

if (!include ($dispatcher)) {
trigger_error('Could not locate CakePHP core files.', E_USER_ERROR);
}
unset($paths, $path, $dispatcher, $root, $ds);

include dirname(__DIR__) . '/Config/bootstrap.php';
return Cake\Console\ShellDispatcher::run($argv);
16 changes: 4 additions & 12 deletions lib/Cake/Console/ConsoleErrorHandler.php
Expand Up @@ -52,13 +52,14 @@ public static function getStderr() {
* @param Exception $exception The exception to handle
* @return void
*/
public function handleException(\Exception $exception) {
public static function handleException(\Exception $exception) {
$stderr = static::getStderr();
$stderr->write(__d('cake_console', "<error>Error:</error> %s\n%s",
$exception->getMessage(),
$exception->getTraceAsString()
));
$this->_stop($exception->getCode() ? $exception->getCode() : 1);
// TODO this makes this method impossible to test.
exit($exception->getCode() ? $exception->getCode() : 1);
}

/**
Expand All @@ -72,7 +73,7 @@ public function handleException(\Exception $exception) {
* @param array $context The backtrace of the error.
* @return void
*/
public function handleError($code, $description, $file = null, $line = null, $context = null) {
public static function handleError($code, $description, $file = null, $line = null, $context = null) {
if (error_reporting() === 0) {
return;
}
Expand All @@ -86,13 +87,4 @@ public function handleError($code, $description, $file = null, $line = null, $co
}
}

/**
* Wrapper for exit(), used for testing.
*
* @param $code int The exit code.
*/
protected function _stop($code = 0) {
exit($code);
}

}
28 changes: 1 addition & 27 deletions lib/Cake/Console/ShellDispatcher.php
Expand Up @@ -85,15 +85,7 @@ protected function _initConstants() {
ini_set('implicit_flush', true);
ini_set('max_execution_time', 0);
}

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('DS', DIRECTORY_SEPARATOR);
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(__DIR__)));
define('CAKEPHP_SHELL', true);
if (!defined('CORE_PATH')) {
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}
define('CAKEPHP_SHELL', true);
}

/**
Expand Down Expand Up @@ -125,21 +117,6 @@ protected function _initEnvironment() {
* @return boolean Success.
*/
protected function _bootstrap() {
define('ROOT', $this->params['root']);
define('APP_DIR', $this->params['app']);
define('APP', $this->params['working'] . DS);
define('WWW_ROOT', APP . $this->params['webroot'] . DS);
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'Cake/Console/Templates/skel/tmp/');
}
$boot = file_exists(ROOT . DS . APP_DIR . DS . 'Config/bootstrap.php');
require CORE_PATH . 'Cake/bootstrap.php';

if (!file_exists(APP . 'Config/core.php')) {
include_once CAKE_CORE_INCLUDE_PATH . DS . 'Cake/Console/Templates/skel/Config/core.php';
App::build();
}

$this->setErrorHandlers();

if (!defined('FULL_BASE_URL')) {
Expand All @@ -151,9 +128,6 @@ protected function _bootstrap() {

/**
* Set the error/exception handlers for the console
* based on the `Error.consoleHandler`, and `Exception.consoleHandler` values
* if they are set. If they are not set, the default ConsoleErrorHandler will be
* used.
*
* @return void
*/
Expand Down

0 comments on commit 4bbc3c8

Please sign in to comment.