1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Railt\Reflection\Stdlib\Scalar; |
11
|
|
|
|
12
|
|
|
use Railt\Reflection\Definition\ScalarDefinition; |
13
|
|
|
use Railt\Reflection\Document; |
14
|
|
|
use Railt\Reflection\Exception\TypeConflictException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class IdScalar |
18
|
|
|
*/ |
19
|
|
|
final class IdScalar extends ScalarDefinition |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
public const TYPE_NAME = 'ID'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public const TYPE_DESCRIPTION = <<<Description |
30
|
|
|
The ID scalar type represents a unique identifier, often used to refetch |
31
|
|
|
an object or as the key for a cache. The ID type is serialized in the |
32
|
|
|
same way as a String; however, defining it as an ID signifies that it |
33
|
|
|
is not intended to be human‐readable. |
34
|
|
|
Description; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* BooleanScalar constructor. |
38
|
|
|
* @param Document $document |
39
|
|
|
*/ |
40
|
9 |
|
public function __construct(Document $document) |
41
|
|
|
{ |
42
|
9 |
|
parent::__construct($document, self::TYPE_NAME); |
43
|
|
|
|
44
|
9 |
|
$this->withDescription(self::TYPE_DESCRIPTION); |
45
|
9 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param mixed $value |
49
|
|
|
* @return string |
50
|
|
|
* @throws TypeConflictException |
51
|
|
|
*/ |
52
|
|
|
public function parse($value): string |
53
|
|
|
{ |
54
|
|
|
if (! \is_scalar($value)) { |
55
|
|
|
throw new TypeConflictException(\sprintf('Could not parse %s type', \gettype($value))); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return (string)parent::parse($value); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param mixed $value |
63
|
|
|
* @return string |
64
|
|
|
* @throws TypeConflictException |
65
|
|
|
*/ |
66
|
|
|
public function serialize($value): string |
67
|
|
|
{ |
68
|
|
|
if (! \is_scalar($value)) { |
69
|
|
|
throw new TypeConflictException(\sprintf('Could not serialize %s type', \gettype($value))); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return (string)parent::serialize($value); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
|
|
public function getLine(): int |
79
|
|
|
{ |
80
|
|
|
return 25; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return bool |
85
|
|
|
*/ |
86
|
|
|
public function isBuiltin(): bool |
87
|
|
|
{ |
88
|
|
|
return true; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|