|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\ORM\Query\AST; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Abstract class of an AST node. |
|
24
|
|
|
* |
|
25
|
|
|
* @link www.doctrine-project.org |
|
26
|
|
|
* @since 2.0 |
|
27
|
|
|
* @author Guilherme Blanco <[email protected]> |
|
28
|
|
|
* @author Jonathan Wage <[email protected]> |
|
29
|
|
|
* @author Roman Borschel <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
|
|
abstract class Node |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Double-dispatch method, supposed to dispatch back to the walker. |
|
35
|
|
|
* |
|
36
|
|
|
* Implementation is not mandatory for all nodes. |
|
37
|
|
|
* |
|
38
|
|
|
* @param \Doctrine\ORM\Query\SqlWalker $walker |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
* |
|
42
|
|
|
* @throws ASTException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function dispatch($walker) |
|
45
|
|
|
{ |
|
46
|
|
|
throw ASTException::noDispatchForNode($this); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Dumps the AST Node into a string representation for information purpose only. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __toString() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->dump($this); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param object $obj |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
|
|
public function dump($obj) |
|
65
|
|
|
{ |
|
66
|
|
|
static $ident = 0; |
|
67
|
|
|
|
|
68
|
|
|
$str = ''; |
|
69
|
|
|
|
|
70
|
|
|
if ($obj instanceof Node) { |
|
71
|
|
|
$str .= get_class($obj) . '(' . PHP_EOL; |
|
72
|
|
|
$props = get_object_vars($obj); |
|
73
|
|
|
|
|
74
|
|
|
foreach ($props as $name => $prop) { |
|
75
|
|
|
$ident += 4; |
|
76
|
|
|
$str .= str_repeat(' ', $ident) . '"' . $name . '": ' |
|
77
|
|
|
. $this->dump($prop) . ',' . PHP_EOL; |
|
78
|
|
|
$ident -= 4; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$str .= str_repeat(' ', $ident) . ')'; |
|
82
|
|
|
} else if (is_array($obj)) { |
|
83
|
|
|
$ident += 4; |
|
84
|
|
|
$str .= 'array('; |
|
85
|
|
|
$some = false; |
|
86
|
|
|
|
|
87
|
|
|
foreach ($obj as $k => $v) { |
|
88
|
|
|
$str .= PHP_EOL . str_repeat(' ', $ident) . '"' |
|
89
|
|
|
. $k . '" => ' . $this->dump($v) . ','; |
|
90
|
|
|
$some = true; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$ident -= 4; |
|
94
|
|
|
$str .= ($some ? PHP_EOL . str_repeat(' ', $ident) : '') . ')'; |
|
95
|
|
|
} else if (is_object($obj)) { |
|
96
|
|
|
$str .= 'instanceof(' . get_class($obj) . ')'; |
|
97
|
|
|
} else { |
|
98
|
|
|
$str .= var_export($obj, true); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $str; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|