1 | <?php |
||
20 | trait LoggableTrait |
||
21 | { |
||
22 | |||
23 | private static $dispatcher; |
||
24 | |||
25 | /** |
||
26 | * @inheritdoc |
||
27 | */ |
||
28 | public function isDebugModeEnabled() |
||
32 | |||
33 | /** |
||
34 | * @return Logger |
||
35 | */ |
||
36 | public static function getLogger() |
||
40 | |||
41 | /** |
||
42 | * Sets the logger object. |
||
43 | * @param Logger $logger the logger object. |
||
44 | */ |
||
45 | public static function setLogger($logger) |
||
49 | |||
50 | /** |
||
51 | * @return Dispatcher |
||
52 | */ |
||
53 | public static function getDispatcher() |
||
62 | |||
63 | /** |
||
64 | * @param array $dispatcher |
||
65 | * @throws \yii\base\InvalidConfigException |
||
66 | */ |
||
67 | public static function setDispatcher($dispatcher = []) |
||
81 | |||
82 | /** |
||
83 | * Logs a trace message. |
||
84 | * Trace messages are logged mainly for development purpose to see |
||
85 | * the execution work flow of some code. |
||
86 | * @param string $message the message to be logged. |
||
87 | * @param string $category the category of the message. |
||
88 | */ |
||
89 | public static function trace($message, $category = 'module') |
||
93 | |||
94 | /** |
||
95 | * Logs an error message. |
||
96 | * An error message is typically logged when an unrecoverable error occurs |
||
97 | * during the execution of an application. |
||
98 | * @param string $message the message to be logged. |
||
99 | * @param string $category the category of the message. |
||
100 | */ |
||
101 | public static function error($message, $category = 'module') |
||
105 | |||
106 | /** |
||
107 | * Logs a warning message. |
||
108 | * A warning message is typically logged when an error occurs while the execution |
||
109 | * can still continue. |
||
110 | * @param string $message the message to be logged. |
||
111 | * @param string $category the category of the message. |
||
112 | */ |
||
113 | public static function warning($message, $category = 'module') |
||
117 | |||
118 | /** |
||
119 | * Logs an informative message. |
||
120 | * An informative message is typically logged by an application to keep record of |
||
121 | * something important (e.g. an administrator logs in). |
||
122 | * @param string $message the message to be logged. |
||
123 | * @param string $category the category of the message. |
||
124 | */ |
||
125 | public static function info($message, $category = 'module') |
||
129 | } |
||
130 |
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: