File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
src/DebugBar/DataCollector Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -185,7 +185,29 @@ public function getMessages()
185
185
*/
186
186
public function log ($ level , $ message , array $ context = array ())
187
187
{
188
- $ this ->addMessage ($ message , $ level );
188
+ $ this ->addMessage ($ this ->interpolate ($ message , $ context ), $ level );
189
+ }
190
+
191
+ /**
192
+ * Interpolates context values into the message placeholders.
193
+ *
194
+ * @param $message
195
+ * @param array $context
196
+ * @return string
197
+ */
198
+ function interpolate ($ message , array $ context = array ())
199
+ {
200
+ // build a replacement array with braces around the context keys
201
+ $ replace = array ();
202
+ foreach ($ context as $ key => $ val ) {
203
+ // check that the value can be cast to string
204
+ if (!is_array ($ val ) && (!is_object ($ val ) || method_exists ($ val , '__toString ' ))) {
205
+ $ replace ['{ ' . $ key . '} ' ] = $ val ;
206
+ }
207
+ }
208
+
209
+ // interpolate replacement values into the message and return
210
+ return strtr ($ message , $ replace );
189
211
}
190
212
191
213
/**
You can’t perform that action at this time.
0 commit comments