Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 610 Bytes

EmbedOneFieldDenormalizer.md

File metadata and controls

32 lines (26 loc) · 610 Bytes

EmbedOneFieldDenormalizer

<?php

use Chubbyphp\Deserialization\Accessor\PropertyAccessor;
use Chubbyphp\Deserialization\Denormalizer\Relation\EmbedOneFieldDenormalizer;
use MyProject\Model\Model;
use MyProject\Model\ReferenceModel;

$model = new Model;
$context = ...;
$denormalizer = ...;

$fieldDenormalizer = new EmbedOneFieldDenormalizer(
    ReferenceModel::class,
    new PropertyAccessor('children')
);

$fieldDenormalizer->denormalizeField(
    'reference',
    $model,
    ['name' => 'php'],
    $context,
    $denormalizer
);

echo $model
    ->getReference()
    ->getName();
// 'php'