1 | <?php |
||
18 | class Quoter |
||
19 | { |
||
20 | /** |
||
21 | * |
||
22 | * The prefix to use when quoting identifier names. |
||
23 | * |
||
24 | * @var string |
||
25 | * |
||
26 | */ |
||
27 | protected $quote_name_prefix = '"'; |
||
28 | |||
29 | /** |
||
30 | * |
||
31 | * The suffix to use when quoting identifier names. |
||
32 | * |
||
33 | * @var string |
||
34 | * |
||
35 | */ |
||
36 | protected $quote_name_suffix = '"'; |
||
37 | |||
38 | /** |
||
39 | * |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param string $quote_name_prefix The prefix to use when quoting |
||
43 | * identifier names. |
||
44 | * |
||
45 | * @param string $quote_name_suffix The suffix to use when quoting |
||
46 | * identifier names. |
||
47 | * |
||
48 | */ |
||
49 | 389 | public function __construct($quote_name_prefix, $quote_name_suffix) |
|
54 | |||
55 | /** |
||
56 | * |
||
57 | * Returns the prefix to use when quoting identifier names. |
||
58 | * |
||
59 | * @return string |
||
60 | * |
||
61 | */ |
||
62 | 241 | public function getQuoteNamePrefix() |
|
66 | |||
67 | /** |
||
68 | * |
||
69 | * Returns the suffix to use when quoting identifier names. |
||
70 | * |
||
71 | * @return string |
||
72 | * |
||
73 | */ |
||
74 | 241 | public function getQuoteNameSuffix() |
|
78 | |||
79 | /** |
||
80 | * |
||
81 | * Quotes a single identifier name (table, table alias, table column, |
||
82 | * index, sequence). |
||
83 | * |
||
84 | * If the name contains `' AS '`, this method will separately quote the |
||
85 | * parts before and after the `' AS '`. |
||
86 | * |
||
87 | * If the name contains a space, this method will separately quote the |
||
88 | * parts before and after the space. |
||
89 | * |
||
90 | * If the name contains a dot, this method will separately quote the |
||
91 | * parts before and after the dot. |
||
92 | * |
||
93 | * @param string $spec The identifier name to quote. |
||
94 | * |
||
95 | * @return string|array The quoted identifier name. |
||
96 | * |
||
97 | * @see replaceName() |
||
98 | * |
||
99 | * @see quoteNameWithSeparator() |
||
100 | * |
||
101 | */ |
||
102 | 212 | public function quoteName($spec) |
|
114 | |||
115 | /** |
||
116 | * |
||
117 | * Quotes an identifier that has a separator. |
||
118 | * |
||
119 | * @param string $spec The identifier name to quote. |
||
120 | * |
||
121 | * @param string $sep The separator, typically a dot or space. |
||
122 | * |
||
123 | * @param int $pos The position of the separator. |
||
124 | * |
||
125 | * @return string The quoted identifier name. |
||
126 | * |
||
127 | */ |
||
128 | 26 | protected function quoteNameWithSeparator($spec, $sep, $pos) |
|
135 | |||
136 | /** |
||
137 | * |
||
138 | * Quotes all fully-qualified identifier names ("table.col") in a string, |
||
139 | * typically an SQL snippet for a SELECT clause. |
||
140 | * |
||
141 | * Does not quote identifier names that are string literals (i.e., inside |
||
142 | * single or double quotes). |
||
143 | * |
||
144 | * Looks for a trailing ' AS alias' and quotes the alias as well. |
||
145 | * |
||
146 | * @param string $text The string in which to quote fully-qualified |
||
147 | * identifier names to quote. |
||
148 | * |
||
149 | * @return string|array The string with names quoted in it. |
||
150 | * |
||
151 | * @see replaceNamesIn() |
||
152 | * |
||
153 | */ |
||
154 | 228 | public function quoteNamesIn($text) |
|
170 | |||
171 | /** |
||
172 | * |
||
173 | * Returns a list of candidate elements for quoting. |
||
174 | * |
||
175 | * @param string $text The text to split into quoting candidates. |
||
176 | * |
||
177 | * @return array |
||
178 | * |
||
179 | */ |
||
180 | 228 | protected function getListForQuoteNamesIn($text) |
|
193 | |||
194 | /** |
||
195 | * |
||
196 | * The in-loop functionality for quoting identifier names. |
||
197 | * |
||
198 | * @param string $val The name to be quoted. |
||
199 | * |
||
200 | * @param bool $is_last Is this the last loop? |
||
201 | * |
||
202 | * @return string The quoted name. |
||
203 | * |
||
204 | */ |
||
205 | 228 | protected function quoteNamesInLoop($val, $is_last) |
|
212 | |||
213 | /** |
||
214 | * |
||
215 | * Replaces the names and alias in a string. |
||
216 | * |
||
217 | * @param string $val The name to be quoted. |
||
218 | * |
||
219 | * @return string The quoted name. |
||
220 | * |
||
221 | */ |
||
222 | 228 | protected function replaceNamesAndAliasIn($val) |
|
232 | |||
233 | /** |
||
234 | * |
||
235 | * Quotes an identifier name (table, index, etc); ignores empty values and |
||
236 | * values of '*'. |
||
237 | * |
||
238 | * @param string $name The identifier name to quote. |
||
239 | * |
||
240 | * @return string The quoted identifier name. |
||
241 | * |
||
242 | * @see quoteName() |
||
243 | * |
||
244 | */ |
||
245 | 223 | protected function replaceName($name) |
|
256 | |||
257 | /** |
||
258 | * |
||
259 | * Quotes all fully-qualified identifier names ("table.col") in a string. |
||
260 | * |
||
261 | * @param string $text The string in which to quote fully-qualified |
||
262 | * identifier names to quote. |
||
263 | * |
||
264 | * @return string|array The string with names quoted in it. |
||
265 | * |
||
266 | * @see quoteNamesIn() |
||
267 | * |
||
268 | */ |
||
269 | 228 | protected function replaceNamesIn($text) |
|
296 | |||
297 | } |
||
298 |