mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-01-16 21:08:34 +01:00
Add support for PSR-3 message placeholders (#465)
This commit is contained in:
parent
150ef8d8a3
commit
7602079356
@ -185,7 +185,29 @@ class MessagesCollector extends AbstractLogger implements DataCollectorInterface
|
||||
*/
|
||||
public function log($level, $message, array $context = array())
|
||||
{
|
||||
$this->addMessage($message, $level);
|
||||
$this->addMessage($this->interpolate($message, $context), $level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpolates context values into the message placeholders.
|
||||
*
|
||||
* @param $message
|
||||
* @param array $context
|
||||
* @return string
|
||||
*/
|
||||
function interpolate($message, array $context = array())
|
||||
{
|
||||
// build a replacement array with braces around the context keys
|
||||
$replace = array();
|
||||
foreach ($context as $key => $val) {
|
||||
// check that the value can be cast to string
|
||||
if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
|
||||
$replace['{' . $key . '}'] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// interpolate replacement values into the message and return
|
||||
return strtr($message, $replace);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user