Skip to content

Commit 60e4466

Browse files
committed
Moving ErrorHandler to ConsoleErrorHandler so it doesn't have classname conflicts.
Making the console use a subclass of ErrorHandler.
1 parent 034aaa7 commit 60e4466

File tree

2 files changed

+99
-249
lines changed

2 files changed

+99
-249
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* ErrorHandler for Console Shells
4+
*
5+
* PHP versions 4 and 5
6+
*
7+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8+
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
9+
*
10+
* Licensed under The MIT License
11+
* Redistributions of files must retain the above copyright notice.
12+
*
13+
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14+
* @link http://cakephp.org CakePHP(tm) Project
15+
* @package cake
16+
* @subpackage cake.cake.console
17+
* @since CakePHP(tm) v 1.2.0.5074
18+
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
19+
*/
20+
21+
App::import('Core', 'ErrorHandler');
22+
23+
/**
24+
* Error Handler for Cake console. Does simple printing of the
25+
* exception that occurred and the stack trace of the error.
26+
*
27+
* @package cake
28+
* @subpackage cake.cake.console
29+
*/
30+
class ConsoleErrorHandler extends ErrorHandler {
31+
32+
/**
33+
* Standard error stream.
34+
*
35+
* @var filehandle
36+
* @access public
37+
*/
38+
public $stderr;
39+
40+
/**
41+
* Class constructor.
42+
*
43+
* @param Exception $error Exception to handle.
44+
* @param array $messages Error messages
45+
*/
46+
function __construct($error) {
47+
$this->stderr = fopen('php://stderr', 'w');
48+
parent::__construct($error);
49+
}
50+
51+
/**
52+
* Handle a exception in the console environment.
53+
*
54+
* @return void
55+
*/
56+
public static function handleException($exception) {
57+
$error = new ConsoleErrorHandler($exception);
58+
$error->render();
59+
}
60+
61+
/**
62+
* Do nothing, no controllers are needed in the console.
63+
*
64+
* @return void
65+
*/
66+
protected function _getController($exception) {
67+
return null;
68+
}
69+
70+
/**
71+
* Overwrite how _cakeError behaves for console. There is no reason
72+
* to prepare urls as they are not relevant for this.
73+
*
74+
* @param $error Exception Exception being handled.
75+
* @return void
76+
*/
77+
protected function _cakeError($error) {
78+
$this->_outputMessage('');
79+
}
80+
81+
/**
82+
* Outputs the exception to STDERR.
83+
*
84+
* @param string $template The name of the template to render.
85+
* @return void
86+
*/
87+
public function _outputMessage($template) {
88+
$this->stderr($this->error->getMessage());
89+
}
90+
91+
/**
92+
* Outputs to the stderr filehandle.
93+
*
94+
* @param string $string Error text to output.
95+
*/
96+
public function stderr($string) {
97+
fwrite($this->stderr, "Error: ". $string . "\n");
98+
}
99+
}

cake/console/error.php

Lines changed: 0 additions & 249 deletions
This file was deleted.

0 commit comments

Comments
 (0)