1 | <?php |
||
32 | class LogMessage implements LogMessageInterface |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * Initializes the message with the necessary information. |
||
37 | * |
||
38 | * @param string $id The unique-ID of the log message |
||
39 | * @param string $level The log level |
||
40 | * @param string $message The message to be logged |
||
41 | * @param array $context The message context |
||
42 | */ |
||
43 | 8 | public function __construct($id, $level, $message, array $context = array()) |
|
50 | |||
51 | /** |
||
52 | * Returns the unique-ID of the log message. |
||
53 | * |
||
54 | * @return string The unique-ID |
||
55 | */ |
||
56 | public function getId() |
||
60 | |||
61 | /** |
||
62 | * Returns the log level. |
||
63 | * |
||
64 | * @return string The log level |
||
65 | * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel |
||
66 | */ |
||
67 | 6 | public function getLevel() |
|
71 | |||
72 | /** |
||
73 | * Returns the message we want to log. |
||
74 | * |
||
75 | * @return string The message to be logged |
||
76 | * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#12-message |
||
77 | */ |
||
78 | 6 | public function getMessage() |
|
82 | |||
83 | /** |
||
84 | * Returns the context we're logging. |
||
85 | * |
||
86 | * @return array The log context |
||
87 | * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#13-context |
||
88 | */ |
||
89 | 6 | public function getContext() |
|
93 | |||
94 | /** |
||
95 | * Sets the context we want to log. |
||
96 | * |
||
97 | * @param array $context The log context |
||
98 | * |
||
99 | * @return void |
||
100 | * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#13-context |
||
101 | */ |
||
102 | public function setContext(array $context) |
||
106 | |||
107 | /** |
||
108 | * Merges the values of the passed array into the context. |
||
109 | * |
||
110 | * @param array $toMerge The array with the data to merge |
||
111 | * |
||
112 | * @return void |
||
113 | * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#13-context |
||
114 | */ |
||
115 | public function mergeIntoContext(array $toMerge) |
||
119 | |||
120 | /** |
||
121 | * Appends the passed key/value pair to the context. |
||
122 | * |
||
123 | * @param string $key The key to merge the value with |
||
124 | * @param mixed $value The value to merge |
||
125 | * |
||
126 | * @return void |
||
127 | * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#13-context |
||
128 | */ |
||
129 | public function appendToContext($key, $value) |
||
133 | } |
||
134 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: