|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Query\AST; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Query\SqlWalker; |
|
8
|
|
|
use const PHP_EOL; |
|
9
|
|
|
use function get_class; |
|
10
|
|
|
use function get_object_vars; |
|
11
|
|
|
use function is_array; |
|
12
|
|
|
use function is_object; |
|
13
|
|
|
use function str_repeat; |
|
14
|
|
|
use function var_export; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Abstract class of an AST node. |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class Node |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Double-dispatch method, supposed to dispatch back to the walker. |
|
23
|
|
|
* |
|
24
|
|
|
* Implementation is not mandatory for all nodes. |
|
25
|
|
|
* |
|
26
|
|
|
* @param SqlWalker $walker |
|
27
|
|
|
* |
|
28
|
|
|
* @throws ASTException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function dispatch($walker) |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
throw ASTException::noDispatchForNode($this); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Dumps the AST Node into a string representation for information purpose only. |
|
37
|
|
|
* |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __toString() |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->dump($this); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param object $obj |
|
47
|
|
|
* |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
public function dump($obj) |
|
51
|
|
|
{ |
|
52
|
|
|
static $ident = 0; |
|
53
|
|
|
|
|
54
|
|
|
$str = ''; |
|
55
|
|
|
|
|
56
|
|
|
if ($obj instanceof Node) { |
|
57
|
|
|
$str .= get_class($obj) . '(' . PHP_EOL; |
|
58
|
|
|
$props = get_object_vars($obj); |
|
59
|
|
|
|
|
60
|
|
|
foreach ($props as $name => $prop) { |
|
61
|
|
|
$ident += 4; |
|
62
|
|
|
$str .= str_repeat(' ', $ident) . '"' . $name . '": ' |
|
63
|
|
|
. $this->dump($prop) . ',' . PHP_EOL; |
|
64
|
|
|
$ident -= 4; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$str .= str_repeat(' ', $ident) . ')'; |
|
68
|
|
|
} elseif (is_array($obj)) { |
|
|
|
|
|
|
69
|
|
|
$ident += 4; |
|
70
|
|
|
$str .= 'array('; |
|
71
|
|
|
$some = false; |
|
72
|
|
|
|
|
73
|
|
|
foreach ($obj as $k => $v) { |
|
74
|
|
|
$str .= PHP_EOL . str_repeat(' ', $ident) . '"' |
|
75
|
|
|
. $k . '" => ' . $this->dump($v) . ','; |
|
76
|
|
|
$some = true; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$ident -= 4; |
|
80
|
|
|
$str .= ($some ? PHP_EOL . str_repeat(' ', $ident) : '') . ')'; |
|
81
|
|
|
} elseif (is_object($obj)) { |
|
82
|
|
|
$str .= 'instanceof(' . get_class($obj) . ')'; |
|
83
|
|
|
} else { |
|
84
|
|
|
$str .= var_export($obj, true); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $str; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.