File tree Expand file tree Collapse file tree 2 files changed +15
-9
lines changed
src/Symfony/Component/Console Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -121,15 +121,23 @@ public function hasErrored()
121
121
*/
122
122
private function interpolate ($ message , array $ context )
123
123
{
124
- // build a replacement array with braces around the context keys
125
- $ replace = array ();
124
+ if (false === strpos ($ message , '{ ' )) {
125
+ return $ message ;
126
+ }
127
+
128
+ $ replacements = array ();
126
129
foreach ($ context as $ key => $ val ) {
127
- if (!is_array ($ val ) && (!is_object ($ val ) || method_exists ($ val , '__toString ' ))) {
128
- $ replace [sprintf ('{%s} ' , $ key )] = $ val ;
130
+ if (null === $ val || is_scalar ($ val ) || (\is_object ($ val ) && method_exists ($ val , '__toString ' ))) {
131
+ $ replacements ["{ {$ key }} " ] = $ val ;
132
+ } elseif ($ val instanceof \DateTimeInterface) {
133
+ $ replacements ["{ {$ key }} " ] = $ val ->format (\DateTime::RFC3339 );
134
+ } elseif (\is_object ($ val )) {
135
+ $ replacements ["{ {$ key }} " ] = '[object ' .\get_class ($ val ).'] ' ;
136
+ } else {
137
+ $ replacements ["{ {$ key }} " ] = '[ ' .\gettype ($ val ).'] ' ;
129
138
}
130
139
}
131
140
132
- // interpolate replacement values into the message and return
133
- return strtr ($ message , $ replace );
141
+ return strtr ($ message , $ replacements );
134
142
}
135
143
}
Original file line number Diff line number Diff line change @@ -166,9 +166,7 @@ public function testObjectCastToString()
166
166
} else {
167
167
$ dummy = $ this ->getMock ('Symfony\Component\Console\Tests\Logger\DummyTest ' , array ('__toString ' ));
168
168
}
169
- $ dummy ->expects ($ this ->once ())
170
- ->method ('__toString ' )
171
- ->will ($ this ->returnValue ('DUMMY ' ));
169
+ $ dummy ->method ('__toString ' )->will ($ this ->returnValue ('DUMMY ' ));
172
170
173
171
$ this ->getLogger ()->warning ($ dummy );
174
172
You can’t perform that action at this time.
0 commit comments