| @@ 14-82 (lines=69) @@ | ||
| 11 | use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMappingBuilderInterface; |
|
| 12 | use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMappingInterface; |
|
| 13 | ||
| 14 | final class DenormalizationFieldMappingBuilder implements DenormalizationFieldMappingBuilderInterface |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @var string |
|
| 18 | */ |
|
| 19 | private $name; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @var array |
|
| 23 | */ |
|
| 24 | private $groups; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @var FieldDenormalizerInterface |
|
| 28 | */ |
|
| 29 | private $fieldDenormalizer; |
|
| 30 | ||
| 31 | private function __construct() |
|
| 32 | { |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @param string $name |
|
| 37 | * |
|
| 38 | * @return DenormalizationFieldMappingBuilderInterface |
|
| 39 | */ |
|
| 40 | public static function create(string $name): DenormalizationFieldMappingBuilderInterface |
|
| 41 | { |
|
| 42 | $self = new self(); |
|
| 43 | $self->name = $name; |
|
| 44 | $self->groups = []; |
|
| 45 | $self->fieldDenormalizer = new FieldDenormalizer(new PropertyAccessor($name)); |
|
| 46 | ||
| 47 | return $self; |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @param array $groups |
|
| 52 | * |
|
| 53 | * @return DenormalizationFieldMappingBuilderInterface |
|
| 54 | */ |
|
| 55 | public function setGroups(array $groups): DenormalizationFieldMappingBuilderInterface |
|
| 56 | { |
|
| 57 | $this->groups = $groups; |
|
| 58 | ||
| 59 | return $this; |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * @param FieldDenormalizerInterface $fieldDenormalizer |
|
| 64 | * |
|
| 65 | * @return DenormalizationFieldMappingBuilderInterface |
|
| 66 | */ |
|
| 67 | public function setFieldDenormalizer( |
|
| 68 | FieldDenormalizerInterface $fieldDenormalizer |
|
| 69 | ): DenormalizationFieldMappingBuilderInterface { |
|
| 70 | $this->fieldDenormalizer = $fieldDenormalizer; |
|
| 71 | ||
| 72 | return $this; |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * @return DenormalizationFieldMappingInterface |
|
| 77 | */ |
|
| 78 | public function getMapping(): DenormalizationFieldMappingInterface |
|
| 79 | { |
|
| 80 | return new DenormalizationFieldMapping($this->name, $this->groups, $this->fieldDenormalizer); |
|
| 81 | } |
|
| 82 | } |
|
| 83 | ||
| @@ 11-79 (lines=69) @@ | ||
| 8 | use Chubbyphp\Deserialization\Denormalizer\FieldDenormalizer; |
|
| 9 | use Chubbyphp\Deserialization\Denormalizer\FieldDenormalizerInterface; |
|
| 10 | ||
| 11 | final class DenormalizationFieldMappingBuilder implements DenormalizationFieldMappingBuilderInterface |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @var string |
|
| 15 | */ |
|
| 16 | private $name; |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @var array |
|
| 20 | */ |
|
| 21 | private $groups; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * @var FieldDenormalizerInterface |
|
| 25 | */ |
|
| 26 | private $fieldDenormalizer; |
|
| 27 | ||
| 28 | private function __construct() |
|
| 29 | { |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * @param string $name |
|
| 34 | * |
|
| 35 | * @return DenormalizationFieldMappingBuilderInterface |
|
| 36 | */ |
|
| 37 | public static function create(string $name): DenormalizationFieldMappingBuilderInterface |
|
| 38 | { |
|
| 39 | $self = new self(); |
|
| 40 | $self->name = $name; |
|
| 41 | $self->groups = []; |
|
| 42 | $self->fieldDenormalizer = new FieldDenormalizer(new PropertyAccessor($name)); |
|
| 43 | ||
| 44 | return $self; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * @param array $groups |
|
| 49 | * |
|
| 50 | * @return DenormalizationFieldMappingBuilderInterface |
|
| 51 | */ |
|
| 52 | public function setGroups(array $groups): DenormalizationFieldMappingBuilderInterface |
|
| 53 | { |
|
| 54 | $this->groups = $groups; |
|
| 55 | ||
| 56 | return $this; |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * @param FieldDenormalizerInterface $fieldDenormalizer |
|
| 61 | * |
|
| 62 | * @return DenormalizationFieldMappingBuilderInterface |
|
| 63 | */ |
|
| 64 | public function setFieldDenormalizer( |
|
| 65 | FieldDenormalizerInterface $fieldDenormalizer |
|
| 66 | ): DenormalizationFieldMappingBuilderInterface { |
|
| 67 | $this->fieldDenormalizer = $fieldDenormalizer; |
|
| 68 | ||
| 69 | return $this; |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * @return DenormalizationFieldMappingInterface |
|
| 74 | */ |
|
| 75 | public function getMapping(): DenormalizationFieldMappingInterface |
|
| 76 | { |
|
| 77 | return new DenormalizationFieldMapping($this->name, $this->groups, $this->fieldDenormalizer); |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||