Completed
Push — master ( 4546ab...42948b )
by Mihail
04:43
created

TemplateException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B display() 0 22 5
1
<?php
2
3
namespace Ffcms\Core\Exception;
4
5
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\Controller;
8
9
abstract class TemplateException extends \Exception
10
{
11
    public $status = 404;
12
    public $title = '404 Not Found';
13
    public $text = 'An unexpected error occurred: %e%';
14
    public $tpl = 'default';
15
16
    public function display()
17
    {
18
        $this->text = App::$Translate->get('Default', $this->text, ['e' => $this->getMessage()]);
19
20
        if (App::$Debug !== null) {
21
            App::$Debug->addException($this);
22
        }
23
24
        $fakeController = new Controller();
25
        if (defined('env_no_layout') && env_no_layout === true) {
26
            $fakeController->layout = null;
27
        }
28
29
        $fakeController->setGlobalVar('title', App::$Translate->get('Default', $this->title));
30
        try {
31
            $fakeController->response = App::$View->render('errors/' . $this->tpl, ['msg' => $this->text]);
32
        } catch (SyntaxException $e) {
33
            $fakeController->response = $this->text;
34
        }
35
36
        App::$Response->setStatusCode((int)$this->status);
37
    }
38
39
}