-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path03.phpdoc-mapping.php
More file actions
55 lines (45 loc) · 1.21 KB
/
03.phpdoc-mapping.php
File metadata and controls
55 lines (45 loc) · 1.21 KB
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
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
use TypeLang\Mapper\Configuration;
use TypeLang\Mapper\Mapper;
require __DIR__ . '/../../vendor/autoload.php';
class ExampleDTO
{
public function __construct(
/**
* @map-var list<bool>
* @var list<string>
*/
public readonly array $value = [],
) {}
}
// Create standard platform with PHPDOC READERS
$platform = new \TypeLang\Mapper\Platform\StandardPlatform(
meta: new \TypeLang\Mapper\Mapping\Reader\PhpDocReader(
paramTagName: 'map-param',
varTagName: 'map-var',
returnTagName: 'map-return',
// In the case of "@map-xxxx" annotations is missing,
// then the @var/@param/@return will be used (fallback)
delegate: new \TypeLang\Mapper\Mapping\Reader\PhpDocReader(
varTagName: 'var',
),
),
);
$mapper = new Mapper($platform, new Configuration(
strictTypes: false,
));
var_dump($mapper->denormalize([
'value' => ['key' => 0, 1, 2],
], ExampleDTO::class));
//
// Because type in "@map-var" tag is "list<bool>".
//
// object(ExampleDTO)#345 (1) {
// ["value"] => array(2) {
// [0] => bool(false)
// [1] => bool(true)
// [2] => bool(true)
// }
// }
//