1 | <?php |
||
2 | |||
3 | namespace Popy\Calendar\Parser; |
||
4 | |||
5 | /** |
||
6 | * DateLexerResult |
||
7 | */ |
||
8 | class DateLexerResult |
||
9 | { |
||
10 | /** |
||
11 | * Resulting offset. |
||
12 | * |
||
13 | * @var integer |
||
14 | */ |
||
15 | protected $offset; |
||
16 | |||
17 | /** |
||
18 | * Data extracted by the lexer. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $data = []; |
||
23 | |||
24 | /** |
||
25 | * Class constructor. |
||
26 | * |
||
27 | * @param integer $offset [description] |
||
28 | */ |
||
29 | public function __construct($offset) |
||
30 | { |
||
31 | $this->offset = $offset; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Gets offset. |
||
36 | * |
||
37 | * @return integer |
||
38 | */ |
||
39 | public function getOffset() |
||
40 | { |
||
41 | return $this->offset; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Set parsed symbol value. |
||
46 | * |
||
47 | * @param string $name Symbol name. |
||
48 | * @param mixed $value Symbol value. |
||
49 | */ |
||
50 | public function set($name, $value) |
||
51 | { |
||
52 | $this->data[$name] = $value; |
||
53 | |||
54 | return $this; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Gets a symbol value. |
||
59 | * |
||
60 | * @param string $name Symbol name. |
||
61 | * @param mixed $default Fallback value. |
||
62 | * |
||
63 | * @return mixed |
||
64 | */ |
||
65 | public function get($name, $default = null) |
||
66 | { |
||
67 | if (isset($this->data[$name])) { |
||
68 | return $this->data[$name]; |
||
69 | } |
||
70 | |||
71 | return $default; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Merges a result into this one. |
||
76 | * |
||
77 | * @param DateLexerResult $result |
||
78 | */ |
||
79 | public function merge(DateLexerResult $result) |
||
80 | { |
||
81 | $this->offset = $result->offset; |
||
82 | $this->data = array_merge($this->data, $result->data); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Get first set symbol value. |
||
87 | * |
||
88 | * @param string $name |
||
89 | * @param string ...$name |
||
90 | * |
||
91 | * @return mixed |
||
92 | */ |
||
93 | public function getFirst($name) |
||
94 | { |
||
95 | $names = func_get_args(); |
||
96 | |||
97 | foreach ($names as $name) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
98 | if (isset($this->data[$name])) { |
||
99 | return $this->data[$name]; |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 |