1919abstract class EsqlBase {
2020 private ?EsqlBase $ parent = null ;
2121
22+ protected function format_id (string $ id , bool $ allow_patterns = false ): string
23+ {
24+ if ($ allow_patterns && str_contains ($ id , "* " )) {
25+ // patterns cannot be escaped
26+ return $ id ;
27+ }
28+ if (preg_match ("/[A-Za-z_@][A-Za-z0-9_ \\.]*/ " , $ id )) {
29+ // all safe characters, so no need to escape
30+ return $ id ;
31+ }
32+ // apply escaping
33+ return "` " . str_replace ("` " , "`` " , $ id ) . "` " ;
34+ }
35+
2236 protected function format_kv (array $ map ): string
2337 {
2438 return implode (", " , array_map (
2539 function ($ k , $ v ) {
26- return $ k . "= " . json_encode ($ v );
40+ return $ k . " = " . json_encode ($ v );
2741 },
2842 array_keys ($ map ),
2943 $ map ,
3044 ));
3145 }
3246
33- public function render (): string
34- {
35- $ query = "" ;
36- if ($ this ->parent ) {
37- $ query .= $ this ->parent ->render () . "\n| " ;
38- }
39- $ query .= $ this ->render_internal ();
40- return $ query ;
41- }
42-
43- protected abstract function render_internal (): string ;
44-
45- public function __construct (?EsqlBase $ parent )
46- {
47- $ this ->parent = $ parent ;
48- }
49-
50- public function __toString (): string
51- {
52- return $ this ->render () . "\n" ;
53- }
54-
5547 protected function is_named_argument_list (array $ args ): bool {
5648 $ named_count = array_sum (array_map ('is_string ' , array_keys ($ args )));
5749 if ($ named_count == sizeof ($ args )) {
@@ -63,20 +55,6 @@ protected function is_named_argument_list(array $args): bool {
6355 return false ;
6456 }
6557
66- protected function format_id (string $ id , bool $ allow_patterns = false ): string
67- {
68- if ($ allow_patterns && str_contains ($ id , "* " )) {
69- // patterns cannot be escaped
70- return $ id ;
71- }
72- if (preg_match ("/[A-Za-z_@][A-Za-z0-9_ \\.]*/ " , $ id )) {
73- // all safe characters, so no need to escape
74- return $ id ;
75- }
76- // apply escaping
77- return "` " . str_replace ("` " , "`` " , $ id ) . "` " ;
78- }
79-
8058 protected function is_forked (): bool
8159 {
8260 if (get_class ($ this ) == "ForkCommand " ) {
@@ -88,6 +66,28 @@ protected function is_forked(): bool
8866 return false ;
8967 }
9068
69+ public function __construct (?EsqlBase $ parent )
70+ {
71+ $ this ->parent = $ parent ;
72+ }
73+
74+ public function render (): string
75+ {
76+ $ query = "" ;
77+ if ($ this ->parent ) {
78+ $ query .= $ this ->parent ->render () . "\n| " ;
79+ }
80+ $ query .= $ this ->renderInternal ();
81+ return $ query ;
82+ }
83+
84+ protected abstract function renderInternal (): string ;
85+
86+ public function __toString (): string
87+ {
88+ return $ this ->render () . "\n" ;
89+ }
90+
9191 /**
9292 * `CHANGE_POINT` detects spikes, dips, and change points in a metric.
9393 *
@@ -105,7 +105,7 @@ protected function is_forked(): bool
105105 * .where("type IS NOT NULL")
106106 * )
107107 */
108- public function change_point (string $ value ): ChangePointCommand
108+ public function changePoint (string $ value ): ChangePointCommand
109109 {
110110 return new ChangePointCommand ($ this , $ value );
111111 }
@@ -394,7 +394,7 @@ public function limit(int $max_number_of_rows): LimitCommand
394394 * .lookup_join("languages_lookup").on("language_code")
395395 * )
396396 */
397- public function lookup_join (string $ lookup_index ): LookupJoinCommand
397+ public function lookupJoin (string $ lookup_index ): LookupJoinCommand
398398 {
399399 return new LookupJoinCommand ($ this , $ lookup_index );
400400 }
@@ -409,7 +409,7 @@ public function lookup_join(string $lookup_index): LookupJoinCommand
409409 *
410410 * query = ESQL.row(a=[1, 2, 3], b="b", j=["a", "b"]).mv_expand("a")
411411 */
412- public function mv_expand (string $ column ): MvExpandCommand
412+ public function mvExpand (string $ column ): MvExpandCommand
413413 {
414414 return new MvExpandCommand ($ this , $ column );
415415 }
0 commit comments