mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
Bootstrap encoder for documents
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Serializer\Helper;
|
||||
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
class NormalizeNullValueHelper
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
public function __construct(NormalizerInterface $normalizer)
|
||||
{
|
||||
$this->normalizer = $normalizer;
|
||||
}
|
||||
|
||||
public function normalize(array $attributes, string $format = 'docgen', ?array $context = [])
|
||||
{
|
||||
$data = [];
|
||||
|
||||
foreach ($attributes as $key => $class) {
|
||||
if (is_numeric($key)) {
|
||||
$data[$class] = '';
|
||||
} else {
|
||||
switch ($class) {
|
||||
case 'array':
|
||||
case 'bool':
|
||||
case 'double':
|
||||
case 'float':
|
||||
case 'int':
|
||||
case 'resource':
|
||||
case 'string':
|
||||
case 'null':
|
||||
$data[$key] = '';
|
||||
break;
|
||||
default:
|
||||
$data[$key] = $this->normalizer->normalize(null, $format, \array_merge(
|
||||
$context,
|
||||
['docgen:expects' => $class]
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user