diff options
Diffstat (limited to 'vendor/doctrine/orm/src/Query/AST/Node.php')
| -rw-r--r-- | vendor/doctrine/orm/src/Query/AST/Node.php | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Query/AST/Node.php b/vendor/doctrine/orm/src/Query/AST/Node.php new file mode 100644 index 0000000..cdb5855 --- /dev/null +++ b/vendor/doctrine/orm/src/Query/AST/Node.php | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Query\AST; | ||
| 6 | |||
| 7 | use Doctrine\ORM\Query\SqlWalker; | ||
| 8 | use Stringable; | ||
| 9 | |||
| 10 | use function get_debug_type; | ||
| 11 | use function get_object_vars; | ||
| 12 | use function is_array; | ||
| 13 | use function is_object; | ||
| 14 | use function str_repeat; | ||
| 15 | use function var_export; | ||
| 16 | |||
| 17 | use const PHP_EOL; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Abstract class of an AST node. | ||
| 21 | * | ||
| 22 | * @link www.doctrine-project.org | ||
| 23 | */ | ||
| 24 | abstract class Node implements Stringable | ||
| 25 | { | ||
| 26 | /** | ||
| 27 | * Double-dispatch method, supposed to dispatch back to the walker. | ||
| 28 | * | ||
| 29 | * Implementation is not mandatory for all nodes. | ||
| 30 | * | ||
| 31 | * @throws ASTException | ||
| 32 | */ | ||
| 33 | public function dispatch(SqlWalker $walker): string | ||
| 34 | { | ||
| 35 | throw ASTException::noDispatchForNode($this); | ||
| 36 | } | ||
| 37 | |||
| 38 | /** | ||
| 39 | * Dumps the AST Node into a string representation for information purpose only. | ||
| 40 | */ | ||
| 41 | public function __toString(): string | ||
| 42 | { | ||
| 43 | return $this->dump($this); | ||
| 44 | } | ||
| 45 | |||
| 46 | public function dump(mixed $value): string | ||
| 47 | { | ||
| 48 | static $ident = 0; | ||
| 49 | |||
| 50 | $str = ''; | ||
| 51 | |||
| 52 | if ($value instanceof Node) { | ||
| 53 | $str .= get_debug_type($value) . '(' . PHP_EOL; | ||
| 54 | $props = get_object_vars($value); | ||
| 55 | |||
| 56 | foreach ($props as $name => $prop) { | ||
| 57 | $ident += 4; | ||
| 58 | $str .= str_repeat(' ', $ident) . '"' . $name . '": ' | ||
| 59 | . $this->dump($prop) . ',' . PHP_EOL; | ||
| 60 | $ident -= 4; | ||
| 61 | } | ||
| 62 | |||
| 63 | $str .= str_repeat(' ', $ident) . ')'; | ||
| 64 | } elseif (is_array($value)) { | ||
| 65 | $ident += 4; | ||
| 66 | $str .= 'array('; | ||
| 67 | $some = false; | ||
| 68 | |||
| 69 | foreach ($value as $k => $v) { | ||
| 70 | $str .= PHP_EOL . str_repeat(' ', $ident) . '"' | ||
| 71 | . $k . '" => ' . $this->dump($v) . ','; | ||
| 72 | $some = true; | ||
| 73 | } | ||
| 74 | |||
| 75 | $ident -= 4; | ||
| 76 | $str .= ($some ? PHP_EOL . str_repeat(' ', $ident) : '') . ')'; | ||
| 77 | } elseif (is_object($value)) { | ||
| 78 | $str .= 'instanceof(' . get_debug_type($value) . ')'; | ||
| 79 | } else { | ||
| 80 | $str .= var_export($value, true); | ||
| 81 | } | ||
| 82 | |||
| 83 | return $str; | ||
| 84 | } | ||
| 85 | } | ||
