| 151 | | if($this->_templatePath===null) |
|---|
| 152 | | $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates'; |
|---|
| 153 | | $base=$this->_templatePath.'/'.self::ERROR_FILE_NAME; |
|---|
| 154 | | $lang=Prado::getPreferredLanguage(); |
|---|
| 155 | | if(is_file("$base$statusCode-$lang.html")) |
|---|
| 156 | | $errorFile="$base$statusCode-$lang.html"; |
|---|
| 157 | | else if(is_file("$base$statusCode.html")) |
|---|
| 158 | | $errorFile="$base$statusCode.html"; |
|---|
| 159 | | else if(is_file("$base-$lang.html")) |
|---|
| 160 | | $errorFile="$base-$lang.html"; |
|---|
| 161 | | else |
|---|
| 162 | | $errorFile="$base.html"; |
|---|
| 163 | | if(($content=@file_get_contents($errorFile))===false) |
|---|
| 164 | | die("Unable to open error template file '$errorFile'."); |
|---|
| | 153 | |
|---|
| | 154 | $content=$this->getErrorTemplate($statusCode,$exception); |
|---|
| | 239 | |
|---|
| | 240 | $content=$this->getExceptionTemplate($exception); |
|---|
| | 241 | |
|---|
| | 242 | echo strtr($content,$tokens); |
|---|
| | 243 | } |
|---|
| | 244 | |
|---|
| | 245 | /** |
|---|
| | 246 | * Retrieves the template used for displaying internal exceptions. |
|---|
| | 247 | * Internal exceptions will be displayed with source code causing the exception. |
|---|
| | 248 | * This occurs when the application is in debug mode. |
|---|
| | 249 | * @param Exception the exception to be displayed |
|---|
| | 250 | * @return string the template content |
|---|
| | 251 | */ |
|---|
| | 252 | protected function getExceptionTemplate($exception) |
|---|
| | 253 | { |
|---|
| 255 | | echo strtr($content,$tokens); |
|---|
| | 260 | return $content; |
|---|
| | 261 | } |
|---|
| | 262 | |
|---|
| | 263 | /** |
|---|
| | 264 | * Retrieves the template used for displaying external exceptions. |
|---|
| | 265 | * External exceptions are those displayed to end-users. They do not contain |
|---|
| | 266 | * error source code. Therefore, you might want to override this method |
|---|
| | 267 | * to provide your own error template for displaying certain external exceptions. |
|---|
| | 268 | * The following tokens in the template will be replaced with corresponding content: |
|---|
| | 269 | * %%StatusCode%% : the status code of the exception |
|---|
| | 270 | * %%ErrorMessage%% : the error message (HTML encoded). |
|---|
| | 271 | * %%ServerAdmin%% : the server admin information (retrieved from Web server configuration) |
|---|
| | 272 | * %%Version%% : the version information of the Web server. |
|---|
| | 273 | * %%Time%% : the time the exception occurs at |
|---|
| | 274 | * |
|---|
| | 275 | * @param integer status code (such as 404, 500, etc.) |
|---|
| | 276 | * @param Exception the exception to be displayed |
|---|
| | 277 | * @return string the template content |
|---|
| | 278 | */ |
|---|
| | 279 | protected function getErrorTemplate($statusCode,$exception) |
|---|
| | 280 | { |
|---|
| | 281 | $base=$this->getErrorTemplatePath().'/'.self::ERROR_FILE_NAME; |
|---|
| | 282 | $lang=Prado::getPreferredLanguage(); |
|---|
| | 283 | if(is_file("$base$statusCode-$lang.html")) |
|---|
| | 284 | $errorFile="$base$statusCode-$lang.html"; |
|---|
| | 285 | else if(is_file("$base$statusCode.html")) |
|---|
| | 286 | $errorFile="$base$statusCode.html"; |
|---|
| | 287 | else if(is_file("$base-$lang.html")) |
|---|
| | 288 | $errorFile="$base-$lang.html"; |
|---|
| | 289 | else |
|---|
| | 290 | $errorFile="$base.html"; |
|---|
| | 291 | if(($content=@file_get_contents($errorFile))===false) |
|---|
| | 292 | die("Unable to open error template file '$errorFile'."); |
|---|
| | 293 | return $content; |
|---|