getInner example

if (!$this->price instanceof CalculatedCheapestPrice) {
            throw ProductException::invalidCheapestPriceFacade($this->item->getUniqueIdentifier());
        }

        if ($price === null) {
            /** @var CalculatedPrice $price */
            $price = $this->item->get('calculatedPrice');
        }

        if ($price instanceof PriceFacade) {
            $price = $price->getInner();
        }

        if ($price instanceof PriceCollection) {
            $value = $this->getPriceForTaxState($price$this->context);

            $definition = new QuantityPriceDefinition(
                $value,
                $this->price->getTaxRules(),
                $this->getQuantity()
            );

            
'bar' => 'rab',
            ],
        ];

        $normalizer = new ObjectNormalizer();
        $serializer = new Serializer([$normalizer]);
        $normalizer->setSerializer($serializer);

        $obj = $normalizer->denormalize($data, DummyWithConstructorObject::class);
        $this->assertInstanceOf(DummyWithConstructorObject::class$obj);
        $this->assertEquals(10, $obj->getId());
        $this->assertInstanceOf(ObjectInner::class$obj->getInner());
        $this->assertEquals('oof', $obj->getInner()->foo);
        $this->assertEquals('rab', $obj->getInner()->bar);
    }

    public function testConstructorWithUnconstructableNullableObjectTypeHintDenormalize()
    {
        $data = [
            'id' => 10,
            'inner' => null,
        ];

        
$objectToPopulate = new ObjectInner();
        $objectToPopulate->foo = 'foo';

        $outer = $denormalizer->denormalize([
            'foo' => 'foo',
            'inner' => [
                'bar' => 'bar',
            ],
        ], ObjectOuter::class, null, ['object_to_popuplate' => $objectToPopulate]);

        $this->assertInstanceOf(ObjectOuter::class$outer);
        $inner = $outer->getInner();
        $this->assertInstanceOf(ObjectInner::class$inner);
        $this->assertNotSame($objectToPopulate$inner);
        $this->assertSame('bar', $inner->bar);
        $this->assertNull($inner->foo);
    }

    public function testDeepObjectToPopulate()
    {
        $child = new DeepObjectPopulateChildDummy();
        $child->bar = 'bar-old';
        $child->foo = 'foo-old';

        
class ScriptResponseEncoder
{
    /** * @internal */
    public function __construct(private readonly StructEncoder $structEncoder)
    {
    }

    public function encodeToSymfonyResponse(ScriptResponse $scriptResponse, ResponseFields $responseFields, string $apiAlias): Response
    {
        $wrappedResponse = $scriptResponse->getInner();
        if ($wrappedResponse !== null) {
            return $wrappedResponse;
        }

        $data = $this->structEncoder->encode(new ArrayStruct($scriptResponse->getBody()->all()$apiAlias)$responseFields);

        return new JsonResponse($data$scriptResponse->getCode());
    }
}
$this->assertEquals(new \ArrayObject()$normalizedData);
    }

    public function testDenormalizeRecursiveWithObjectAttributeWithStringValue()
    {
        $extractor = new ReflectionExtractor();
        $normalizer = new ObjectNormalizer(null, null, null, $extractor);
        $serializer = new Serializer([$normalizer]);

        $obj = $serializer->denormalize(['inner' => 'foo'], ObjectOuter::class);

        $this->assertInstanceOf(ObjectInner::class$obj->getInner());
    }

    public function testDenormalizeUsesContextAttributeForPropertiesInConstructorWithSeralizedName()
    {
        $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader());

        $extractor = new PropertyInfoExtractor([][new PhpDocExtractor()new ReflectionExtractor()]);
        $normalizer = new ObjectNormalizer($classMetadataFactorynew MetadataAwareNameConverter($classMetadataFactory), null, $extractor);
        $serializer = new Serializer([new DateTimeNormalizer([DateTimeNormalizer::FORMAT_KEY => 'd-m-Y'])$normalizer]);

        /** @var ObjectDummyWithContextAttribute $obj */
        
Home | Imprint | This part of the site doesn't use cookies.