Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 644 Bytes

ReferenceOneFieldNormalizer.md

File metadata and controls

31 lines (24 loc) · 644 Bytes

ReferenceOneFieldNormalizer

<?php

use Chubbyphp\Serialization\Accessor\PropertyAccessor;
use Chubbyphp\Serialization\Normalizer\Relation\ReferenceOneFieldNormalizer;
use MyProject\Model\Model;
use MyProject\Model\RelationModel;

$model = new Model;
$model->setReference((new RelationModel)->setName('php'));

$context = ...;
$normalizer = ...;

$fieldNormalizer = new ReferenceOneFieldNormalizer(
    new PropertyAccessor('id'),
    new PropertyAccessor('children')
);

$data = $fieldNormalizer->normalizeField(
    'reference',
    $model,
    $context,
    $normalizer
);

echo $data;
// '4b184500-38d3-4cdf-b0ec-d36a61d1f9cd'