|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Doctrine Behavioral Extensions package. |
| 5 | + * (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace Gedmo\Tool\ORM\Walker; |
| 11 | + |
| 12 | +use Doctrine\ORM\Query\AST; |
| 13 | +use Doctrine\ORM\Query\AST\DeleteClause; |
| 14 | +use Doctrine\ORM\Query\AST\FromClause; |
| 15 | +use Doctrine\ORM\Query\AST\GroupByClause; |
| 16 | +use Doctrine\ORM\Query\AST\HavingClause; |
| 17 | +use Doctrine\ORM\Query\AST\OrderByClause; |
| 18 | +use Doctrine\ORM\Query\AST\SelectClause; |
| 19 | +use Doctrine\ORM\Query\AST\SelectStatement; |
| 20 | +use Doctrine\ORM\Query\AST\SimpleSelectClause; |
| 21 | +use Doctrine\ORM\Query\AST\SubselectFromClause; |
| 22 | +use Doctrine\ORM\Query\AST\WhereClause; |
| 23 | +use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; |
| 24 | +use Doctrine\ORM\Query\SqlWalker; |
| 25 | + |
| 26 | +/** |
| 27 | + * Helper trait to address compatibility issues between ORM 2.x and 3.x. |
| 28 | + * |
| 29 | + * @mixin SqlWalker |
| 30 | + * |
| 31 | + * @internal |
| 32 | + */ |
| 33 | +trait SqlWalkerCompat |
| 34 | +{ |
| 35 | + /** |
| 36 | + * Gets an executor that can be used to execute the result of this walker. |
| 37 | + * |
| 38 | + * @param SelectStatement|AST\UpdateStatement|AST\DeleteStatement $statement |
| 39 | + * |
| 40 | + * @return AbstractSqlExecutor |
| 41 | + */ |
| 42 | + public function getExecutor($statement) |
| 43 | + { |
| 44 | + return $this->doGetExecutorWithCompat($statement); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Walks down a SelectStatement AST node, thereby generating the appropriate SQL. |
| 49 | + * |
| 50 | + * @param SelectStatement $selectStatement |
| 51 | + * |
| 52 | + * @return string |
| 53 | + */ |
| 54 | + public function walkSelectStatement($selectStatement) |
| 55 | + { |
| 56 | + return $this->doWalkSelectStatementWithCompat($selectStatement); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Walks down a SelectClause AST node, thereby generating the appropriate SQL. |
| 61 | + * |
| 62 | + * @param SelectClause $selectClause |
| 63 | + * |
| 64 | + * @return string |
| 65 | + */ |
| 66 | + public function walkSelectClause($selectClause) |
| 67 | + { |
| 68 | + return $this->doWalkSelectClauseWithCompat($selectClause); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Walks down a FromClause AST node, thereby generating the appropriate SQL. |
| 73 | + * |
| 74 | + * @param FromClause $fromClause |
| 75 | + * |
| 76 | + * @return string |
| 77 | + */ |
| 78 | + public function walkFromClause($fromClause) |
| 79 | + { |
| 80 | + return $this->doWalkFromClauseWithCompat($fromClause); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Walks down a OrderByClause AST node, thereby generating the appropriate SQL. |
| 85 | + * |
| 86 | + * @param OrderByClause $orderByClause |
| 87 | + * |
| 88 | + * @return string |
| 89 | + */ |
| 90 | + public function walkOrderByClause($orderByClause) |
| 91 | + { |
| 92 | + return $this->doWalkOrderByClauseWithCompat($orderByClause); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Walks down a HavingClause AST node, thereby generating the appropriate SQL. |
| 97 | + * |
| 98 | + * @param HavingClause $havingClause |
| 99 | + * |
| 100 | + * @return string |
| 101 | + */ |
| 102 | + public function walkHavingClause($havingClause) |
| 103 | + { |
| 104 | + return $this->doWalkHavingClauseWithCompat($havingClause); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Walks down a SubselectFromClause AST node, thereby generating the appropriate SQL. |
| 109 | + * |
| 110 | + * @param SubselectFromClause $subselectFromClause |
| 111 | + * |
| 112 | + * @return string |
| 113 | + */ |
| 114 | + public function walkSubselectFromClause($subselectFromClause) |
| 115 | + { |
| 116 | + return $this->doWalkSubselectFromClauseWithCompat($subselectFromClause); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Walks down a SimpleSelectClause AST node, thereby generating the appropriate SQL. |
| 121 | + * |
| 122 | + * @param SimpleSelectClause $simpleSelectClause |
| 123 | + * |
| 124 | + * @return string |
| 125 | + */ |
| 126 | + public function walkSimpleSelectClause($simpleSelectClause) |
| 127 | + { |
| 128 | + return $this->doWalkSimpleSelectClauseWithCompat($simpleSelectClause); |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Walks down a GroupByClause AST node, thereby generating the appropriate SQL. |
| 133 | + * |
| 134 | + * @param GroupByClause $groupByClause |
| 135 | + * |
| 136 | + * @return string |
| 137 | + */ |
| 138 | + public function walkGroupByClause($groupByClause) |
| 139 | + { |
| 140 | + return $this->doWalkGroupByClauseWithCompat($groupByClause); |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Walks down a DeleteClause AST node, thereby generating the appropriate SQL. |
| 145 | + * |
| 146 | + * @param DeleteClause $deleteClause |
| 147 | + * |
| 148 | + * @return string |
| 149 | + */ |
| 150 | + public function walkDeleteClause($deleteClause) |
| 151 | + { |
| 152 | + return $this->doWalkDeleteClauseWithCompat($deleteClause); |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * Walks down a WhereClause AST node, thereby generating the appropriate SQL. |
| 157 | + * |
| 158 | + * WhereClause or not, the appropriate discriminator sql is added. |
| 159 | + * |
| 160 | + * @param WhereClause|null $whereClause |
| 161 | + * |
| 162 | + * @return string |
| 163 | + */ |
| 164 | + public function walkWhereClause($whereClause) |
| 165 | + { |
| 166 | + return $this->doWalkWhereClauseWithCompat($whereClause); |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * Gets an executor that can be used to execute the result of this walker. |
| 171 | + * |
| 172 | + * @param SelectStatement|AST\UpdateStatement|AST\DeleteStatement $statement |
| 173 | + */ |
| 174 | + protected function doGetExecutorWithCompat($statement): AbstractSqlExecutor |
| 175 | + { |
| 176 | + return parent::getExecutor($statement); |
| 177 | + } |
| 178 | + |
| 179 | + protected function doWalkSelectStatementWithCompat(SelectStatement $selectStatement): string |
| 180 | + { |
| 181 | + return parent::walkSelectStatement($selectStatement); |
| 182 | + } |
| 183 | + |
| 184 | + protected function doWalkSelectClauseWithCompat(SelectClause $selectClause): string |
| 185 | + { |
| 186 | + return parent::walkSelectClause($selectClause); |
| 187 | + } |
| 188 | + |
| 189 | + protected function doWalkFromClauseWithCompat(FromClause $fromClause): string |
| 190 | + { |
| 191 | + return parent::walkFromClause($fromClause); |
| 192 | + } |
| 193 | + |
| 194 | + protected function doWalkOrderByClauseWithCompat(OrderByClause $orderByClause): string |
| 195 | + { |
| 196 | + return parent::walkOrderByClause($orderByClause); |
| 197 | + } |
| 198 | + |
| 199 | + protected function doWalkHavingClauseWithCompat(HavingClause $havingClause): string |
| 200 | + { |
| 201 | + return parent::walkHavingClause($havingClause); |
| 202 | + } |
| 203 | + |
| 204 | + protected function doWalkSubselectFromClauseWithCompat(SubselectFromClause $subselectFromClause): string |
| 205 | + { |
| 206 | + return parent::walkSubselectFromClause($subselectFromClause); |
| 207 | + } |
| 208 | + |
| 209 | + protected function doWalkSimpleSelectClauseWithCompat(SimpleSelectClause $simpleSelectClause): string |
| 210 | + { |
| 211 | + return parent::walkSimpleSelectClause($simpleSelectClause); |
| 212 | + } |
| 213 | + |
| 214 | + protected function doWalkGroupByClauseWithCompat(GroupByClause $groupByClause): string |
| 215 | + { |
| 216 | + return parent::walkGroupByClause($groupByClause); |
| 217 | + } |
| 218 | + |
| 219 | + protected function doWalkDeleteClauseWithCompat(DeleteClause $deleteClause): string |
| 220 | + { |
| 221 | + return parent::walkDeleteClause($deleteClause); |
| 222 | + } |
| 223 | + |
| 224 | + protected function doWalkWhereClauseWithCompat(?WhereClause $whereClause): string |
| 225 | + { |
| 226 | + return parent::walkWhereClause($whereClause); |
| 227 | + } |
| 228 | +} |
0 commit comments