Skip to content

Latest commit

 

History

History
33 lines (27 loc) · 588 Bytes

CallbackFieldDenormalizer.md

File metadata and controls

33 lines (27 loc) · 588 Bytes

CallbackFieldDenormalizer

<?php

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

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

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

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

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