AbstractException.php 3.22 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/29/16
 * Time: 8:03 AM
 */

namespace qfq;

11
require_once(__DIR__ . '/../../qfq/store/Store.php');
12
require_once(__DIR__ . '/UserFormException.php');
13
require_once(__DIR__ . '/../Constants.php');
14

15
16
17
18
19
20

class AbstractException extends \Exception {

    public $messageArray = array();
    public $store;

21
22
23
    protected $file = '';
    protected $line = '';

24

25

26
27
28
29
    /**
     * @return string
     */
    public function formatException() {
30
        $debug = '';
31
32
33
34
35
36
37
        try {
            // In a very early stage, it might be possible that Store can't be initialized: take care not to use it.
            $store = Store::getInstance();
        } catch (UserFormException $e) {
            $store = null;
        }

38
        $html = '';
39

40
        $this->messageArray['File'] = $this->getFile();
41
        $this->messageArray['Line'] = $this->getLine();
42
43
        $this->messageArray['Message'] = $this->getMessage();
        $this->messageArray['Code'] = $this->getCode();
44

45
        $this->messageArray['Stacktrace'] = '<pre>' . $this->getTraceAsString() . '</pre>';
46
47
48
49
        if ($store !== null) {
            $this->messageArray['Page Id'] = $store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
            $this->messageArray['Content Id'] = $store->getVar(TYPO3_TT_CONTENT_UID, STORE_TYPO3);
        }
50

51
52
53
        $html .= "Code: " . $this->messageArray['Code'] . "<br>";
        $html .= "Message: " . Support::wrapTag("<strong>", $this->messageArray['Message']) . "</br>";

54
        // Form
55
56
57
58
59
60
61
62
        if (isset($this->messageArray['Form'])) {
            $html .= "Form: " . Support::wrapTag("<strong>", $this->messageArray['Form']) . "</br>";
        }

        if (isset($this->messageArray['Form Element'])) {
            $html .= "Form Element: " . Support::wrapTag("<strong>", $this->messageArray['Form Element']) . "</br>";
        }

63
64
65
66
67
68
69
70
71
72
73
74
75
        // Report
        if (isset($this->messageArray[SYSTEM_REPORT_COLUMN_INDEX])) {
            $html .= "Column index: " . Support::wrapTag("<strong>", $this->messageArray[SYSTEM_REPORT_COLUMN_INDEX]) . "</br>";
        }

        if (isset($this->messageArray[SYSTEM_REPORT_COLUMN_NAME])) {
            $html .= "Column name: " . Support::wrapTag("<strong>", $this->messageArray[SYSTEM_REPORT_COLUMN_NAME]) . "</br>";
        }

        if (isset($this->messageArray[SYSTEM_REPORT_COLUMN_VALUE])) {
            $html .= "Column value: " . Support::wrapTag("<strong>", $this->messageArray[SYSTEM_REPORT_COLUMN_VALUE]) . "</br>";
        }

76
77
        $html = "<h2>Error</h2>" . Support::wrapTag('<p>', $html);
        $html = Support::wrapTag("<div class='warning'>", $html);
78

79
        if ($store !== null && $store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes') {
80
81
82
83
84
85
86
87
88
89

            // Layout
            $debug = '<tr bgcolor="#dddddd"><td colspan="2">Exception</td></tr>';
            foreach ($this->messageArray as $key => $value) {
                if (is_array($value)) {
                    $value = var_export($value, true);
                }

                if ($value !== '' && $value !== false)
                    $debug .= "<tr>" . "<td>$key</td>" . "<td>$value</td>" . "</tr>";
90
            }
91
            $debug = "<table border=1>" . $debug . "</table>";
92
        }
93
        return $html . $debug;
94
95
96
    }

}