Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 655 Bytes

FieldDenormalizer.md

File metadata and controls

42 lines (33 loc) · 655 Bytes

FieldDenormalizer

<?php

use Chubbyphp\Deserialization\Accessor\PropertyAccessor;
use Chubbyphp\Deserialization\Denormalizer\FieldDenormalizer;
use MyProject\Model\Model;

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

$fieldDenormalizer = new FieldDenormalizer(
    new PropertyAccessor('name')
);

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

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

// empty to null
$fieldDenormalizer = new FieldDenormalizer(
    new PropertyAccessor('name'),
    true
);

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

echo $model->getName();
// null