mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-06 13:16:39 +02:00
Merge pull request #891 from naderman/t/do-not-iterate-non-arrays
Do not iterate non-array Traversables
This commit is contained in:
@@ -70,17 +70,13 @@ class NormalizerFormatter implements FormatterInterface
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($data) || $data instanceof \Traversable) {
|
if (is_array($data)) {
|
||||||
$normalized = array();
|
$normalized = array();
|
||||||
|
|
||||||
$count = 1;
|
$count = 1;
|
||||||
if ($data instanceof \Generator && !$data->valid()) {
|
|
||||||
return array('...' => 'Generator is already consumed, aborting');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
if ($count++ >= 1000) {
|
if ($count++ >= 1000) {
|
||||||
$normalized['...'] = 'Over 1000 items ('.($data instanceof \Generator ? 'generator function' : count($data).' total').'), aborting normalization';
|
$normalized['...'] = 'Over 1000 items ('.count($data).' total), aborting normalization';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$normalized[$key] = $this->normalize($value);
|
$normalized[$key] = $this->normalize($value);
|
||||||
|
Reference in New Issue
Block a user