1 | <?php |
||
49 | class TokenRegistry implements \Iterator, \Countable |
||
50 | { |
||
51 | /** |
||
52 | * Storage for the Tokens. |
||
53 | * |
||
54 | * @var \Org\Heigl\Hyphenator\Tokenizer\Token[] $registry |
||
55 | */ |
||
56 | private $registry = array(); |
||
57 | |||
58 | /** |
||
59 | * Add an item to the registry |
||
60 | * |
||
61 | * @param \Org\Heigl\Hyphenator\Tokenizer\Token $token The token to add |
||
62 | * |
||
63 | * @return \Org\Heigl\Hyphenator\Tokenizer\TokenRegistry |
||
64 | */ |
||
65 | public function add(Token $token) |
||
71 | |||
72 | /** |
||
73 | * Replace a given token with an array of new tokens |
||
74 | * |
||
75 | * This will be used when a tokenizer has to replace a token that has been |
||
76 | * divided into multiple tokens. |
||
77 | * |
||
78 | * @param Token $oldToken The token to be replaced |
||
79 | * @param Token[] $newTokens The array of tokens replacing the old one |
||
80 | * |
||
81 | * @return TokenRegistry |
||
82 | */ |
||
83 | public function replace(Token $oldToken, array $newTokens) |
||
105 | |||
106 | /** |
||
107 | * Get a Token entry by its key |
||
108 | * |
||
109 | * @param mixed $key The key to get the token for |
||
110 | * |
||
111 | * @return Token|null |
||
112 | */ |
||
113 | public function getTokenWithKey($key) |
||
121 | |||
122 | /** |
||
123 | * Implementation of \Iterator |
||
124 | * |
||
125 | * @see \Iterator::rewind() |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | public function rewind() |
||
133 | |||
134 | /** |
||
135 | * Get the current object |
||
136 | * |
||
137 | * @see \Iterator::current() |
||
138 | * |
||
139 | * @return \Org\Heigl\Hyphenator\Tokenizer\Token |
||
140 | */ |
||
141 | public function current() |
||
145 | |||
146 | /** |
||
147 | * Get the current key |
||
148 | * |
||
149 | * @see \Iterator::key() |
||
150 | * |
||
151 | * @return mixed |
||
152 | */ |
||
153 | public function key() |
||
157 | |||
158 | /** |
||
159 | * Get the number of items in the registry |
||
160 | * |
||
161 | * @see \Countable::count() |
||
162 | * |
||
163 | * @return int |
||
164 | */ |
||
165 | public function count() |
||
169 | |||
170 | /** |
||
171 | * Push the internal pointer forward one step |
||
172 | * |
||
173 | * @see \Iterator::next() |
||
174 | * |
||
175 | * @return void |
||
176 | */ |
||
177 | public function next() |
||
181 | |||
182 | /** |
||
183 | * Check whether the current pointer is in a valid place |
||
184 | * |
||
185 | * @see \Iterator::valid() |
||
186 | * |
||
187 | * @return boolean |
||
188 | */ |
||
189 | public function valid() |
||
197 | } |
||
198 |