|
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\SDL\IR; |
|
11
|
|
|
|
|
12
|
|
|
use Railt\Io\PositionInterface; |
|
13
|
|
|
use Railt\Io\Readable; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @property string $name |
|
17
|
|
|
* @property string $description |
|
18
|
|
|
* @property TypeInterface|Type $type |
|
19
|
|
|
* @property array|Definition[] $directives |
|
20
|
|
|
* |
|
21
|
|
|
* -- Interfaces and Objects: |
|
22
|
|
|
* @property array|Definition[] $implements |
|
23
|
|
|
* @property array|Definition[] $fields |
|
24
|
|
|
* |
|
25
|
|
|
* -- Fields, InputFields, Arguments and EnumValues: |
|
26
|
|
|
* @property mixed $hint |
|
27
|
|
|
* @property int $modifiers |
|
28
|
|
|
* |
|
29
|
|
|
* -- Fields and Directives: |
|
30
|
|
|
* @property array|Definition[] $arguments |
|
31
|
|
|
* |
|
32
|
|
|
* -- InputFields |
|
33
|
|
|
* @property mixed $default |
|
34
|
|
|
* |
|
35
|
|
|
* -- Enums |
|
36
|
|
|
* @property array|Definition[] $values |
|
37
|
|
|
* |
|
38
|
|
|
* -- EnumValues |
|
39
|
|
|
* @property mixed $value |
|
40
|
|
|
* |
|
41
|
|
|
* -- Unions and Documents |
|
42
|
|
|
* @property array|Definition[] $definitions |
|
43
|
|
|
* |
|
44
|
|
|
* -- Scalars |
|
45
|
|
|
* @property string $extends |
|
46
|
|
|
*/ |
|
47
|
|
|
class Definition extends ValueObject implements DefinitionInterface |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* @var int |
|
51
|
|
|
*/ |
|
52
|
|
|
private $offset = 0; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var Readable|null |
|
56
|
|
|
*/ |
|
57
|
|
|
private $file; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var PositionInterface |
|
61
|
|
|
*/ |
|
62
|
|
|
private $position; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param Readable $file |
|
66
|
|
|
* @param int $offset |
|
67
|
|
|
* @return Definition |
|
68
|
|
|
*/ |
|
69
|
|
|
public function in(Readable $file, int $offset = 0): Definition |
|
70
|
|
|
{ |
|
71
|
|
|
$this->file = $file; |
|
72
|
|
|
$this->offset = $offset; |
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return int |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getLine(): int |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->getPosition()->getLine(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return PositionInterface |
|
87
|
|
|
*/ |
|
88
|
|
|
private function getPosition(): PositionInterface |
|
89
|
|
|
{ |
|
90
|
|
|
if ($this->position === null) { |
|
91
|
|
|
$this->position = $this->getFile()->getPosition($this->offset); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $this->position; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return Readable |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getFile(): Readable |
|
101
|
|
|
{ |
|
102
|
|
|
\assert($this->file !== null); |
|
103
|
|
|
|
|
104
|
|
|
return $this->file; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return int |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getColumn(): int |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->getPosition()->getColumn(); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|