Created
May 6, 2019 11:50
-
-
Save slifin/066fbc097f39f8bcce8327bc404de893 to your computer and use it in GitHub Desktop.
part 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $data = | |
| [':select' => [':a', ':b', [':select' => [':c']]], | |
| ':from' => [':foo']]; | |
| function recur(array $map) : object { | |
| return new \RecursiveIteratorIterator( | |
| new \RecursiveArrayIterator($map), | |
| \RecursiveIteratorIterator::SELF_FIRST | |
| ); | |
| } | |
| function map_to_sql(array &$sql, object $map) : array { | |
| // $map = recur($map); | |
| foreach ($map as $key => $result) { | |
| switch (TRUE) { | |
| case $key === ':select': | |
| var_dump($result); | |
| $sql[] = 'SELECT ' . implode(' ', $result); | |
| break; | |
| case $key === ':from': | |
| $sql[] = 'FROM ' . implode(' ', $result); | |
| break; | |
| } | |
| } | |
| return $sql; | |
| } | |
| function has_key(object $map, string $key) : bool { | |
| return isset($map->{$key}); | |
| } | |
| $sql = []; | |
| $out = map_to_sql($sql, recur($data)); | |
| $out = implode("\n", $out); | |
| var_dump($out); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment