File tree Expand file tree Collapse file tree 1 file changed +30
-6
lines changed
Expand file tree Collapse file tree 1 file changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -31,24 +31,48 @@ composer require type-lang/mapper
3131## Quick Start
3232
3333``` php
34+ use TypeLang\Mapper\Mapping\MapProperty;
35+
3436class ExampleObject
3537{
3638 public function __construct(
37- public readonly string $name,
39+ #[MapProperty('list<non-empty-string >')]
40+ public readonly array $name,
3841 ) {}
3942}
4043
4144$mapper = new \TypeLang\Mapper\Mapper();
4245
43- $normalized = $mapper->normalize(new ExampleObject('Example'));
46+ $result = $mapper->normalize(
47+ new ExampleObject(['Example'])
48+ );
4449// Expected Result:
50+ //
4551// array:1 [
46- // "name" => "Example"
52+ // "names" => array:1 [
53+ // 0 => "Example"
54+ // ]
4755// ]
4856
49- $denormalized = $mapper->denormalize($normalized, ExampleObject::class);
57+
58+ $result = $mapper->denormalize([
59+ 'names' => ['first', 'second']
60+ ], ExampleObject::class);
5061// Expected Result:
51- // ExampleObject {#14
52- // +name: "Example"
62+ //
63+ // ExampleObject {#324
64+ // +names: array:2 [
65+ // 0 => "first"
66+ // 1 => "second"
67+ // ]
5368// }
69+
70+
71+ $result = $mapper->denormalize([
72+ 'names' => ['first', 'second', ''],
73+ ], ExampleObject::class);
74+ // Expected Result:
75+ //
76+ // InvalidFieldTypeValueException: Passed value of field "names" must be of type
77+ // list<non-empty-string >, but array(3)["first", "second", ""] given at $.names[2]
5478```
You can’t perform that action at this time.
0 commit comments