1 | <?php |
||
19 | trait LoggableTrait |
||
20 | { |
||
21 | |||
22 | private static $_dispatcher; |
||
23 | |||
24 | /** |
||
25 | * @inheritdoc |
||
26 | */ |
||
27 | public function isDebugModeEnabled() |
||
31 | |||
32 | /** |
||
33 | * @return Logger |
||
34 | */ |
||
35 | public static function getLogger() |
||
39 | |||
40 | /** |
||
41 | * Sets the logger object. |
||
42 | * @param Logger $logger the logger object. |
||
43 | */ |
||
44 | public static function setLogger($logger) |
||
48 | |||
49 | /** |
||
50 | * @return Dispatcher |
||
51 | */ |
||
52 | public static function getDispatcher() |
||
61 | |||
62 | /** |
||
63 | * @param array $dispatcher |
||
64 | * @throws \yii\base\InvalidConfigException |
||
65 | */ |
||
66 | public static function setDispatcher($dispatcher = []) |
||
78 | |||
79 | /** |
||
80 | * Logs a trace message. |
||
81 | * Trace messages are logged mainly for development purpose to see |
||
82 | * the execution work flow of some code. |
||
83 | * @param string $message the message to be logged. |
||
84 | * @param string $category the category of the message. |
||
85 | */ |
||
86 | public static function trace($message, $category = 'module') |
||
90 | |||
91 | /** |
||
92 | * Logs an error message. |
||
93 | * An error message is typically logged when an unrecoverable error occurs |
||
94 | * during the execution of an application. |
||
95 | * @param string $message the message to be logged. |
||
96 | * @param string $category the category of the message. |
||
97 | */ |
||
98 | public static function error($message, $category = 'module') |
||
102 | |||
103 | /** |
||
104 | * Logs a warning message. |
||
105 | * A warning message is typically logged when an error occurs while the execution |
||
106 | * can still continue. |
||
107 | * @param string $message the message to be logged. |
||
108 | * @param string $category the category of the message. |
||
109 | */ |
||
110 | public static function warning($message, $category = 'module') |
||
114 | |||
115 | /** |
||
116 | * Logs an informative message. |
||
117 | * An informative message is typically logged by an application to keep record of |
||
118 | * something important (e.g. an administrator logs in). |
||
119 | * @param string $message the message to be logged. |
||
120 | * @param string $category the category of the message. |
||
121 | */ |
||
122 | public static function info($message, $category = 'module') |
||
126 | |||
127 | } |
||
128 |
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: