setDenormalizationContextForGroups example

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

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

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

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

    
yield from $this->getMethodAnnotations($reflector);
        }
        if ($reflector instanceof \ReflectionProperty) {
            yield from $this->getPropertyAnnotations($reflector);
        }
    }

    private function setAttributeContextsForGroups(Context $annotation, AttributeMetadataInterface $attributeMetadata): void
    {
        if ($annotation->getContext()) {
            $attributeMetadata->setNormalizationContextForGroups($annotation->getContext()$annotation->getGroups());
            $attributeMetadata->setDenormalizationContextForGroups($annotation->getContext()$annotation->getGroups());
        }

        if ($annotation->getNormalizationContext()) {
            $attributeMetadata->setNormalizationContextForGroups($annotation->getNormalizationContext()$annotation->getGroups());
        }

        if ($annotation->getDenormalizationContext()) {
            $attributeMetadata->setDenormalizationContextForGroups($annotation->getDenormalizationContext()$annotation->getGroups());
        }
    }

    
throw new MappingException(sprintf('The "ignore" value must be a boolean in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute$classMetadata->getName()));
                    }

                    $attributeMetadata->setIgnore($data['ignore']);
                }

                foreach ($data['contexts'] ?? [] as $line) {
                    $groups = $line['groups'] ?? [];

                    if ($context = $line['context'] ?? false) {
                        $attributeMetadata->setNormalizationContextForGroups($context$groups);
                        $attributeMetadata->setDenormalizationContextForGroups($context$groups);
                    }

                    if ($context = $line['normalization_context'] ?? false) {
                        $attributeMetadata->setNormalizationContextForGroups($context$groups);
                    }

                    if ($context = $line['denormalization_context'] ?? false) {
                        $attributeMetadata->setDenormalizationContextForGroups($context$groups);
                    }
                }
            }
        }
throw new MappingException(sprintf('The "ignore" value must be a boolean in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute$classMetadata->getName()));
                    }

                    $attributeMetadata->setIgnore($data['ignore']);
                }

                foreach ($data['contexts'] ?? [] as $line) {
                    $groups = $line['groups'] ?? [];

                    if ($context = $line['context'] ?? false) {
                        $attributeMetadata->setNormalizationContextForGroups($context$groups);
                        $attributeMetadata->setDenormalizationContextForGroups($context$groups);
                    }

                    if ($context = $line['normalization_context'] ?? false) {
                        $attributeMetadata->setNormalizationContextForGroups($context$groups);
                    }

                    if ($context = $line['denormalization_context'] ?? false) {
                        $attributeMetadata->setDenormalizationContextForGroups($context$groups);
                    }
                }
            }
        }

                }

                if (isset($attribute['ignore'])) {
                    $attributeMetadata->setIgnore(XmlUtils::phpize($attribute['ignore']));
                }

                foreach ($attribute->context as $node) {
                    $groups = (array) $node->group;
                    $context = $this->parseContext($node->entry);
                    $attributeMetadata->setNormalizationContextForGroups($context$groups);
                    $attributeMetadata->setDenormalizationContextForGroups($context$groups);
                }

                foreach ($attribute->normalization_context as $node) {
                    $groups = (array) $node->group;
                    $context = $this->parseContext($node->entry);
                    $attributeMetadata->setNormalizationContextForGroups($context$groups);
                }

                foreach ($attribute->denormalization_context as $node) {
                    $groups = (array) $node->group;
                    $context = $this->parseContext($node->entry);
                    
yield from $this->reader->getMethodAnnotations($reflector);
        }
        if ($reflector instanceof \ReflectionProperty) {
            yield from $this->reader->getPropertyAnnotations($reflector);
        }
    }

    private function setAttributeContextsForGroups(Context $annotation, AttributeMetadataInterface $attributeMetadata): void
    {
        if ($annotation->getContext()) {
            $attributeMetadata->setNormalizationContextForGroups($annotation->getContext()$annotation->getGroups());
            $attributeMetadata->setDenormalizationContextForGroups($annotation->getContext()$annotation->getGroups());
        }

        if ($annotation->getNormalizationContext()) {
            $attributeMetadata->setNormalizationContextForGroups($annotation->getNormalizationContext()$annotation->getGroups());
        }

        if ($annotation->getDenormalizationContext()) {
            $attributeMetadata->setDenormalizationContextForGroups($annotation->getDenormalizationContext()$annotation->getGroups());
        }
    }

    

                }

                if (isset($attribute['ignore'])) {
                    $attributeMetadata->setIgnore(XmlUtils::phpize($attribute['ignore']));
                }

                foreach ($attribute->context as $node) {
                    $groups = (array) $node->group;
                    $context = $this->parseContext($node->entry);
                    $attributeMetadata->setNormalizationContextForGroups($context$groups);
                    $attributeMetadata->setDenormalizationContextForGroups($context$groups);
                }

                foreach ($attribute->normalization_context as $node) {
                    $groups = (array) $node->group;
                    $context = $this->parseContext($node->entry);
                    $attributeMetadata->setNormalizationContextForGroups($context$groups);
                }

                foreach ($attribute->denormalization_context as $node) {
                    $groups = (array) $node->group;
                    $context = $this->parseContext($node->entry);
                    
Home | Imprint | This part of the site doesn't use cookies.