Skip to content

Commit 7e6773c

Browse files
committed
Updating ErrorHandler and CakeErrorController to use CakeRequest. Tests updated.
1 parent 3e3265a commit 7e6773c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

cake/libs/error.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CakeErrorController extends AppController {
4848
function __construct() {
4949
parent::__construct();
5050
$this->_set(Router::getPaths());
51-
$this->params = Router::getParams();
51+
$this->request = $this->params = Router::getRequest();
5252
$this->constructClasses();
5353
$this->Component->initialize($this);
5454
$this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
@@ -87,9 +87,9 @@ function __construct($method, $messages) {
8787

8888
if ($__previousError != array($method, $messages)) {
8989
$__previousError = array($method, $messages);
90-
$this->controller =& new CakeErrorController();
90+
$this->controller = new CakeErrorController();
9191
} else {
92-
$this->controller =& new Controller();
92+
$this->controller = new Controller();
9393
$this->controller->viewPath = 'errors';
9494
}
9595
$options = array('escape' => false);
@@ -158,7 +158,7 @@ public function error404($params) {
158158
'code' => '404',
159159
'name' => __('Not Found'),
160160
'message' => h($url),
161-
'base' => $this->controller->base
161+
'base' => $this->controller->request->base
162162
));
163163
$this->_outputMessage('error404');
164164
}
@@ -172,15 +172,15 @@ public function error500($params) {
172172
extract($params, EXTR_OVERWRITE);
173173

174174
if (!isset($url)) {
175-
$url = $this->controller->here;
175+
$url = $this->controller->request->here;
176176
}
177177
$url = Router::normalize($url);
178178
$this->controller->header("HTTP/1.0 500 Internal Server Error");
179179
$this->controller->set(array(
180180
'code' => '500',
181181
'name' => __('An Internal Error Has Occurred'),
182182
'message' => h($url),
183-
'base' => $this->controller->base
183+
'base' => $this->controller->request->base
184184
));
185185
$this->_outputMessage('error500');
186186
}

cake/tests/cases/libs/error.test.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ function skip() {
269269
$this->skipIf(PHP_SAPI === 'cli', '%s Cannot be run from console');
270270
}
271271

272+
/**
273+
* setup create a request object to get out of router later.
274+
*
275+
* @return void
276+
*/
277+
function setUp() {
278+
$request = new CakeRequest(null, false);
279+
$request->base = '';
280+
Router::setRequestInfo($request);
281+
}
282+
272283
/**
273284
* test that methods declared in an ErrorHandler subclass are not converted
274285
* into error404 when debug == 0
@@ -279,19 +290,19 @@ function testSubclassMethodsNotBeingConvertedToError() {
279290
$back = Configure::read('debug');
280291
Configure::write('debug', 2);
281292
ob_start();
282-
$ErrorHandler =& new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
293+
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
283294
$result = ob_get_clean();
284295
$this->assertEqual($result, 'widget thing is missing');
285296

286297
Configure::write('debug', 0);
287298
ob_start();
288-
$ErrorHandler =& new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
299+
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
289300
$result = ob_get_clean();
290301
$this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404. %s');
291302

292303
Configure::write('debug', 0);
293304
ob_start();
294-
$ErrorHandler =& new MyCustomErrorHandler('missingController', array(
305+
$ErrorHandler = new MyCustomErrorHandler('missingController', array(
295306
'className' => 'Missing', 'message' => 'Page not found'
296307
));
297308
$result = ob_get_clean();

0 commit comments

Comments
 (0)