1 | <?php |
||
13 | class Context |
||
14 | { |
||
15 | /** |
||
16 | * @var string Parsing string. |
||
17 | */ |
||
18 | protected $string; |
||
19 | |||
20 | /** |
||
21 | * @var int The number of the current position. |
||
22 | */ |
||
23 | protected $cursor = 0; |
||
24 | |||
25 | /** |
||
26 | * @var int The current depth of immersion in the rules tree. |
||
27 | */ |
||
28 | protected $depth = 0; |
||
29 | |||
30 | /** |
||
31 | * @var ErrorCollectionInterface |
||
32 | */ |
||
33 | protected $errors; |
||
34 | |||
35 | /** |
||
36 | * @param ErrorCollectionInterface $errorCollection |
||
37 | */ |
||
38 | 2 | public function __construct(ErrorCollectionInterface $errorCollection) |
|
42 | |||
43 | /** |
||
44 | * Set new string and reset cursor. |
||
45 | * |
||
46 | * @param string $string |
||
47 | * @return void |
||
48 | */ |
||
49 | 2 | public function setString($string) |
|
56 | |||
57 | /** |
||
58 | * Returns the characters from the current position with the given $size. |
||
59 | * |
||
60 | * @param int $size |
||
61 | * @return bool|string |
||
62 | */ |
||
63 | 3 | public function value($size = 1) |
|
73 | |||
74 | /** |
||
75 | * Returns the current value of the cursor. |
||
76 | * |
||
77 | * @return int |
||
78 | */ |
||
79 | 3 | public function getCursor() |
|
83 | |||
84 | /** |
||
85 | * Sets a new value for the cursor. |
||
86 | * |
||
87 | * @param int $position |
||
88 | * @throws Exception |
||
89 | */ |
||
90 | 4 | public function setCursor($position) |
|
97 | |||
98 | /** |
||
99 | * Increase the depth by one. |
||
100 | * |
||
101 | * @throws Exception |
||
102 | */ |
||
103 | 7 | public function increaseDepth() |
|
107 | |||
108 | /** |
||
109 | * Decrease the depth by one. |
||
110 | * |
||
111 | * @throws Exception |
||
112 | */ |
||
113 | 7 | public function decreaseDepth() |
|
120 | |||
121 | /** |
||
122 | * @param RuleInterface $rule |
||
123 | * @param int $index |
||
124 | */ |
||
125 | public function error(RuleInterface $rule, $index) |
||
129 | } |
||
130 |