mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-22 17:16:18 +02:00
Migrate maxNormalizeDepth/maxNormalizeItemCount props and setters to NormalizerFormatter
This commit is contained in:
@@ -24,6 +24,8 @@ class NormalizerFormatter implements FormatterInterface
|
||||
const SIMPLE_DATE = "Y-m-d\TH:i:sP";
|
||||
|
||||
protected $dateFormat;
|
||||
protected $maxNormalizeDepth = 9;
|
||||
protected $maxNormalizeItemCount = 1000;
|
||||
|
||||
/**
|
||||
* @param string $dateFormat The format of the timestamp: one supported by DateTime::format
|
||||
@@ -56,14 +58,40 @@ class NormalizerFormatter implements FormatterInterface
|
||||
return $records;
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum number of normalization levels to go through
|
||||
*/
|
||||
public function getMaxNormalizeDepth(): int
|
||||
{
|
||||
return $this->maxNormalizeDepth;
|
||||
}
|
||||
|
||||
public function setMaxNormalizeDepth(int $maxNormalizeDepth): void
|
||||
{
|
||||
$this->maxNormalizeDepth = $maxNormalizeDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum number of items to normalize per level
|
||||
*/
|
||||
public function getMaxNormalizeItemCount(): int
|
||||
{
|
||||
return $this->maxNormalizeItemCount;
|
||||
}
|
||||
|
||||
public function setMaxNormalizeItemCount(int $maxNormalizeItemCount): void
|
||||
{
|
||||
$this->maxNormalizeItemCount = $maxNormalizeItemCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @return int|bool|string|null|array
|
||||
*/
|
||||
protected function normalize($data, int $depth = 0)
|
||||
{
|
||||
if ($depth > 9) {
|
||||
return 'Over 9 levels deep, aborting normalization';
|
||||
if ($depth > $this->maxNormalizeDepth) {
|
||||
return 'Over ' . $this->maxNormalizeDepth . ' levels deep, aborting normalization';
|
||||
}
|
||||
|
||||
if (null === $data || is_scalar($data)) {
|
||||
@@ -84,8 +112,8 @@ class NormalizerFormatter implements FormatterInterface
|
||||
|
||||
$count = 1;
|
||||
foreach ($data as $key => $value) {
|
||||
if ($count++ > 1000) {
|
||||
$normalized['...'] = 'Over 1000 items ('.count($data).' total), aborting normalization';
|
||||
if ($count++ > $this->maxNormalizeItemCount) {
|
||||
$normalized['...'] = 'Over ' . $this->maxNormalizeItemCount . ' items ('.count($data).' total), aborting normalization';
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user