Skip to content

Latest commit

 

History

History
34 lines (28 loc) · 757 Bytes

NormalizationLinkMappingBuilder.md

File metadata and controls

34 lines (28 loc) · 757 Bytes

NormalizationLinkMappingBuilder

<?php

use Chubbyphp\Serialization\Link\Link;
use Chubbyphp\Serialization\Mapping\NormalizationLinkMappingBuilder;
use Chubbyphp\Serialization\Normalizer\CallbackLinkNormalizer;
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;

$fieldMapping = NormalizationLinkMappingBuilder::create(
    'name',
    new CallbackLinkNormalizer(
        function (
            string $path,
            $object,
            NormalizerContextInterface $context
        ) {
            return new Link('/api/model');
        }
    )
)
->getMapping();

echo $fieldMapping->getName();
// 'name'

print_r($fieldMapping->getGroups());
// ['group1']

$fieldMapping
    ->getLinkNormalizer()
    ->normalizeLink(...);