-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path04.array-mapping.php
More file actions
48 lines (38 loc) · 939 Bytes
/
04.array-mapping.php
File metadata and controls
48 lines (38 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
use TypeLang\Mapper\Configuration;
use TypeLang\Mapper\Mapper;
require __DIR__ . '/../../vendor/autoload.php';
class ExampleDTO
{
public function __construct(
public readonly array $value = [],
) {}
}
// Create standard platform with ARRAY READER
$platform = new \TypeLang\Mapper\Platform\StandardPlatform(
meta: new \TypeLang\Mapper\Mapping\Reader\ArrayReader([
ExampleDTO::class => [
'properties' => [
'value' => 'list<bool>',
],
],
]),
);
$mapper = new Mapper($platform, new Configuration(
strictTypes: false,
));
var_dump($mapper->denormalize([
'value' => ['key' => 0, 1, 2],
], ExampleDTO::class));
//
// Because type in config is "list<bool>"
//
// object(ExampleDTO)#345 (1) {
// ["value"] => array(2) {
// [0] => bool(false)
// [1] => bool(true)
// [2] => bool(true)
// }
// }
//