Skip to content

Latest commit

 

History

History
33 lines (27 loc) · 584 Bytes

CallbackFieldDenormalizer.md

File metadata and controls

33 lines (27 loc) · 584 Bytes

CallbackFieldDenormalizer

<?php

use Chubbyphp\Deserialization\Denormalizer\CallbackFieldDenormalizer;
use MyProject\Model\Model;

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

$fieldDenormalizer = new CallbackFieldDenormalizer(
    function (
        string $path,
        object $object,
        $value,
        DenormalizerContextInterface $context,
        DenormalizerInterface $denormalizer = null
    ) {
        $object->setName($value);
    }
);

$fieldDenormalizer->denormalizeField(
    'name',
    $model,
    'php',
    $context
);

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