getDenormalizationContextForGroups example


    protected function getAttributeDenormalizationContext(string $class, string $attribute, array $context): array
    {
        $context['deserialization_path'] = ($context['deserialization_path'] ?? false) ? $context['deserialization_path'].'.'.$attribute : $attribute;

        if (null === $metadata = $this->getAttributeMetadata($class$attribute)) {
            return $context;
        }

        return array_merge($context$metadata->getDenormalizationContextForGroups($this->getGroups($context)));
    }

    /** * @internal */
    protected function getAttributeMetadata(object|string $objectOrClass, string $attribute): ?AttributeMetadataInterface
    {
        if (!$this->classMetadataFactory) {
            return null;
        }

        

    protected function getAttributeDenormalizationContext(string $class, string $attribute, array $context): array
    {
        $context['deserialization_path'] = ($context['deserialization_path'] ?? false) ? $context['deserialization_path'].'.'.$attribute : $attribute;

        if (null === $metadata = $this->getAttributeMetadata($class$attribute)) {
            return $context;
        }

        return array_merge($context$metadata->getDenormalizationContextForGroups($this->getGroups($context)));
    }

    /** * @internal */
    protected function getAttributeMetadata(object|string $objectOrClass, string $attribute): ?AttributeMetadataInterface
    {
        if (!$this->classMetadataFactory) {
            return null;
        }

        
self::assertSame(['foo' => 'default', 'bar' => 'default']$metadata->getNormalizationContextForGroups([]));
        self::assertSame(['foo' => 'overridden', 'bar' => 'default']$metadata->getNormalizationContextForGroups(['a']));
        self::assertSame(['foo' => 'overridden', 'bar' => 'default']$metadata->getNormalizationContextForGroups(['b']));
        self::assertSame(['foo' => 'default', 'bar' => 'overridden']$metadata->getNormalizationContextForGroups(['c']));
        self::assertSame(['foo' => 'overridden', 'bar' => 'overridden']$metadata->getNormalizationContextForGroups(['b', 'c']));

        $metadata->setDenormalizationContextForGroups(['foo' => 'default', 'bar' => 'default'][]);
        $metadata->setDenormalizationContextForGroups(['foo' => 'overridden']['a', 'b']);
        $metadata->setDenormalizationContextForGroups(['bar' => 'overridden']['c']);

        self::assertSame(['foo' => 'default', 'bar' => 'default']$metadata->getDenormalizationContextForGroups([]));
        self::assertSame(['foo' => 'overridden', 'bar' => 'default']$metadata->getDenormalizationContextForGroups(['a']));
        self::assertSame(['foo' => 'overridden', 'bar' => 'default']$metadata->getDenormalizationContextForGroups(['b']));
        self::assertSame(['foo' => 'default', 'bar' => 'overridden']$metadata->getDenormalizationContextForGroups(['c']));
        self::assertSame(['foo' => 'overridden', 'bar' => 'overridden']$metadata->getDenormalizationContextForGroups(['b', 'c']));
    }

    public function testMerge()
    {
        $serializedPath = new PropertyPath('[a4][a5]');
        $attributeMetadata1 = new AttributeMetadata('a1');
        $attributeMetadata1->addGroup('a');
        
Home | Imprint | This part of the site doesn't use cookies.