Skip to content

Commit 4bbc3c8

Browse files
committed
Making App/Console/cake work again.
1 parent 701cf08 commit 4bbc3c8

File tree

4 files changed

+10
-52
lines changed

4 files changed

+10
-52
lines changed

App/Config/error.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
*
1313
* - `handler` - callback - The callback to handle errors. You can set this to any callable type,
1414
* including anonymous functions.
15+
* - `consoleHandler` - callback - The callback to handle errors. You can set this to any callable type,
16+
* including anonymous functions.
1517
* - `level` - int - The level of errors you are interested in capturing.
1618
* - `trace` - boolean - Include stack traces for errors in log files.
1719
*
1820
* @see ErrorHandler for more information on error handling and configuration.
1921
*/
2022
$error = array(
2123
'handler' => 'Cake\Error\ErrorHandler::handleError',
24+
'consoleHandler' => 'Cake\Console\ConsoleErrorHandler::handleError',
2225
'level' => E_ALL & ~E_DEPRECATED,
2326
'trace' => true
2427
);
@@ -41,6 +44,7 @@
4144
*/
4245
$exception = array(
4346
'handler' => 'Cake\Error\ErrorHandler::handleException',
47+
'consoleHandler' => 'Cake\Console\ConsoleErrorHandler::handleException',
4448
'renderer' => 'Cake\Error\ExceptionRenderer',
4549
'log' => true
4650
);

App/Console/cake.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,5 @@
1717
* @since CakePHP(tm) v 2.0
1818
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1919
*/
20-
$ds = DIRECTORY_SEPARATOR;
21-
$dispatcher = 'Cake' . $ds . 'Console' . $ds . 'ShellDispatcher.php';
22-
23-
if (function_exists('ini_set')) {
24-
$root = dirname(dirname(__DIR__));
25-
ini_set('include_path', $root . $ds . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
26-
}
27-
28-
if (!include ($dispatcher)) {
29-
trigger_error('Could not locate CakePHP core files.', E_USER_ERROR);
30-
}
31-
unset($paths, $path, $dispatcher, $root, $ds);
32-
20+
include dirname(__DIR__) . '/Config/bootstrap.php';
3321
return Cake\Console\ShellDispatcher::run($argv);

lib/Cake/Console/ConsoleErrorHandler.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ public static function getStderr() {
5252
* @param Exception $exception The exception to handle
5353
* @return void
5454
*/
55-
public function handleException(\Exception $exception) {
55+
public static function handleException(\Exception $exception) {
5656
$stderr = static::getStderr();
5757
$stderr->write(__d('cake_console', "<error>Error:</error> %s\n%s",
5858
$exception->getMessage(),
5959
$exception->getTraceAsString()
6060
));
61-
$this->_stop($exception->getCode() ? $exception->getCode() : 1);
61+
// TODO this makes this method impossible to test.
62+
exit($exception->getCode() ? $exception->getCode() : 1);
6263
}
6364

6465
/**
@@ -72,7 +73,7 @@ public function handleException(\Exception $exception) {
7273
* @param array $context The backtrace of the error.
7374
* @return void
7475
*/
75-
public function handleError($code, $description, $file = null, $line = null, $context = null) {
76+
public static function handleError($code, $description, $file = null, $line = null, $context = null) {
7677
if (error_reporting() === 0) {
7778
return;
7879
}
@@ -86,13 +87,4 @@ public function handleError($code, $description, $file = null, $line = null, $co
8687
}
8788
}
8889

89-
/**
90-
* Wrapper for exit(), used for testing.
91-
*
92-
* @param $code int The exit code.
93-
*/
94-
protected function _stop($code = 0) {
95-
exit($code);
96-
}
97-
9890
}

lib/Cake/Console/ShellDispatcher.php

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,7 @@ protected function _initConstants() {
8585
ini_set('implicit_flush', true);
8686
ini_set('max_execution_time', 0);
8787
}
88-
89-
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
90-
define('DS', DIRECTORY_SEPARATOR);
91-
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(__DIR__)));
92-
define('CAKEPHP_SHELL', true);
93-
if (!defined('CORE_PATH')) {
94-
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
95-
}
96-
}
88+
define('CAKEPHP_SHELL', true);
9789
}
9890

9991
/**
@@ -125,21 +117,6 @@ protected function _initEnvironment() {
125117
* @return boolean Success.
126118
*/
127119
protected function _bootstrap() {
128-
define('ROOT', $this->params['root']);
129-
define('APP_DIR', $this->params['app']);
130-
define('APP', $this->params['working'] . DS);
131-
define('WWW_ROOT', APP . $this->params['webroot'] . DS);
132-
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
133-
define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'Cake/Console/Templates/skel/tmp/');
134-
}
135-
$boot = file_exists(ROOT . DS . APP_DIR . DS . 'Config/bootstrap.php');
136-
require CORE_PATH . 'Cake/bootstrap.php';
137-
138-
if (!file_exists(APP . 'Config/core.php')) {
139-
include_once CAKE_CORE_INCLUDE_PATH . DS . 'Cake/Console/Templates/skel/Config/core.php';
140-
App::build();
141-
}
142-
143120
$this->setErrorHandlers();
144121

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

152129
/**
153130
* Set the error/exception handlers for the console
154-
* based on the `Error.consoleHandler`, and `Exception.consoleHandler` values
155-
* if they are set. If they are not set, the default ConsoleErrorHandler will be
156-
* used.
157131
*
158132
* @return void
159133
*/

0 commit comments

Comments
 (0)