Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -1,41 +1,40 @@
<?php
/**
* Error handler
* ErrorHandler class
*
* Provides Error Capturing for Framework errors.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Error
* @since CakePHP(tm) v 0.10.5.1732
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Debugger', 'Utility');
App::uses('CakeLog', 'Log');
App::uses('ExceptionRenderer', 'Error');
App::uses('Router', 'Routing');
/**
*
* Error Handler provides basic error and exception handling for your application. It captures and
* handles all unhandled exceptions and errors. Displays helpful framework errors when debug > 1.
*
* ### Uncaught exceptions
*
* When debug < 1 a CakeException will render 404 or 500 errors. If an uncaught exception is thrown
* When debug < 1 a CakeException will render 404 or 500 errors. If an uncaught exception is thrown
* and it is a type that ErrorHandler does not know about it will be treated as a 500 error.
*
* ### Implementing application specific exception handling
*
* You can implement application specific exception handling in one of a few ways. Each approach
* You can implement application specific exception handling in one of a few ways. Each approach
* gives you different amounts of control over the exception handling process.
*
* - Set Configure::write('Exception.handler', 'YourClass::yourMethod');
@ -44,22 +43,22 @@ App::uses('ExceptionRenderer', 'Error');
*
* #### Create your own Exception handler with `Exception.handler`
*
* This gives you full control over the exception handling process. The class you choose should be
* loaded in your app/Config/bootstrap.php, so its available to handle any exceptions. You can
* This gives you full control over the exception handling process. The class you choose should be
* loaded in your app/Config/bootstrap.php, so its available to handle any exceptions. You can
* define the handler as any callback type. Using Exception.handler overrides all other exception
* handling settings and logic.
*
* #### Using `AppController::appError();`
*
* This controller method is called instead of the default exception rendering. It receives the
* thrown exception as its only argument. You should implement your error handling in that method.
* This controller method is called instead of the default exception rendering. It receives the
* thrown exception as its only argument. You should implement your error handling in that method.
* Using AppController::appError(), will supersede any configuration for Exception.renderer.
*
* #### Using a custom renderer with `Exception.renderer`
*
* If you don't want to take control of the exception handling, but want to change how exceptions are
* rendered you can use `Exception.renderer` to choose a class to render exception pages. By default
* `ExceptionRenderer` is used. Your custom exception renderer class should be placed in app/Lib/Error.
* rendered you can use `Exception.renderer` to choose a class to render exception pages. By default
* `ExceptionRenderer` is used. Your custom exception renderer class should be placed in app/Lib/Error.
*
* Your custom renderer should expect an exception in its constructor, and implement a render method.
* Failing to do so will cause additional errors.
@ -73,8 +72,8 @@ App::uses('ExceptionRenderer', 'Error');
* ### PHP errors
*
* Error handler also provides the built in features for handling php errors (trigger_error).
* While in debug mode, errors will be output to the screen using debugger. While in production mode,
* errors will be logged to CakeLog. You can control which errors are logged by setting
* While in debug mode, errors will be output to the screen using debugger. While in production mode,
* errors will be logged to CakeLog. You can control which errors are logged by setting
* `Error.level` in your core.php.
*
* #### Logging errors
@ -84,7 +83,7 @@ App::uses('ExceptionRenderer', 'Error');
*
* #### Controlling what errors are logged/displayed
*
* You can control which errors are logged / displayed by ErrorHandler by setting `Error.level`. Setting this
* You can control which errors are logged / displayed by ErrorHandler by setting `Error.level`. Setting this
* to one or a combination of a few of the E_* constants will only enable the specified errors.
*
* e.g. `Configure::write('Error.level', E_ALL & ~E_NOTICE);`
@ -96,27 +95,29 @@ App::uses('ExceptionRenderer', 'Error');
*/
class ErrorHandler {
/**
* Whether to give up rendering an exception, if the renderer itself is
* throwing exceptions.
*
* @var bool
*/
protected static $_bailExceptionRendering = false;
/**
* Set as the default exception handler by the CakePHP bootstrap process.
*
* This will either use custom exception renderer class if configured,
* or use the default ExceptionRenderer.
*
* @param Exception $exception
* @param Exception|ParseError $exception The exception to render.
* @return void
* @see http://php.net/manual/en/function.set-exception-handler.php
*/
public static function handleException(Exception $exception) {
public static function handleException($exception) {
$config = Configure::read('Exception');
if (!empty($config['log'])) {
$message = sprintf("[%s] %s\n%s",
get_class($exception),
$exception->getMessage(),
$exception->getTraceAsString()
);
CakeLog::write(LOG_ERR, $message);
}
$renderer = $config['renderer'];
static::_log($exception, $config);
$renderer = isset($config['renderer']) ? $config['renderer'] : 'ExceptionRenderer';
if ($renderer !== 'ExceptionRenderer') {
list($plugin, $renderer) = pluginSplit($renderer, true);
App::uses($renderer, $plugin . 'Error');
@ -132,33 +133,83 @@ class ErrorHandler {
$e->getMessage(),
$e->getTraceAsString()
);
static::$_bailExceptionRendering = true;
trigger_error($message, E_USER_ERROR);
}
}
/**
* Generates a formatted error message
*
* @param Exception $exception Exception instance
* @return string Formatted message
*/
protected static function _getMessage($exception) {
$message = sprintf("[%s] %s",
get_class($exception),
$exception->getMessage()
);
if (method_exists($exception, 'getAttributes')) {
$attributes = $exception->getAttributes();
if ($attributes) {
$message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);
}
}
if (PHP_SAPI !== 'cli') {
$request = Router::getRequest();
if ($request) {
$message .= "\nRequest URL: " . $request->here();
}
}
$message .= "\nStack Trace:\n" . $exception->getTraceAsString();
return $message;
}
/**
* Handles exception logging
*
* @param Exception|ParseError $exception The exception to render.
* @param array $config An array of configuration for logging.
* @return bool
*/
protected static function _log($exception, $config) {
if (empty($config['log'])) {
return false;
}
if (!empty($config['skipLog'])) {
foreach ((array)$config['skipLog'] as $class) {
if ($exception instanceof $class) {
return false;
}
}
}
return CakeLog::write(LOG_ERR, static::_getMessage($exception));
}
/**
* Set as the default error handler by CakePHP. Use Configure::write('Error.handler', $callback), to use your own
* error handling methods. This function will use Debugger to display errors when debug > 0. And
* error handling methods. This function will use Debugger to display errors when debug > 0. And
* will log errors to CakeLog, when debug == 0.
*
* You can use Configure::write('Error.level', $value); to set what type of errors will be handled here.
* Stack traces for errors can be enabled with Configure::write('Error.trace', true);
*
* @param integer $code Code of error
* @param int $code Code of error
* @param string $description Error description
* @param string $file File on which error occurred
* @param integer $line Line that triggered the error
* @param int $line Line that triggered the error
* @param array $context Context
* @return boolean true if error was handled
* @return bool true if error was handled
*/
public static function handleError($code, $description, $file = null, $line = null, $context = null) {
if (error_reporting() === 0) {
return false;
}
$errorConfig = Configure::read('Error');
list($error, $log) = self::mapErrorCode($code);
list($error, $log) = static::mapErrorCode($code);
if ($log === LOG_ERR) {
return self::handleFatalError($code, $description, $file, $line);
return static::handleFatalError($code, $description, $file, $line);
}
$debug = Configure::read('debug');
@ -175,24 +226,21 @@ class ErrorHandler {
'path' => Debugger::trimPath($file)
);
return Debugger::getInstance()->outputError($data);
} else {
$message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
if (!empty($errorConfig['trace'])) {
$trace = Debugger::trace(array('start' => 1, 'format' => 'log'));
$message .= "\nTrace:\n" . $trace . "\n";
}
return CakeLog::write($log, $message);
}
$message = static::_getErrorMessage($error, $code, $description, $file, $line);
return CakeLog::write($log, $message);
}
/**
* Generate an error page when some fatal error happens.
*
* @param integer $code Code of error
* @param int $code Code of error
* @param string $description Error description
* @param string $file File on which error occurred
* @param integer $line Line that triggered the error
* @return boolean
* @param int $line Line that triggered the error
* @return bool
* @throws FatalErrorException If the Exception renderer threw an exception during rendering, and debug > 0.
* @throws InternalErrorException If the Exception renderer threw an exception during rendering, and debug is 0.
*/
public static function handleFatalError($code, $description, $file, $line) {
$logMessage = 'Fatal Error (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
@ -204,21 +252,29 @@ class ErrorHandler {
}
if (ob_get_level()) {
ob_clean();
ob_end_clean();
}
if (Configure::read('debug')) {
call_user_func($exceptionHandler, new FatalErrorException($description, 500, $file, $line));
$exception = new FatalErrorException($description, 500, $file, $line);
} else {
call_user_func($exceptionHandler, new InternalErrorException());
$exception = new InternalErrorException();
}
if (static::$_bailExceptionRendering) {
static::$_bailExceptionRendering = false;
throw $exception;
}
call_user_func($exceptionHandler, $exception);
return false;
}
/**
* Map an error code into an Error word, and log location.
*
* @param integer $code Error code to map
* @param int $code Error code to map
* @return array Array of error word, and log location.
*/
public static function mapErrorCode($code) {
@ -231,30 +287,59 @@ class ErrorHandler {
case E_USER_ERROR:
$error = 'Fatal Error';
$log = LOG_ERR;
break;
break;
case E_WARNING:
case E_USER_WARNING:
case E_COMPILE_WARNING:
case E_RECOVERABLE_ERROR:
$error = 'Warning';
$log = LOG_WARNING;
break;
break;
case E_NOTICE:
case E_USER_NOTICE:
$error = 'Notice';
$log = LOG_NOTICE;
break;
break;
case E_STRICT:
$error = 'Strict';
$log = LOG_NOTICE;
break;
break;
case E_DEPRECATED:
case E_USER_DEPRECATED:
$error = 'Deprecated';
$log = LOG_NOTICE;
break;
break;
}
return array($error, $log);
}
/**
* Generate the string to use to describe the error.
*
* @param string $error The error type (e.g. "Warning")
* @param int $code Code of error
* @param string $description Error description
* @param string $file File on which error occurred
* @param int $line Line that triggered the error
* @return string
*/
protected static function _getErrorMessage($error, $code, $description, $file, $line) {
$errorConfig = Configure::read('Error');
$message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
if (!empty($errorConfig['trace'])) {
// https://bugs.php.net/bug.php?id=65322
if (version_compare(PHP_VERSION, '5.4.21', '<')) {
if (!class_exists('Debugger')) {
App::load('Debugger');
}
if (!class_exists('CakeText')) {
App::uses('CakeText', 'Utility');
App::load('CakeText');
}
}
$trace = Debugger::trace(array('start' => 1, 'format' => 'log'));
$message .= "\nTrace:\n" . $trace . "\n";
}
return $message;
}
}

View file

@ -2,47 +2,49 @@
/**
* Exception Renderer
*
* Provides Exception rendering features. Which allow exceptions to be rendered
* Provides Exception rendering features. Which allow exceptions to be rendered
* as HTML pages.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Error
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Sanitize', 'Utility');
App::uses('Dispatcher', 'Routing');
App::uses('Router', 'Routing');
App::uses('CakeResponse', 'Network');
App::uses('Controller', 'Controller');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
App::uses('CakeEvent', 'Event');
/**
* Exception Renderer.
*
* Captures and handles all unhandled exceptions. Displays helpful framework errors when debug > 1.
* When debug < 1 a CakeException will render 404 or 500 errors. If an uncaught exception is thrown
* When debug < 1 a CakeException will render 404 or 500 errors. If an uncaught exception is thrown
* and it is a type that ExceptionHandler does not know about it will be treated as a 500 error.
*
* ### Implementing application specific exception rendering
*
* You can implement application specific exception handling in one of a few ways:
*
* - Create a AppController::appError();
* - Create an AppController::appError();
* - Create a subclass of ExceptionRenderer and configure it to be the `Exception.renderer`
*
* #### Using AppController::appError();
*
* This controller method is called instead of the default exception handling. It receives the
* thrown exception as its only argument. You should implement your error handling in that method.
* This controller method is called instead of the default exception handling. It receives the
* thrown exception as its only argument. You should implement your error handling in that method.
*
* #### Using a subclass of ExceptionRenderer
*
@ -87,13 +89,14 @@ class ExceptionRenderer {
* If the error is a CakeException it will be converted to either a 400 or a 500
* code error depending on the code used to construct the error.
*
* @param Exception $exception Exception
* @param Exception|ParseError $exception Exception
*/
public function __construct(Exception $exception) {
public function __construct($exception) {
$this->controller = $this->_getController($exception);
if (method_exists($this->controller, 'apperror')) {
return $this->controller->appError($exception);
if (method_exists($this->controller, 'appError')) {
$this->controller->appError($exception);
return;
}
$method = $template = Inflector::variable(str_replace('Exception', '', get_class($exception)));
$code = $exception->getCode();
@ -102,10 +105,7 @@ class ExceptionRenderer {
if ($exception instanceof CakeException && !$methodExists) {
$method = '_cakeError';
if (empty($template)) {
$template = 'error500';
}
if ($template == 'internalError') {
if (empty($template) || $template === 'internalError') {
$template = 'error500';
}
} elseif ($exception instanceof PDOException) {
@ -119,13 +119,12 @@ class ExceptionRenderer {
}
}
if (Configure::read('debug') == 0) {
if ($method == '_cakeError') {
$method = 'error400';
}
if ($code == 500) {
$method = 'error500';
}
$isNotDebug = !Configure::read('debug');
if ($isNotDebug && $method === '_cakeError') {
$method = 'error400';
}
if ($isNotDebug && $code == 500) {
$method = 'error500';
}
$this->template = $template;
$this->method = $method;
@ -147,13 +146,31 @@ class ExceptionRenderer {
if (!$request = Router::getRequest(true)) {
$request = new CakeRequest();
}
$response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
try {
$controller = new CakeErrorController($request, $response);
$controller->startupProcess();
} catch (Exception $e) {
if (!empty($controller) && $controller->Components->enabled('RequestHandler')) {
$controller->RequestHandler->startup($controller);
$response = new CakeResponse();
if (method_exists($exception, 'responseHeader')) {
$response->header($exception->responseHeader());
}
if (class_exists('AppController')) {
try {
$controller = new CakeErrorController($request, $response);
$controller->startupProcess();
$startup = true;
} catch (Exception $e) {
$startup = false;
}
// Retry RequestHandler, as another aspect of startupProcess()
// could have failed. Ignore any exceptions out of startup, as
// there could be userland input data parsers.
if ($startup === false &&
!empty($controller) &&
$controller->Components->enabled('RequestHandler')
) {
try {
$controller->RequestHandler->startup($controller);
} catch (Exception $e) {
}
}
}
if (empty($controller)) {
@ -177,7 +194,7 @@ class ExceptionRenderer {
/**
* Generic handler for the internal framework errors CakePHP can generate.
*
* @param CakeException $error
* @param CakeException $error The exception to render.
* @return void
*/
protected function _cakeError(CakeException $error) {
@ -186,10 +203,11 @@ class ExceptionRenderer {
$this->controller->response->statusCode($code);
$this->controller->set(array(
'code' => $code,
'name' => h($error->getMessage()),
'message' => h($error->getMessage()),
'url' => h($url),
'name' => $error->getMessage(),
'error' => $error,
'_serialize' => array('code', 'url', 'name')
'_serialize' => array('code', 'name', 'message', 'url')
));
$this->controller->set($error->getAttributes());
$this->_outputMessage($this->template);
@ -198,21 +216,22 @@ class ExceptionRenderer {
/**
* Convenience method to display a 400 series page.
*
* @param Exception $error
* @param Exception $error The exception to render.
* @return void
*/
public function error400($error) {
$message = $error->getMessage();
if (Configure::read('debug') == 0 && $error instanceof CakeException) {
if (!Configure::read('debug') && $error instanceof CakeException) {
$message = __d('cake', 'Not Found');
}
$url = $this->controller->request->here();
$this->controller->response->statusCode($error->getCode());
$this->controller->set(array(
'name' => $message,
'name' => h($message),
'message' => h($message),
'url' => h($url),
'error' => $error,
'_serialize' => array('name', 'url')
'_serialize' => array('name', 'message', 'url')
));
$this->_outputMessage('error400');
}
@ -220,22 +239,23 @@ class ExceptionRenderer {
/**
* Convenience method to display a 500 page.
*
* @param Exception $error
* @param Exception $error The exception to render.
* @return void
*/
public function error500($error) {
$message = $error->getMessage();
if (Configure::read('debug') == 0) {
if (!Configure::read('debug')) {
$message = __d('cake', 'An Internal Error Has Occurred.');
}
$url = $this->controller->request->here();
$code = ($error->getCode() > 500 && $error->getCode() < 506) ? $error->getCode() : 500;
$this->controller->response->statusCode($code);
$this->controller->set(array(
'name' => $message,
'message' => h($url),
'name' => h($message),
'message' => h($message),
'url' => h($url),
'error' => $error,
'_serialize' => array('name', 'message')
'_serialize' => array('name', 'message', 'url')
));
$this->_outputMessage('error500');
}
@ -243,7 +263,7 @@ class ExceptionRenderer {
/**
* Convenience method to display a PDOException.
*
* @param PDOException $error
* @param PDOException $error The exception to render.
* @return void
*/
public function pdoError(PDOException $error) {
@ -252,10 +272,11 @@ class ExceptionRenderer {
$this->controller->response->statusCode($code);
$this->controller->set(array(
'code' => $code,
'name' => h($error->getMessage()),
'message' => h($error->getMessage()),
'url' => h($url),
'name' => $error->getMessage(),
'error' => $error,
'_serialize' => array('code', 'url', 'name', 'error')
'_serialize' => array('code', 'name', 'message', 'url', 'error')
));
$this->_outputMessage($this->template);
}
@ -269,7 +290,7 @@ class ExceptionRenderer {
protected function _outputMessage($template) {
try {
$this->controller->render($template);
$this->controller->afterFilter();
$this->_shutdown();
$this->controller->response->send();
} catch (MissingViewException $e) {
$attributes = $e->getAttributes();
@ -278,6 +299,12 @@ class ExceptionRenderer {
} else {
$this->_outputMessage('error500');
}
} catch (MissingPluginException $e) {
$attributes = $e->getAttributes();
if (isset($attributes['plugin']) && $attributes['plugin'] === $this->controller->plugin) {
$this->controller->plugin = null;
}
$this->_outputMessageSafe('error500');
} catch (Exception $e) {
$this->_outputMessageSafe('error500');
}
@ -293,7 +320,7 @@ class ExceptionRenderer {
protected function _outputMessageSafe($template) {
$this->controller->layoutPath = null;
$this->controller->subDir = null;
$this->controller->viewPath = 'Errors/';
$this->controller->viewPath = 'Errors';
$this->controller->layout = 'error';
$this->controller->helpers = array('Form', 'Html', 'Session');
@ -303,4 +330,23 @@ class ExceptionRenderer {
$this->controller->response->send();
}
/**
* Run the shutdown events.
*
* Triggers the afterFilter and afterDispatch events.
*
* @return void
*/
protected function _shutdown() {
$afterFilterEvent = new CakeEvent('Controller.shutdown', $this->controller);
$this->controller->getEventManager()->dispatch($afterFilterEvent);
$Dispatcher = new Dispatcher();
$afterDispatchEvent = new CakeEvent('Dispatcher.afterDispatch', $Dispatcher, array(
'request' => $this->controller->request,
'response' => $this->controller->response
));
$Dispatcher->getEventManager()->dispatch($afterDispatchEvent);
}
}

View file

@ -1,32 +1,68 @@
<?php
/**
* Exceptions file. Contains the various exceptions CakePHP will throw until they are
* Exceptions file. Contains the various exceptions CakePHP will throw until they are
* moved into their permanent location.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html
* @package Cake.Error
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Base class that all Exceptions extend.
*
* @package Cake.Error
*/
class CakeBaseException extends RuntimeException {
/**
* Array of headers to be passed to CakeResponse::header()
*
* @var array
*/
protected $_responseHeaders = null;
/**
* Get/set the response header to be used
*
* @param string|array $header An array of header strings or a single header string
* - an associative array of "header name" => "header value"
* - an array of string headers is also accepted
* @param string $value The header value.
* @return array
* @see CakeResponse::header()
*/
public function responseHeader($header = null, $value = null) {
if ($header) {
if (is_array($header)) {
return $this->_responseHeaders = $header;
}
$this->_responseHeaders = array($header => $value);
}
return $this->_responseHeaders;
}
}
if (!class_exists('HttpException', false)) {
/**
* Parent class for all of the HTTP related exceptions in CakePHP.
*
* All HTTP status/error related exceptions should extend this class so
* catch blocks can be specifically typed.
*
* @package Cake.Error
*/
if (!class_exists('HttpException')) {
class HttpException extends RuntimeException {
class HttpException extends CakeBaseException {
}
}
@ -41,7 +77,7 @@ class BadRequestException extends HttpException {
* Constructor
*
* @param string $message If no message is given 'Bad Request' will be the message
* @param string $code Status code, defaults to 400
* @param int $code Status code, defaults to 400
*/
public function __construct($message = null, $code = 400) {
if (empty($message)) {
@ -63,7 +99,7 @@ class UnauthorizedException extends HttpException {
* Constructor
*
* @param string $message If no message is given 'Unauthorized' will be the message
* @param string $code Status code, defaults to 401
* @param int $code Status code, defaults to 401
*/
public function __construct($message = null, $code = 401) {
if (empty($message)) {
@ -85,7 +121,7 @@ class ForbiddenException extends HttpException {
* Constructor
*
* @param string $message If no message is given 'Forbidden' will be the message
* @param string $code Status code, defaults to 403
* @param int $code Status code, defaults to 403
*/
public function __construct($message = null, $code = 403) {
if (empty($message)) {
@ -107,7 +143,7 @@ class NotFoundException extends HttpException {
* Constructor
*
* @param string $message If no message is given 'Not Found' will be the message
* @param string $code Status code, defaults to 404
* @param int $code Status code, defaults to 404
*/
public function __construct($message = null, $code = 404) {
if (empty($message)) {
@ -129,7 +165,7 @@ class MethodNotAllowedException extends HttpException {
* Constructor
*
* @param string $message If no message is given 'Method Not Allowed' will be the message
* @param string $code Status code, defaults to 405
* @param int $code Status code, defaults to 405
*/
public function __construct($message = null, $code = 405) {
if (empty($message)) {
@ -151,7 +187,7 @@ class InternalErrorException extends HttpException {
* Constructor
*
* @param string $message If no message is given 'Internal Server Error' will be the message
* @param string $code Status code, defaults to 500
* @param int $code Status code, defaults to 500
*/
public function __construct($message = null, $code = 500) {
if (empty($message)) {
@ -168,7 +204,7 @@ class InternalErrorException extends HttpException {
*
* @package Cake.Error
*/
class CakeException extends RuntimeException {
class CakeException extends CakeBaseException {
/**
* Array of attributes that are passed in from the constructor, and
@ -193,7 +229,7 @@ class CakeException extends RuntimeException {
*
* @param string|array $message Either the string of the error message, or an array of attributes
* that are made available in the view, and sprintf()'d into CakeException::$_messageTemplate
* @param string $code The code of the error, is also the HTTP status code for the error.
* @param int $code The code of the error, is also the HTTP status code for the error.
*/
public function __construct($message, $code = 500) {
if (is_array($message)) {
@ -343,6 +379,12 @@ class MissingConnectionException extends CakeException {
protected $_messageTemplate = 'Database connection "%s" is missing, or could not be created.';
/**
* Constructor
*
* @param string|array $message The error message.
* @param int $code The error code.
*/
public function __construct($message, $code = 500) {
if (is_array($message)) {
$message += array('enabled' => true);
@ -403,7 +445,7 @@ class MissingDatasourceConfigException extends CakeException {
*/
class MissingDatasourceException extends CakeException {
protected $_messageTemplate = 'Datasource class %s could not be found.';
protected $_messageTemplate = 'Datasource class %s could not be found. %s';
}
@ -471,7 +513,7 @@ class AclException extends CakeException {
}
/**
* Exception class for Cache. This exception will be thrown from Cache when it
* Exception class for Cache. This exception will be thrown from Cache when it
* encounters an error.
*
* @package Cake.Error
@ -480,7 +522,7 @@ class CacheException extends CakeException {
}
/**
* Exception class for Router. This exception will be thrown from Router when it
* Exception class for Router. This exception will be thrown from Router when it
* encounters an error.
*
* @package Cake.Error
@ -489,7 +531,7 @@ class RouterException extends CakeException {
}
/**
* Exception class for CakeLog. This exception will be thrown from CakeLog when it
* Exception class for CakeLog. This exception will be thrown from CakeLog when it
* encounters an error.
*
* @package Cake.Error
@ -498,7 +540,7 @@ class CakeLogException extends CakeException {
}
/**
* Exception class for CakeSession. This exception will be thrown from CakeSession when it
* Exception class for CakeSession. This exception will be thrown from CakeSession when it
* encounters an error.
*
* @package Cake.Error
@ -507,7 +549,7 @@ class CakeSessionException extends CakeException {
}
/**
* Exception class for Configure. This exception will be thrown from Configure when it
* Exception class for Configure. This exception will be thrown from Configure when it
* encounters an error.
*
* @package Cake.Error
@ -525,7 +567,7 @@ class SocketException extends CakeException {
}
/**
* Exception class for Xml. This exception will be thrown from Xml when it
* Exception class for Xml. This exception will be thrown from Xml when it
* encounters an error.
*
* @package Cake.Error
@ -534,7 +576,7 @@ class XmlException extends CakeException {
}
/**
* Exception class for Console libraries. This exception will be thrown from Console library
* Exception class for Console libraries. This exception will be thrown from Console library
* classes when they encounter an error.
*
* @package Cake.Error
@ -552,10 +594,10 @@ class FatalErrorException extends CakeException {
/**
* Constructor
*
* @param string $message
* @param integer $code
* @param string $file
* @param integer $line
* @param string $message The error message.
* @param int $code The error code.
* @param string $file The file the error occurred in.
* @param int $line The line the error occurred on.
*/
public function __construct($message, $code = 500, $file = null, $line = null) {
parent::__construct($message, $code);