mirror of
https://github.com/brmlab/brmbiolab_sklad.git
synced 2025-06-09 21:54:01 +02:00
Initial commit
This commit is contained in:
commit
3b93da31de
1004 changed files with 265840 additions and 0 deletions
301
lib/Cake/Error/ErrorHandler.php
Normal file
301
lib/Cake/Error/ErrorHandler.php
Normal file
|
@ -0,0 +1,301 @@
|
|||
<?php
|
||||
/**
|
||||
* ErrorHandler class
|
||||
*
|
||||
* Provides Error Capturing for Framework errors.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (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 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
|
||||
* 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
|
||||
* gives you different amounts of control over the exception handling process.
|
||||
*
|
||||
* - Set Configure::write('Exception.handler', 'YourClass::yourMethod');
|
||||
* - Create AppController::appError();
|
||||
* - Set Configure::write('Exception.renderer', 'YourClass');
|
||||
*
|
||||
* #### 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
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* Your custom renderer should expect an exception in its constructor, and implement a render method.
|
||||
* Failing to do so will cause additional errors.
|
||||
*
|
||||
* #### Logging exceptions
|
||||
*
|
||||
* Using the built-in exception handling, you can log all the exceptions
|
||||
* that are dealt with by ErrorHandler by setting `Exception.log` to true in your core.php.
|
||||
* Enabling this will log every exception to CakeLog and the configured loggers.
|
||||
*
|
||||
* ### 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
|
||||
* `Error.level` in your core.php.
|
||||
*
|
||||
* #### Logging errors
|
||||
*
|
||||
* When ErrorHandler is used for handling errors, you can enable error logging by setting `Error.log` to true.
|
||||
* This will log all errors to the configured log handlers.
|
||||
*
|
||||
* #### Controlling what errors are logged/displayed
|
||||
*
|
||||
* 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);`
|
||||
*
|
||||
* Would enable handling for all non Notice errors.
|
||||
*
|
||||
* @package Cake.Error
|
||||
* @see ExceptionRenderer for more information on how to customize exception rendering.
|
||||
*/
|
||||
class ErrorHandler {
|
||||
|
||||
/**
|
||||
* 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 The exception to render.
|
||||
* @return void
|
||||
* @see http://php.net/manual/en/function.set-exception-handler.php
|
||||
*/
|
||||
public static function handleException(Exception $exception) {
|
||||
$config = Configure::read('Exception');
|
||||
self::_log($exception, $config);
|
||||
|
||||
$renderer = isset($config['renderer']) ? $config['renderer'] : 'ExceptionRenderer';
|
||||
if ($renderer !== 'ExceptionRenderer') {
|
||||
list($plugin, $renderer) = pluginSplit($renderer, true);
|
||||
App::uses($renderer, $plugin . 'Error');
|
||||
}
|
||||
try {
|
||||
$error = new $renderer($exception);
|
||||
$error->render();
|
||||
} catch (Exception $e) {
|
||||
set_error_handler(Configure::read('Error.handler')); // Should be using configured ErrorHandler
|
||||
Configure::write('Error.trace', false); // trace is useless here since it's internal
|
||||
$message = sprintf("[%s] %s\n%s", // Keeping same message format
|
||||
get_class($e),
|
||||
$e->getMessage(),
|
||||
$e->getTraceAsString()
|
||||
);
|
||||
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_name() !== 'cli') {
|
||||
$request = Router::getRequest();
|
||||
if ($request) {
|
||||
$message .= "\nRequest URL: " . $request->here();
|
||||
}
|
||||
}
|
||||
$message .= "\nStack Trace:\n" . $exception->getTraceAsString();
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles exception logging
|
||||
*
|
||||
* @param Exception $exception The exception to render.
|
||||
* @param array $config An array of configuration for logging.
|
||||
* @return bool
|
||||
*/
|
||||
protected static function _log(Exception $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, self::_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
|
||||
* 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 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
|
||||
* @param array $context Context
|
||||
* @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);
|
||||
if ($log === LOG_ERR) {
|
||||
return self::handleFatalError($code, $description, $file, $line);
|
||||
}
|
||||
|
||||
$debug = Configure::read('debug');
|
||||
if ($debug) {
|
||||
$data = array(
|
||||
'level' => $log,
|
||||
'code' => $code,
|
||||
'error' => $error,
|
||||
'description' => $description,
|
||||
'file' => $file,
|
||||
'line' => $line,
|
||||
'context' => $context,
|
||||
'start' => 2,
|
||||
'path' => Debugger::trimPath($file)
|
||||
);
|
||||
return Debugger::getInstance()->outputError($data);
|
||||
}
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an error page when some fatal error happens.
|
||||
*
|
||||
* @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 bool
|
||||
*/
|
||||
public static function handleFatalError($code, $description, $file, $line) {
|
||||
$logMessage = 'Fatal Error (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
|
||||
CakeLog::write(LOG_ERR, $logMessage);
|
||||
|
||||
$exceptionHandler = Configure::read('Exception.handler');
|
||||
if (!is_callable($exceptionHandler)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ob_get_level()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
if (Configure::read('debug')) {
|
||||
call_user_func($exceptionHandler, new FatalErrorException($description, 500, $file, $line));
|
||||
} else {
|
||||
call_user_func($exceptionHandler, new InternalErrorException());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map an error code into an Error word, and log location.
|
||||
*
|
||||
* @param int $code Error code to map
|
||||
* @return array Array of error word, and log location.
|
||||
*/
|
||||
public static function mapErrorCode($code) {
|
||||
$error = $log = null;
|
||||
switch ($code) {
|
||||
case E_PARSE:
|
||||
case E_ERROR:
|
||||
case E_CORE_ERROR:
|
||||
case E_COMPILE_ERROR:
|
||||
case E_USER_ERROR:
|
||||
$error = 'Fatal Error';
|
||||
$log = LOG_ERR;
|
||||
break;
|
||||
case E_WARNING:
|
||||
case E_USER_WARNING:
|
||||
case E_COMPILE_WARNING:
|
||||
case E_RECOVERABLE_ERROR:
|
||||
$error = 'Warning';
|
||||
$log = LOG_WARNING;
|
||||
break;
|
||||
case E_NOTICE:
|
||||
case E_USER_NOTICE:
|
||||
$error = 'Notice';
|
||||
$log = LOG_NOTICE;
|
||||
break;
|
||||
case E_STRICT:
|
||||
$error = 'Strict';
|
||||
$log = LOG_NOTICE;
|
||||
break;
|
||||
case E_DEPRECATED:
|
||||
case E_USER_DEPRECATED:
|
||||
$error = 'Deprecated';
|
||||
$log = LOG_NOTICE;
|
||||
break;
|
||||
}
|
||||
return array($error, $log);
|
||||
}
|
||||
|
||||
}
|
319
lib/Cake/Error/ExceptionRenderer.php
Normal file
319
lib/Cake/Error/ExceptionRenderer.php
Normal file
|
@ -0,0 +1,319 @@
|
|||
<?php
|
||||
/**
|
||||
* Exception Renderer
|
||||
*
|
||||
* Provides Exception rendering features. Which allow exceptions to be rendered
|
||||
* as HTML pages.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (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 http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Sanitize', 'Utility');
|
||||
App::uses('Router', 'Routing');
|
||||
App::uses('CakeResponse', 'Network');
|
||||
App::uses('Controller', 'Controller');
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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 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.
|
||||
*
|
||||
* #### Using a subclass of ExceptionRenderer
|
||||
*
|
||||
* Using a subclass of ExceptionRenderer gives you full control over how Exceptions are rendered, you
|
||||
* can configure your class in your core.php, with `Configure::write('Exception.renderer', 'MyClass');`
|
||||
* You should place any custom exception renderers in `app/Lib/Error`.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class ExceptionRenderer {
|
||||
|
||||
/**
|
||||
* Controller instance.
|
||||
*
|
||||
* @var Controller
|
||||
*/
|
||||
public $controller = null;
|
||||
|
||||
/**
|
||||
* template to render for CakeException
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template = '';
|
||||
|
||||
/**
|
||||
* The method corresponding to the Exception this object is for.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $method = '';
|
||||
|
||||
/**
|
||||
* The exception being handled.
|
||||
*
|
||||
* @var Exception
|
||||
*/
|
||||
public $error = null;
|
||||
|
||||
/**
|
||||
* Creates the controller to perform rendering on the error response.
|
||||
* 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
|
||||
*/
|
||||
public function __construct(Exception $exception) {
|
||||
$this->controller = $this->_getController($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();
|
||||
|
||||
$methodExists = method_exists($this, $method);
|
||||
|
||||
if ($exception instanceof CakeException && !$methodExists) {
|
||||
$method = '_cakeError';
|
||||
if (empty($template) || $template === 'internalError') {
|
||||
$template = 'error500';
|
||||
}
|
||||
} elseif ($exception instanceof PDOException) {
|
||||
$method = 'pdoError';
|
||||
$template = 'pdo_error';
|
||||
$code = 500;
|
||||
} elseif (!$methodExists) {
|
||||
$method = 'error500';
|
||||
if ($code >= 400 && $code < 500) {
|
||||
$method = 'error400';
|
||||
}
|
||||
}
|
||||
|
||||
$isNotDebug = !Configure::read('debug');
|
||||
if ($isNotDebug && $method === '_cakeError') {
|
||||
$method = 'error400';
|
||||
}
|
||||
if ($isNotDebug && $code == 500) {
|
||||
$method = 'error500';
|
||||
}
|
||||
$this->template = $template;
|
||||
$this->method = $method;
|
||||
$this->error = $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the controller instance to handle the exception.
|
||||
* Override this method in subclasses to customize the controller used.
|
||||
* This method returns the built in `CakeErrorController` normally, or if an error is repeated
|
||||
* a bare controller will be used.
|
||||
*
|
||||
* @param Exception $exception The exception to get a controller for.
|
||||
* @return Controller
|
||||
*/
|
||||
protected function _getController($exception) {
|
||||
App::uses('AppController', 'Controller');
|
||||
App::uses('CakeErrorController', 'Controller');
|
||||
if (!$request = Router::getRequest(true)) {
|
||||
$request = new CakeRequest();
|
||||
}
|
||||
$response = new CakeResponse();
|
||||
|
||||
if (method_exists($exception, 'responseHeader')) {
|
||||
$response->header($exception->responseHeader());
|
||||
}
|
||||
|
||||
if (class_exists('AppController')) {
|
||||
try {
|
||||
$controller = new CakeErrorController($request, $response);
|
||||
$controller->startupProcess();
|
||||
} catch (Exception $e) {
|
||||
if (!empty($controller) && $controller->Components->enabled('RequestHandler')) {
|
||||
$controller->RequestHandler->startup($controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($controller)) {
|
||||
$controller = new Controller($request, $response);
|
||||
$controller->viewPath = 'Errors';
|
||||
}
|
||||
return $controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the response for the exception.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render() {
|
||||
if ($this->method) {
|
||||
call_user_func_array(array($this, $this->method), array($this->error));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic handler for the internal framework errors CakePHP can generate.
|
||||
*
|
||||
* @param CakeException $error The exception to render.
|
||||
* @return void
|
||||
*/
|
||||
protected function _cakeError(CakeException $error) {
|
||||
$url = $this->controller->request->here();
|
||||
$code = ($error->getCode() >= 400 && $error->getCode() < 506) ? $error->getCode() : 500;
|
||||
$this->controller->response->statusCode($code);
|
||||
$this->controller->set(array(
|
||||
'code' => $code,
|
||||
'name' => h($error->getMessage()),
|
||||
'message' => h($error->getMessage()),
|
||||
'url' => h($url),
|
||||
'error' => $error,
|
||||
'_serialize' => array('code', 'name', 'message', 'url')
|
||||
));
|
||||
$this->controller->set($error->getAttributes());
|
||||
$this->_outputMessage($this->template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to display a 400 series page.
|
||||
*
|
||||
* @param Exception $error The exception to render.
|
||||
* @return void
|
||||
*/
|
||||
public function error400($error) {
|
||||
$message = $error->getMessage();
|
||||
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' => h($message),
|
||||
'message' => h($message),
|
||||
'url' => h($url),
|
||||
'error' => $error,
|
||||
'_serialize' => array('name', 'message', 'url')
|
||||
));
|
||||
$this->_outputMessage('error400');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to display a 500 page.
|
||||
*
|
||||
* @param Exception $error The exception to render.
|
||||
* @return void
|
||||
*/
|
||||
public function error500($error) {
|
||||
$message = $error->getMessage();
|
||||
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' => h($message),
|
||||
'message' => h($message),
|
||||
'url' => h($url),
|
||||
'error' => $error,
|
||||
'_serialize' => array('name', 'message', 'url')
|
||||
));
|
||||
$this->_outputMessage('error500');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to display a PDOException.
|
||||
*
|
||||
* @param PDOException $error The exception to render.
|
||||
* @return void
|
||||
*/
|
||||
public function pdoError(PDOException $error) {
|
||||
$url = $this->controller->request->here();
|
||||
$code = 500;
|
||||
$this->controller->response->statusCode($code);
|
||||
$this->controller->set(array(
|
||||
'code' => $code,
|
||||
'name' => h($error->getMessage()),
|
||||
'message' => h($error->getMessage()),
|
||||
'url' => h($url),
|
||||
'error' => $error,
|
||||
'_serialize' => array('code', 'name', 'message', 'url', 'error')
|
||||
));
|
||||
$this->_outputMessage($this->template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the response using the controller object.
|
||||
*
|
||||
* @param string $template The template to render.
|
||||
* @return void
|
||||
*/
|
||||
protected function _outputMessage($template) {
|
||||
try {
|
||||
$this->controller->render($template);
|
||||
$this->controller->afterFilter();
|
||||
$this->controller->response->send();
|
||||
} catch (MissingViewException $e) {
|
||||
$attributes = $e->getAttributes();
|
||||
if (isset($attributes['file']) && strpos($attributes['file'], 'error500') !== false) {
|
||||
$this->_outputMessageSafe('error500');
|
||||
} 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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A safer way to render error messages, replaces all helpers, with basics
|
||||
* and doesn't call component methods.
|
||||
*
|
||||
* @param string $template The template to render
|
||||
* @return void
|
||||
*/
|
||||
protected function _outputMessageSafe($template) {
|
||||
$this->controller->layoutPath = null;
|
||||
$this->controller->subDir = null;
|
||||
$this->controller->viewPath = 'Errors';
|
||||
$this->controller->layout = 'error';
|
||||
$this->controller->helpers = array('Form', 'Html', 'Session');
|
||||
|
||||
$view = new View($this->controller);
|
||||
$this->controller->response->body($view->render($template, 'error'));
|
||||
$this->controller->response->type('html');
|
||||
$this->controller->response->send();
|
||||
}
|
||||
|
||||
}
|
628
lib/Cake/Error/exceptions.php
Normal file
628
lib/Cake/Error/exceptions.php
Normal file
|
@ -0,0 +1,628 @@
|
|||
<?php
|
||||
/**
|
||||
* Exceptions file. Contains the various exceptions CakePHP will throw until they are
|
||||
* moved into their permanent location.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (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 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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', false)) {
|
||||
class HttpException extends CakeBaseException {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an HTTP 400 error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class BadRequestException extends HttpException {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $message If no message is given 'Bad Request' will be the message
|
||||
* @param int $code Status code, defaults to 400
|
||||
*/
|
||||
public function __construct($message = null, $code = 400) {
|
||||
if (empty($message)) {
|
||||
$message = 'Bad Request';
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an HTTP 401 error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class UnauthorizedException extends HttpException {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $message If no message is given 'Unauthorized' will be the message
|
||||
* @param int $code Status code, defaults to 401
|
||||
*/
|
||||
public function __construct($message = null, $code = 401) {
|
||||
if (empty($message)) {
|
||||
$message = 'Unauthorized';
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an HTTP 403 error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class ForbiddenException extends HttpException {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $message If no message is given 'Forbidden' will be the message
|
||||
* @param int $code Status code, defaults to 403
|
||||
*/
|
||||
public function __construct($message = null, $code = 403) {
|
||||
if (empty($message)) {
|
||||
$message = 'Forbidden';
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an HTTP 404 error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class NotFoundException extends HttpException {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $message If no message is given 'Not Found' will be the message
|
||||
* @param int $code Status code, defaults to 404
|
||||
*/
|
||||
public function __construct($message = null, $code = 404) {
|
||||
if (empty($message)) {
|
||||
$message = 'Not Found';
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an HTTP 405 error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MethodNotAllowedException extends HttpException {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $message If no message is given 'Method Not Allowed' will be the message
|
||||
* @param int $code Status code, defaults to 405
|
||||
*/
|
||||
public function __construct($message = null, $code = 405) {
|
||||
if (empty($message)) {
|
||||
$message = 'Method Not Allowed';
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an HTTP 500 error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class InternalErrorException extends HttpException {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $message If no message is given 'Internal Server Error' will be the message
|
||||
* @param int $code Status code, defaults to 500
|
||||
*/
|
||||
public function __construct($message = null, $code = 500) {
|
||||
if (empty($message)) {
|
||||
$message = 'Internal Server Error';
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* CakeException is used a base class for CakePHP's internal exceptions.
|
||||
* In general framework errors are interpreted as 500 code errors.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class CakeException extends CakeBaseException {
|
||||
|
||||
/**
|
||||
* Array of attributes that are passed in from the constructor, and
|
||||
* made available in the view when a development error is displayed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_attributes = array();
|
||||
|
||||
/**
|
||||
* Template string that has attributes sprintf()'ed into it.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_messageTemplate = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Allows you to create exceptions that are treated as framework errors and disabled
|
||||
* when debug = 0.
|
||||
*
|
||||
* @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 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)) {
|
||||
$this->_attributes = $message;
|
||||
$message = __d('cake_dev', $this->_messageTemplate, $message);
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the passed in attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes() {
|
||||
return $this->_attributes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Missing Controller exception - used when a controller
|
||||
* cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingControllerException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Controller class %s could not be found.';
|
||||
|
||||
//@codingStandardsIgnoreStart
|
||||
public function __construct($message, $code = 404) {
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
//@codingStandardsIgnoreEnd
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Missing Action exception - used when a controller action
|
||||
* cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingActionException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Action %s::%s() could not be found.';
|
||||
|
||||
//@codingStandardsIgnoreStart
|
||||
public function __construct($message, $code = 404) {
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
//@codingStandardsIgnoreEnd
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Private Action exception - used when a controller action
|
||||
* starts with a `_`.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class PrivateActionException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.';
|
||||
|
||||
//@codingStandardsIgnoreStart
|
||||
public function __construct($message, $code = 404, Exception $previous = null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
//@codingStandardsIgnoreEnd
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a component cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingComponentException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Component class %s could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a behavior cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingBehaviorException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Behavior class %s could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a view file cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingViewException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'View file "%s" is missing.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a layout file cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingLayoutException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Layout file "%s" is missing.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a helper cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingHelperException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Helper class %s could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime Exceptions for ConnectionManager
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingDatabaseException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Database connection "%s" could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when no connections can be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
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);
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a Task cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingTaskException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Task class %s could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a shell method cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingShellMethodException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = "Unknown command %1\$s %2\$s.\nFor usage try `cake %1\$s --help`";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a shell cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingShellException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Shell class %s could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class to be thrown when a datasource configuration is not found
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingDatasourceConfigException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'The datasource configuration "%s" was not found in database.php';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a datasource cannot be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingDatasourceException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Datasource class %s could not be found. %s';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class to be thrown when a database table is not found in the datasource
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingTableException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Table %s for model %s was not found in datasource %s.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception raised when a Model could not be found.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingModelException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Model %s could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception raised when a test loader could not be found
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingTestLoaderException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Test loader %s could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception raised when a plugin could not be found
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingPluginException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Plugin %s could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception raised when a Dispatcher filter could not be found
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class MissingDispatcherFilterException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = 'Dispatcher filter %s could not be found.';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for AclComponent and Interface implementations.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class AclException extends CakeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for Cache. This exception will be thrown from Cache when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class CacheException extends CakeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for Router. This exception will be thrown from Router when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class RouterException extends CakeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for CakeLog. This exception will be thrown from CakeLog when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class CakeLogException extends CakeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for CakeSession. This exception will be thrown from CakeSession when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class CakeSessionException extends CakeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for Configure. This exception will be thrown from Configure when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class ConfigureException extends CakeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for Socket. This exception will be thrown from CakeSocket, CakeEmail, HttpSocket
|
||||
* SmtpTransport, MailTransport and HttpResponse when it encounters an error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class SocketException extends CakeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for Xml. This exception will be thrown from Xml when it
|
||||
* encounters an error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class XmlException extends CakeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for Console libraries. This exception will be thrown from Console library
|
||||
* classes when they encounter an error.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class ConsoleException extends CakeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a fatal error
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class FatalErrorException extends CakeException {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @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);
|
||||
if ($file) {
|
||||
$this->file = $file;
|
||||
}
|
||||
if ($line) {
|
||||
$this->line = $line;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Implemented Exception - used when an API method is not implemented
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
class NotImplementedException extends CakeException {
|
||||
|
||||
protected $_messageTemplate = '%s is not implemented.';
|
||||
|
||||
//@codingStandardsIgnoreStart
|
||||
public function __construct($message, $code = 501) {
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
//@codingStandardsIgnoreEnd
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue