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