View Source
/hsphere/local/home/c251266/sunsetvines.com/www.sunsetvines.com/sunsetvines/current/vendor/creovel/classes/error.php (2.794 KB)
#0001
#0002
#0003
#0004
#0005
#0006
#0007
#0008
#0009
#0010
#0011
#0012
#0013
#0014
#0015
#0016
#0017
#0018
#0019
#0020
#0021
#0022
#0023
#0024
#0025
#0026
#0027
#0028
#0029
#0030
#0031
#0032
#0033
#0034
#0035
#0036
#0037
#0038
#0039
#0040
#0041
#0042
#0043
#0044
#0045
#0046
#0047
#0048
#0049
#0050
#0051
#0052
#0053
#0054
#0055
#0056
#0057
#0058
#0059
#0060
#0061
#0062
#0063
#0064
#0065
#0066
#0067
#0068
#0069
#0070
#0071
#0072
#0073
#0074
#0075
#0076
#0077
#0078
#0079
#0080
#0081
#0082
#0083
#0084
#0085
#0086
#0087
#0088
#0089
#0090
#0091
#0092
#0093
#0094
#0095
#0096
#0097
#0098
#0099
#0100
#0101
#0102
#0103
#0104
#0105
#0106
#0107
#0108
#0109
#0110
#0111
#0112
#0113
#0114
#0115
#0116
#0117
#0118
#0119
#0120
#0121
#0122
#0123
#0124
#0125
#0126
#0127
#0128
#0129
#0130
#0131
#0132
#0133
#0134
#0135
#0136
#0137
#0138
#0139
#0140
#0141
#0142
#0143
#0144
#0145
#0146
#0147
#0148
#0149
#0150
#0151
#0152
|
<?php /* * Error class. * */ class error {
/** * Error type * * @author Nesbert Hidalgo * @access private * @var string */ private $type;
/** * Error count * * @author Nesbert Hidalgo * @access private * @var string */ private $error_count = 0;
/** * Set error type in construct * * @author Nesbert Hidalgo * @access public * @param string $type applicaiton, model */ public function __construct($type) { $this->type = $type; } /** * Add errors to object * * @author Nesbert Hidalgo * @access public * @param string $args[0] message if application error and field name if model error * @param object|string $args[1] exception oject if application error and message if model error */ public function add() { $this->error_count++; $args = func_get_args(); switch ( $this->type ) { case 'application': $this->application_error($args[0], $args[1]); break; default: $this->model_error($args[0], $args[1]); break; } } /** * Returns bool value for errors * * @author Nesbert Hidalgo * @access public * @return bool */ public function has_errors() { return $this->error_count ? true : false; } /** * Returns $error_count * * @author Nesbert Hidalgo * @access public * @return int */ public function count() { return $this->error_count; } /** * Display application errors to user * * @author Nesbert Hidalgo * @access public * @param string $message required * @param object $exception optional */ private function application_error($message, $exception = null) { // check whether or not to show debugging errors $this->handle_error(); // clean output buffer for application errors @ob_end_clean(); $this->message = $message; if ( is_object($exception) ) $this->traces = $exception->getTrace(); if ( isset($_GET['view_source']) ) { view::_show_view(CREOVEL_PATH.'views'.DS.'view_source.php', CREOVEL_PATH.'views'.DS.'layouts'.DS.'creovel.php'); } else { view::_show_view(CREOVEL_PATH.'views'.DS.'application_error.php', CREOVEL_PATH.'views'.DS.'layouts'.DS.'creovel.php'); } die; } /** * Handle how to display errors to the user. If in dvelopment mode * show debugging information else redirect to error page * * @author Nesbert Hidalgo * @access private * @return bool */ private function handle_error() { if ( $_ENV['mode'] !== 'development' ) { die('redirect 500 page!'); } else { return true; } } /** * Create a property for each error * * @author Nesbert Hidalgo * @access private * @param string $field required * @param object $message required */ private function model_error($field, $message) { $this->$field = $message; // add to globals $_ENV['model_error'][$field] = $message; } } ?>
|