|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the O2System Framework package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Steeve Andrian Salim |
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
|
13
|
|
|
|
|
14
|
|
|
namespace O2System\Gear; |
|
15
|
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* O2System Gear Trace |
|
20
|
|
|
* |
|
21
|
|
|
* @package O2System\Gear |
|
22
|
|
|
*/ |
|
23
|
|
|
class Trace |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Trace::$backtrace |
|
27
|
|
|
* |
|
28
|
|
|
* @type string name of called class |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $backtrace = null; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Trace::$chronology |
|
34
|
|
|
* |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $chronology = []; |
|
38
|
|
|
|
|
39
|
|
|
// ------------------------------------------------------------------------ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Trace::__construct |
|
43
|
|
|
* |
|
44
|
|
|
* @param array $trace |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct($trace = []) |
|
47
|
|
|
{ |
|
48
|
|
|
if ( ! empty($trace)) { |
|
49
|
|
|
$this->backtrace = $trace; |
|
|
|
|
|
|
50
|
|
|
} else { |
|
51
|
|
|
$this->backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// reverse array to make steps line up chronologically |
|
55
|
|
|
$this->backtrace = array_reverse($this->backtrace); |
|
56
|
|
|
|
|
57
|
|
|
// Generate Lines |
|
58
|
|
|
$this->setChronology(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// ------------------------------------------------------------------------ |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Trace::setChronology |
|
65
|
|
|
* |
|
66
|
|
|
* Generate Chronology Method |
|
67
|
|
|
* |
|
68
|
|
|
* Generate array of Backtrace Chronology |
|
69
|
|
|
* |
|
70
|
|
|
* @access private |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
private function setChronology() |
|
74
|
|
|
{ |
|
75
|
|
|
foreach ($this->backtrace as $trace) { |
|
|
|
|
|
|
76
|
|
|
$line = new Trace\DataStructures\Chronology($trace); |
|
77
|
|
|
|
|
78
|
|
|
if (isset($trace[ 'class' ]) AND isset($trace[ 'type' ])) { |
|
79
|
|
|
$line->call = $trace[ 'class' ] . $trace[ 'type' ] . $trace[ 'function' ] . '()'; |
|
|
|
|
|
|
80
|
|
|
$line->type = $trace[ 'type' ] === '->' ? 'non-static' : 'static'; |
|
|
|
|
|
|
81
|
|
|
} else { |
|
82
|
|
|
$line->call = $trace[ 'function' ] . '()'; |
|
83
|
|
|
$line->type = 'non-static'; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if ( ! isset($trace[ 'file' ])) { |
|
87
|
|
|
$currentTrace = current($this->backtrace); |
|
|
|
|
|
|
88
|
|
|
$line->file = isset($currentTrace[ 'file' ]) ? $currentTrace[ 'file' ] : null; |
|
|
|
|
|
|
89
|
|
|
$line->line = isset($currentTrace[ 'line' ]) ? $currentTrace[ 'line' ] : null; |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (defined('PATH_ROOT')) { |
|
93
|
|
|
$line->file = str_replace(PATH_ROOT, '', $line->file); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$this->chronology[] = $line; |
|
97
|
|
|
|
|
98
|
|
|
if (in_array($line->call, ['print_out()', 'print_line()', 'O2System\Core\Gear\Debug::stop()'])) { |
|
99
|
|
|
break; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
// ------------------------------------------------------------------------ |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Trace::getChronology |
|
108
|
|
|
* |
|
109
|
|
|
* @param bool $reset |
|
110
|
|
|
* |
|
111
|
|
|
* @return array |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getChronology($reset = true) |
|
114
|
|
|
{ |
|
115
|
|
|
$chronology = $this->chronology; |
|
116
|
|
|
|
|
117
|
|
|
if ($reset === true) { |
|
118
|
|
|
$this->chronology = []; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $chronology; |
|
122
|
|
|
} |
|
123
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..