@@ -77,7 +77,6 @@ class Tokenizer
7777 */
7878 protected $ tokenCache = [];
7979
80-
8180 /**
8281 * @var array
8382 */
@@ -115,6 +114,7 @@ protected function initRegex($variable)
115114 * Each token is an associative array with type and value.
116115 *
117116 * @param string $string
117+ *
118118 * @return array
119119 */
120120 public function tokenize ($ string )
@@ -131,17 +131,11 @@ public function tokenize($string)
131131 break ;
132132 }
133133
134- $ oldStringLength = $ currentStringLength ;
135-
136- $ cacheKey = $ this ->useTokenCache ($ string , $ currentStringLength );
137- if (!empty ($ cacheKey ) && isset ($ this ->tokenCache [$ cacheKey ])) {
138- $ token = $ this ->getNextTokenFromCache ($ cacheKey );
139- } else {
140- $ token = $ this ->getNextTokenFromString ($ string , $ token , $ cacheKey );
141- }
142-
134+ $ token = $ this ->getToken ($ string , $ currentStringLength , $ token );
143135 $ tokens [] = $ token ;
144136 $ tokenLength = strlen ($ token [self ::TOKEN_VALUE ]);
137+
138+ $ oldStringLength = $ currentStringLength ;
145139 $ currentStringLength -= $ tokenLength ;
146140
147141 $ string = substr ($ string , $ tokenLength );
@@ -198,25 +192,6 @@ protected function getNextTokenFromString($string, $token, $cacheKey)
198192 return $ token ;
199193 }
200194
201- /**
202- * @param array $nextToken
203- *
204- * @return $this
205- */
206- public function setNextToken ($ nextToken )
207- {
208- $ this ->nextToken = $ nextToken ;
209- return $ this ;
210- }
211-
212- /**
213- * @return array
214- */
215- public function getNextToken ()
216- {
217- return $ this ->nextToken ;
218- }
219-
220195 /**
221196 * Return the next token and token type in a SQL string.
222197 * Quoted strings, comments, reserved words, whitespace, and punctuation are all their own tokens.
@@ -228,7 +203,7 @@ public function getNextToken()
228203 */
229204 protected function parseNextToken ($ string , $ previous = null )
230205 {
231- $ matches = [];
206+ $ matches = [];
232207 $ this ->nextToken = [];
233208
234209 WhiteSpace::isWhiteSpace ($ this , $ string , $ matches );
@@ -245,15 +220,22 @@ protected function parseNextToken($string, $previous = null)
245220 }
246221
247222 /**
248- * Helper function for building regular expressions for reserved words and boundary characters
249- *
250- * @param string $string
223+ * @return array
224+ */
225+ public function getNextToken ()
226+ {
227+ return $ this ->nextToken ;
228+ }
229+
230+ /**
231+ * @param array $nextToken
251232 *
252- * @return string
233+ * @return $this
253234 */
254- protected function quoteRegex ( $ string )
235+ public function setNextToken ( $ nextToken )
255236 {
256- return preg_quote ($ string , '/ ' );
237+ $ this ->nextToken = $ nextToken ;
238+ return $ this ;
257239 }
258240
259241 /**
@@ -295,4 +277,34 @@ public function getRegexReservedTopLevel()
295277 {
296278 return $ this ->regexReservedTopLevel ;
297279 }
280+
281+ /**
282+ * Helper function for building regular expressions for reserved words and boundary characters
283+ *
284+ * @param string $string
285+ *
286+ * @return string
287+ */
288+ protected function quoteRegex ($ string )
289+ {
290+ return preg_quote ($ string , '/ ' );
291+ }
292+
293+ /**
294+ * @param $string
295+ * @param $currentStringLength
296+ * @param $token
297+ *
298+ * @return array|mixed
299+ */
300+ protected function getToken ($ string , $ currentStringLength , $ token )
301+ {
302+ $ cacheKey = $ this ->useTokenCache ($ string , $ currentStringLength );
303+ if (!empty ($ cacheKey ) && isset ($ this ->tokenCache [$ cacheKey ])) {
304+ $ token = $ this ->getNextTokenFromCache ($ cacheKey );
305+ } else {
306+ $ token = $ this ->getNextTokenFromString ($ string , $ token , $ cacheKey );
307+ }
308+ return $ token ;
309+ }
298310}
0 commit comments