Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 643 Bytes

CallbackFieldNormalizer.md

File metadata and controls

31 lines (26 loc) · 643 Bytes

CallbackFieldNormalizer

<?php

use Chubbyphp\Serialization\Normalizer\CallbackFieldNormalizer;
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;
use Chubbyphp\Serialization\Normalizer\NormalizerInterface;
use MyProject\Model\Model;

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

$fieldNormalizer = new CallbackFieldNormalizer(
    function (
        string $path,
        object $object,
        NormalizerContextInterface $context,
        NormalizerInterface $normalizer = null
    ) {
        return $object->getName();
    }
);

echo $fieldNormalizer->normalizeField(
    'name',
    $model,
    $context
);
// 'php'