8000 [Console] Sync ConsoleLogger::interpolate with the one in HttpKernel by dunglas · Pull Request #24527 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Sync ConsoleLogger::interpolate with the one in HttpKernel #24527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/Symfony/Component/Console/Logger/ConsoleLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,23 @@ public function hasErrored()
*/
private function interpolate($message, array $context)
{
// build a replacement array with braces around the context keys
$replace = array();
if (false === strpos($message, '{')) {
return $message;
}

$replacements = array();
foreach ($context as $key => $val) {
if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
$replace[sprintf('{%s}', $key)] = $val;
if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) {
$replacements["{{$key}}"] = $val;
} elseif ($val instanceof \DateTimeInterface) {
$replacements["{{$key}}"] = $val->format(\DateTime::RFC3339);
} elseif (\is_object($val)) {
$replacements["{{$key}}"] = '[object '.\get_class($val).']';
} else {
$replacements["{{$key}}"] = '['.\gettype($val).']';
}
}

// interpolate replacement values into the message and return
return strtr($message, $replace);
return strtr($message, $replacements);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ public function testObjectCastToString()
} else {
$dummy = $this->getMock('Symfony\Component\Console\Tests\Logger\DummyTest', array('__toString'));
}
$dummy->expects($this->once())
->method('__toString')
->will($this->returnValue('DUMMY'));
$dummy->method('__toString')->will($this->returnValue('DUMMY'));

$this->getLogger()->warning($dummy);

Expand Down
0