1818 */
1919final class Reserved
2020{
21+ /**
22+ * @param array $matches
23+ * @param string $previous
24+ * @param string $string
25+ * @param string $reservedTopLevel
26+ * @param string $reservedNewLine
27+ * @param string $boundaries
28+ * @param string $reserved
29+ *
30+ * @return array
31+ */
32+ public static function isReserved (
33+ array &$ matches ,
34+ $ previous ,
35+ $ string ,
36+ $ reservedTopLevel ,
37+ $ reservedNewLine ,
38+ $ boundaries ,
39+ $ reserved
40+ ) {
41+ $ reservedArray = [];
42+
43+ if (Reserved::isReservedPrecededByDotCharacter ($ previous )) {
44+ if (Reserved::isReservedString ($ string , $ matches , $ reservedTopLevel , $ boundaries )) {
45+ $ reservedArray = Reserved::getReservedTopLevelString ($ string , $ matches );
46+ }
47+
48+ if (empty ($ reservedArray ) && Reserved::isReservedString ($ string , $ matches , $ reservedNewLine , $ boundaries )) {
49+ $ reservedArray = Reserved::getReservedNewLineString ($ string , $ matches );
50+ }
51+
52+ if (empty ($ reservedArray ) && Reserved::isReservedString ($ string , $ matches , $ reserved , $ boundaries )) {
53+ $ reservedArray = Reserved::getReservedString ($ string , $ matches );
54+ }
55+ }
56+
57+ return $ reservedArray ;
58+ }
59+
2160 /**
2261 * A reserved word cannot be preceded by a "." in order to differentiate "mytable.from" from the token "from".
2362 *
@@ -30,45 +69,47 @@ public static function isReservedPrecededByDotCharacter($previous)
3069 return !$ previous || !isset ($ previous [Tokenizer::TOKEN_VALUE ]) || $ previous [Tokenizer::TOKEN_VALUE ] !== '. ' ;
3170 }
3271
33-
3472 /**
35- * @param string $string
36- * @param array $matches
73+ * @param string $upper
74+ * @param array $matches
75+ * @param string $regexReserved
76+ * @param string $regexBoundaries
3777 *
38- * @return array
78+ * @return bool
3979 */
40- public static function getReservedTopLevelString ( $ string , array &$ matches )
80+ public static function isReservedString ( $ upper , array &$ matches, $ regexReserved , $ regexBoundaries )
4181 {
42- return self ::getStringTypeArray (Tokenizer::TOKEN_TYPE_RESERVED_TOP_LEVEL , $ string , $ matches );
82+ return 1 == preg_match (
83+ '/^( ' . $ regexReserved . ')($|\s| ' . $ regexBoundaries . ')/ ' ,
84+ strtoupper ($ upper ),
85+ $ matches
86+ );
4387 }
4488
45-
4689 /**
4790 * @param string $string
4891 * @param array $matches
4992 *
5093 * @return array
5194 */
52- public static function getReservedNewLineString ($ string , array &$ matches )
95+ public static function getReservedTopLevelString ($ string , array &$ matches )
5396 {
54- return self ::getStringTypeArray (Tokenizer::TOKEN_TYPE_RESERVED_NEWLINE , strtoupper ( $ string) , $ matches );
97+ return self ::getStringTypeArray (Tokenizer::TOKEN_TYPE_RESERVED_TOP_LEVEL , $ string , $ matches );
5598 }
5699
57100 /**
58- * @param string $upper
101+ * @param $type
102+ * @param string $string
59103 * @param array $matches
60- * @param string $regexReserved
61- * @param string $regexBoundaries
62104 *
63- * @return bool
105+ * @return array
64106 */
65- public static function isReservedString ( $ upper , array & $ matches , $ regexReserved , $ regexBoundaries )
107+ protected static function getStringTypeArray ( $ type , $ string , array & $ matches )
66108 {
67- return 1 == preg_match (
68- '/^( ' . $ regexReserved . ')($|\s| ' . $ regexBoundaries . ')/ ' ,
69- strtoupper ($ upper ),
70- $ matches
71- );
109+ return [
110+ Tokenizer::TOKEN_TYPE => $ type ,
111+ Tokenizer::TOKEN_VALUE => substr ($ string , 0 , strlen ($ matches [1 ]))
112+ ];
72113 }
73114
74115 /**
@@ -77,23 +118,19 @@ public static function isReservedString($upper, array &$matches, $regexReserved,
77118 *
78119 * @return array
79120 */
80- public static function getReservedString ($ string , array &$ matches )
121+ public static function getReservedNewLineString ($ string , array &$ matches )
81122 {
82- return self ::getStringTypeArray (Tokenizer::TOKEN_TYPE_RESERVED , $ string , $ matches );
123+ return self ::getStringTypeArray (Tokenizer::TOKEN_TYPE_RESERVED_NEWLINE , strtoupper ( $ string) , $ matches );
83124 }
84125
85126 /**
86- * @param $type
87127 * @param string $string
88- * @param array $matches
128+ * @param array $matches
89129 *
90130 * @return array
91131 */
92- protected static function getStringTypeArray ( $ type , $ string , array &$ matches )
132+ public static function getReservedString ( $ string , array &$ matches )
93133 {
94- return [
95- Tokenizer::TOKEN_TYPE => $ type ,
96- Tokenizer::TOKEN_VALUE => substr ($ string , 0 , strlen ($ matches [1 ]))
97- ];
134+ return self ::getStringTypeArray (Tokenizer::TOKEN_TYPE_RESERVED , $ string , $ matches );
98135 }
99136}
0 commit comments