Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 570 Bytes

CallbackLinkNormalizer.md

File metadata and controls

30 lines (25 loc) · 570 Bytes

CallbackLinkNormalizer

<?php

use Chubbyphp\Serialization\Link\Link;
use Chubbyphp\Serialization\Normalizer\CallbackLinkNormalizer;
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;
use MyProject\Model\Model;

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

$fieldNormalizer = new CallbackLinkNormalizer(
    function (
        string $path,
        object $object,
        NormalizerContextInterface $context
    ) {
        return new Link('/api/model');
    }
);

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