getNormalizationContextForGroups example

 $metadata->getDenormalizationContexts());
    }

    public function testGetContextsForGroups()
    {
        $metadata = new AttributeMetadata('a1');

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

        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']));
        
/** * Computes the normalization context merged with current one. Metadata always wins over global context, as more specific. * * @internal */
    protected function getAttributeNormalizationContext(object $object, string $attribute, array $context): array
    {
        if (null === $metadata = $this->getAttributeMetadata($object$attribute)) {
            return $context;
        }

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

    /** * Computes the denormalization context merged with current one. Metadata always wins over global context, as more specific. * * @internal */
    protected function getAttributeDenormalizationContext(string $class, string $attribute, array $context): array
    {
        $context['deserialization_path'] = ($context['deserialization_path'] ?? false) ? $context['deserialization_path'].'.'.$attribute : $attribute;

        
/** * Computes the normalization context merged with current one. Metadata always wins over global context, as more specific. * * @internal */
    protected function getAttributeNormalizationContext(object $object, string $attribute, array $context): array
    {
        if (null === $metadata = $this->getAttributeMetadata($object$attribute)) {
            return $context;
        }

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

    /** * Computes the denormalization context merged with current one. Metadata always wins over global context, as more specific. * * @internal */
    protected function getAttributeDenormalizationContext(string $class, string $attribute, array $context): array
    {
        $context['deserialization_path'] = ($context['deserialization_path'] ?? false) ? $context['deserialization_path'].'.'.$attribute : $attribute;

        
Home | Imprint | This part of the site doesn't use cookies.