1 | <?php |
||
15 | class LogParser |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Constants |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | const REGEX_DATE_PATTERN = '\d{4}(-\d{2}){2}'; |
||
23 | const REGEX_TIME_PATTERN = '\d{2}(:\d{2}){2}'; |
||
24 | const REGEX_DATETIME_PATTERN = self::REGEX_DATE_PATTERN.' '.self::REGEX_TIME_PATTERN; |
||
25 | |||
26 | /* ----------------------------------------------------------------- |
||
27 | | Properties |
||
28 | | ----------------------------------------------------------------- |
||
29 | */ |
||
30 | |||
31 | /** |
||
32 | * Parsed data. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected static $parsed = []; |
||
37 | |||
38 | /* ----------------------------------------------------------------- |
||
39 | | Main Methods |
||
40 | | ----------------------------------------------------------------- |
||
41 | */ |
||
42 | |||
43 | /** |
||
44 | * Parse file content. |
||
45 | * |
||
46 | * @param string $raw |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | 378 | public static function parse($raw) |
|
71 | |||
72 | /* ----------------------------------------------------------------- |
||
73 | | Other Methods |
||
74 | | ----------------------------------------------------------------- |
||
75 | */ |
||
76 | |||
77 | /** |
||
78 | * Extract the date. |
||
79 | * |
||
80 | * @param string $string |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 390 | public static function extractDate(string $string): string |
|
88 | |||
89 | /** |
||
90 | * Parse raw data. |
||
91 | * |
||
92 | * @param string $raw |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | 378 | private static function parseRawData($raw) |
|
109 | |||
110 | /** |
||
111 | * Populate entries. |
||
112 | * |
||
113 | * @param array $heading |
||
114 | * @param array $data |
||
115 | * @param int $key |
||
116 | */ |
||
117 | 378 | private static function populateEntries($heading, $data, $key) |
|
118 | { |
||
119 | 378 | foreach (LogLevels::all() as $level) { |
|
120 | 378 | if (static::hasLogLevel($heading[$key], $level)) { |
|
121 | static::$parsed[] = [ |
||
122 | 378 | 'level' => $level, |
|
123 | 378 | 'header' => $heading[$key], |
|
124 | 378 | 'stack' => $data[$key] |
|
125 | ]; |
||
126 | } |
||
127 | } |
||
128 | 378 | } |
|
129 | |||
130 | /** |
||
131 | * Check if header has a log level. |
||
132 | * |
||
133 | * @param string $heading |
||
134 | * @param string $level |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | 378 | private static function hasLogLevel($heading, $level) |
|
142 | } |
||
143 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: