mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 19:13:49 +00:00
Docgen/action add missing goals
This commit is contained in:
@@ -11,9 +11,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Serializer\Helper;
|
||||
|
||||
use Symfony\Component\Serializer\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
use function array_merge;
|
||||
use function is_array;
|
||||
|
||||
class NormalizeNullValueHelper
|
||||
{
|
||||
@@ -30,7 +32,7 @@ class NormalizeNullValueHelper
|
||||
$this->discriminatorValue = $discriminatorValue;
|
||||
}
|
||||
|
||||
public function normalize(array $attributes, string $format = 'docgen', ?array $context = [])
|
||||
public function normalize(array $attributes, string $format = 'docgen', ?array $context = [], ?ClassMetadata $classMetadata = null)
|
||||
{
|
||||
$data = [];
|
||||
$data['isNull'] = true;
|
||||
@@ -58,7 +60,7 @@ class NormalizeNullValueHelper
|
||||
|
||||
default:
|
||||
$data[$key] = $this->normalizer->normalize(null, $format, array_merge(
|
||||
$context,
|
||||
$this->getContextForAttribute($key, $context, $classMetadata),
|
||||
['docgen:expects' => $class]
|
||||
));
|
||||
|
||||
@@ -69,4 +71,25 @@ class NormalizeNullValueHelper
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getContextForAttribute(string $key, array $initialContext, ?ClassMetadata $classMetadata): array
|
||||
{
|
||||
if (null === $classMetadata) {
|
||||
return $initialContext;
|
||||
}
|
||||
|
||||
$attributeMetadata = $classMetadata->getAttributesMetadata()[$key] ?? null;
|
||||
|
||||
if (null !== $attributeMetadata) {
|
||||
/** @var \Symfony\Component\Serializer\Mapping\AttributeMetadata $attributeMetadata */
|
||||
$initialContext = array_merge(
|
||||
$initialContext,
|
||||
$attributeMetadata->getNormalizationContextForGroups(
|
||||
is_array($initialContext['groups']) ? $initialContext['groups'] : [$initialContext['groups']]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $initialContext;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user