2022-10-17 21:25:03 +02:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Monolog package.
|
|
|
|
*
|
|
|
|
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Monolog\Formatter;
|
|
|
|
|
|
|
|
/**
|
2023-07-02 23:57:24 +02:00
|
|
|
* Formats data into an associative array of scalar values.
|
2022-10-17 21:25:03 +02:00
|
|
|
* Objects and arrays will be JSON encoded.
|
|
|
|
*
|
|
|
|
* @author Andrew Lawson <adlawson@gmail.com>
|
|
|
|
*/
|
|
|
|
class ScalarFormatter extends NormalizerFormatter
|
|
|
|
{
|
|
|
|
/**
|
2023-07-02 23:57:24 +02:00
|
|
|
* {@inheritDoc}
|
2022-10-17 21:25:03 +02:00
|
|
|
*
|
|
|
|
* @phpstan-return array<string, scalar|null> $record
|
|
|
|
*/
|
2023-07-02 23:57:24 +02:00
|
|
|
public function format(array $record): array
|
2022-10-17 21:25:03 +02:00
|
|
|
{
|
|
|
|
$result = [];
|
2023-07-02 23:57:24 +02:00
|
|
|
foreach ($record as $key => $value) {
|
|
|
|
$result[$key] = $this->normalizeValue($value);
|
2022-10-17 21:25:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2023-07-02 23:57:24 +02:00
|
|
|
/**
|
|
|
|
* @param mixed $value
|
|
|
|
* @return scalar|null
|
|
|
|
*/
|
|
|
|
protected function normalizeValue($value)
|
2022-10-17 21:25:03 +02:00
|
|
|
{
|
|
|
|
$normalized = $this->normalize($value);
|
|
|
|
|
|
|
|
if (is_array($normalized)) {
|
|
|
|
return $this->toJson($normalized, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $normalized;
|
|
|
|
}
|
|
|
|
}
|