1 | <?php |
||
16 | class LogParser |
||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Constants |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | const REGEX_DATE_PATTERN = '\d{4}(-\d{2}){2}'; |
||
24 | const REGEX_TIME_PATTERN = '\d{2}(:\d{2}){2}'; |
||
25 | const REGEX_DATETIME_PATTERN = self::REGEX_DATE_PATTERN.' '.self::REGEX_TIME_PATTERN; |
||
26 | |||
27 | /* ----------------------------------------------------------------- |
||
28 | | Properties |
||
29 | | ----------------------------------------------------------------- |
||
30 | */ |
||
31 | |||
32 | /** |
||
33 | * Parsed data. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected static $parsed = []; |
||
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Main Methods |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Parse file content. |
||
46 | * |
||
47 | * @param string $raw |
||
48 | * |
||
49 | * @return array |
||
50 | */ |
||
51 | 378 | public static function parse($raw) |
|
72 | |||
73 | /* ----------------------------------------------------------------- |
||
74 | | Other Methods |
||
75 | | ----------------------------------------------------------------- |
||
76 | */ |
||
77 | |||
78 | /** |
||
79 | * Extract the date. |
||
80 | * |
||
81 | * @param string $string |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | 390 | public static function extractDate(string $string): string |
|
89 | |||
90 | /** |
||
91 | * Parse raw data. |
||
92 | * |
||
93 | * @param string $raw |
||
94 | * |
||
95 | * @return array |
||
96 | */ |
||
97 | 378 | private static function parseRawData($raw) |
|
110 | |||
111 | /** |
||
112 | * Populate entries. |
||
113 | * |
||
114 | * @param array $heading |
||
115 | * @param array $data |
||
116 | * @param int $key |
||
117 | */ |
||
118 | 378 | private static function populateEntries($heading, $data, $key) |
|
130 | |||
131 | /** |
||
132 | * Check if header has a log level. |
||
133 | * |
||
134 | * @param string $heading |
||
135 | * @param string $level |
||
136 | * |
||
137 | * @return bool |
||
138 | */ |
||
139 | 378 | private static function hasLogLevel($heading, $level) |
|
143 | } |
||
144 |
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: