TreeWalker.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. namespace Doctrine\ORM\Query;
  20. use Doctrine\ORM\AbstractQuery;
  21. use Doctrine\ORM\Mapping\ClassMetadata;
  22. /**
  23. * Interface for walkers of DQL ASTs (abstract syntax trees).
  24. */
  25. interface TreeWalker
  26. {
  27. /**
  28. * Initializes TreeWalker with important information about the ASTs to be walked.
  29. *
  30. * @param AbstractQuery $query The parsed Query.
  31. * @param ParserResult $parserResult The result of the parsing process.
  32. * @param mixed[] $queryComponents The query components (symbol table).
  33. */
  34. public function __construct($query, $parserResult, array $queryComponents);
  35. /**
  36. * Returns internal queryComponents array.
  37. *
  38. * @return array<string, array<string, mixed>>
  39. *
  40. * @psalm-return array<string, array{
  41. * metadata: ClassMetadata,
  42. * parent: string,
  43. * relation: mixed[],
  44. * map: mixed,
  45. * nestingLevel: int,
  46. * token: array
  47. * }>
  48. */
  49. public function getQueryComponents();
  50. /**
  51. * Sets or overrides a query component for a given dql alias.
  52. *
  53. * @param string $dqlAlias The DQL alias.
  54. * @param array<string, mixed> $queryComponent
  55. *
  56. * @return void
  57. */
  58. public function setQueryComponent($dqlAlias, array $queryComponent);
  59. /**
  60. * Walks down a SelectStatement AST node, thereby generating the appropriate SQL.
  61. *
  62. * @return string The SQL.
  63. */
  64. public function walkSelectStatement(AST\SelectStatement $AST);
  65. /**
  66. * Walks down a SelectClause AST node, thereby generating the appropriate SQL.
  67. *
  68. * @param AST\SelectClause $selectClause
  69. *
  70. * @return string The SQL.
  71. */
  72. public function walkSelectClause($selectClause);
  73. /**
  74. * Walks down a FromClause AST node, thereby generating the appropriate SQL.
  75. *
  76. * @param AST\FromClause $fromClause
  77. *
  78. * @return string The SQL.
  79. */
  80. public function walkFromClause($fromClause);
  81. /**
  82. * Walks down a FunctionNode AST node, thereby generating the appropriate SQL.
  83. *
  84. * @param AST\Functions\FunctionNode $function
  85. *
  86. * @return string The SQL.
  87. */
  88. public function walkFunction($function);
  89. /**
  90. * Walks down an OrderByClause AST node, thereby generating the appropriate SQL.
  91. *
  92. * @param AST\OrderByClause $orderByClause
  93. *
  94. * @return string The SQL.
  95. */
  96. public function walkOrderByClause($orderByClause);
  97. /**
  98. * Walks down an OrderByItem AST node, thereby generating the appropriate SQL.
  99. *
  100. * @param AST\OrderByItem $orderByItem
  101. *
  102. * @return string The SQL.
  103. */
  104. public function walkOrderByItem($orderByItem);
  105. /**
  106. * Walks down a HavingClause AST node, thereby generating the appropriate SQL.
  107. *
  108. * @param AST\HavingClause $havingClause
  109. *
  110. * @return string The SQL.
  111. */
  112. public function walkHavingClause($havingClause);
  113. /**
  114. * Walks down a Join AST node and creates the corresponding SQL.
  115. *
  116. * @param AST\Join $join
  117. *
  118. * @return string The SQL.
  119. */
  120. public function walkJoin($join);
  121. /**
  122. * Walks down a SelectExpression AST node and generates the corresponding SQL.
  123. *
  124. * @param AST\SelectExpression $selectExpression
  125. *
  126. * @return string The SQL.
  127. */
  128. public function walkSelectExpression($selectExpression);
  129. /**
  130. * Walks down a QuantifiedExpression AST node, thereby generating the appropriate SQL.
  131. *
  132. * @param AST\QuantifiedExpression $qExpr
  133. *
  134. * @return string The SQL.
  135. */
  136. public function walkQuantifiedExpression($qExpr);
  137. /**
  138. * Walks down a Subselect AST node, thereby generating the appropriate SQL.
  139. *
  140. * @param AST\Subselect $subselect
  141. *
  142. * @return string The SQL.
  143. */
  144. public function walkSubselect($subselect);
  145. /**
  146. * Walks down a SubselectFromClause AST node, thereby generating the appropriate SQL.
  147. *
  148. * @param AST\SubselectFromClause $subselectFromClause
  149. *
  150. * @return string The SQL.
  151. */
  152. public function walkSubselectFromClause($subselectFromClause);
  153. /**
  154. * Walks down a SimpleSelectClause AST node, thereby generating the appropriate SQL.
  155. *
  156. * @param AST\SimpleSelectClause $simpleSelectClause
  157. *
  158. * @return string The SQL.
  159. */
  160. public function walkSimpleSelectClause($simpleSelectClause);
  161. /**
  162. * Walks down a SimpleSelectExpression AST node, thereby generating the appropriate SQL.
  163. *
  164. * @param AST\SimpleSelectExpression $simpleSelectExpression
  165. *
  166. * @return string The SQL.
  167. */
  168. public function walkSimpleSelectExpression($simpleSelectExpression);
  169. /**
  170. * Walks down an AggregateExpression AST node, thereby generating the appropriate SQL.
  171. *
  172. * @param AST\AggregateExpression $aggExpression
  173. *
  174. * @return string The SQL.
  175. */
  176. public function walkAggregateExpression($aggExpression);
  177. /**
  178. * Walks down a GroupByClause AST node, thereby generating the appropriate SQL.
  179. *
  180. * @param AST\GroupByClause $groupByClause
  181. *
  182. * @return string The SQL.
  183. */
  184. public function walkGroupByClause($groupByClause);
  185. /**
  186. * Walks down a GroupByItem AST node, thereby generating the appropriate SQL.
  187. *
  188. * @param AST\PathExpression|string $groupByItem
  189. *
  190. * @return string The SQL.
  191. */
  192. public function walkGroupByItem($groupByItem);
  193. /**
  194. * Walks down an UpdateStatement AST node, thereby generating the appropriate SQL.
  195. *
  196. * @return string The SQL.
  197. */
  198. public function walkUpdateStatement(AST\UpdateStatement $AST);
  199. /**
  200. * Walks down a DeleteStatement AST node, thereby generating the appropriate SQL.
  201. *
  202. * @return string The SQL.
  203. */
  204. public function walkDeleteStatement(AST\DeleteStatement $AST);
  205. /**
  206. * Walks down a DeleteClause AST node, thereby generating the appropriate SQL.
  207. *
  208. * @return string The SQL.
  209. */
  210. public function walkDeleteClause(AST\DeleteClause $deleteClause);
  211. /**
  212. * Walks down an UpdateClause AST node, thereby generating the appropriate SQL.
  213. *
  214. * @param AST\UpdateClause $updateClause
  215. *
  216. * @return string The SQL.
  217. */
  218. public function walkUpdateClause($updateClause);
  219. /**
  220. * Walks down an UpdateItem AST node, thereby generating the appropriate SQL.
  221. *
  222. * @param AST\UpdateItem $updateItem
  223. *
  224. * @return string The SQL.
  225. */
  226. public function walkUpdateItem($updateItem);
  227. /**
  228. * Walks down a WhereClause AST node, thereby generating the appropriate SQL.
  229. * WhereClause or not, the appropriate discriminator sql is added.
  230. *
  231. * @param AST\WhereClause $whereClause
  232. *
  233. * @return string The SQL.
  234. */
  235. public function walkWhereClause($whereClause);
  236. /**
  237. * Walk down a ConditionalExpression AST node, thereby generating the appropriate SQL.
  238. *
  239. * @param AST\ConditionalExpression $condExpr
  240. *
  241. * @return string The SQL.
  242. */
  243. public function walkConditionalExpression($condExpr);
  244. /**
  245. * Walks down a ConditionalTerm AST node, thereby generating the appropriate SQL.
  246. *
  247. * @param AST\ConditionalTerm $condTerm
  248. *
  249. * @return string The SQL.
  250. */
  251. public function walkConditionalTerm($condTerm);
  252. /**
  253. * Walks down a ConditionalFactor AST node, thereby generating the appropriate SQL.
  254. *
  255. * @param AST\ConditionalFactor $factor
  256. *
  257. * @return string The SQL.
  258. */
  259. public function walkConditionalFactor($factor);
  260. /**
  261. * Walks down a ConditionalPrimary AST node, thereby generating the appropriate SQL.
  262. *
  263. * @param AST\ConditionalPrimary $primary
  264. *
  265. * @return string The SQL.
  266. */
  267. public function walkConditionalPrimary($primary);
  268. /**
  269. * Walks down an ExistsExpression AST node, thereby generating the appropriate SQL.
  270. *
  271. * @param AST\ExistsExpression $existsExpr
  272. *
  273. * @return string The SQL.
  274. */
  275. public function walkExistsExpression($existsExpr);
  276. /**
  277. * Walks down a CollectionMemberExpression AST node, thereby generating the appropriate SQL.
  278. *
  279. * @param AST\CollectionMemberExpression $collMemberExpr
  280. *
  281. * @return string The SQL.
  282. */
  283. public function walkCollectionMemberExpression($collMemberExpr);
  284. /**
  285. * Walks down an EmptyCollectionComparisonExpression AST node, thereby generating the appropriate SQL.
  286. *
  287. * @param AST\EmptyCollectionComparisonExpression $emptyCollCompExpr
  288. *
  289. * @return string The SQL.
  290. */
  291. public function walkEmptyCollectionComparisonExpression($emptyCollCompExpr);
  292. /**
  293. * Walks down a NullComparisonExpression AST node, thereby generating the appropriate SQL.
  294. *
  295. * @param AST\NullComparisonExpression $nullCompExpr
  296. *
  297. * @return string The SQL.
  298. */
  299. public function walkNullComparisonExpression($nullCompExpr);
  300. /**
  301. * Walks down an InExpression AST node, thereby generating the appropriate SQL.
  302. *
  303. * @param AST\InExpression $inExpr
  304. *
  305. * @return string The SQL.
  306. */
  307. public function walkInExpression($inExpr);
  308. /**
  309. * Walks down an InstanceOfExpression AST node, thereby generating the appropriate SQL.
  310. *
  311. * @param AST\InstanceOfExpression $instanceOfExpr
  312. *
  313. * @return string The SQL.
  314. */
  315. public function walkInstanceOfExpression($instanceOfExpr);
  316. /**
  317. * Walks down a literal that represents an AST node, thereby generating the appropriate SQL.
  318. *
  319. * @param mixed $literal
  320. *
  321. * @return string The SQL.
  322. */
  323. public function walkLiteral($literal);
  324. /**
  325. * Walks down a BetweenExpression AST node, thereby generating the appropriate SQL.
  326. *
  327. * @param AST\BetweenExpression $betweenExpr
  328. *
  329. * @return string The SQL.
  330. */
  331. public function walkBetweenExpression($betweenExpr);
  332. /**
  333. * Walks down a LikeExpression AST node, thereby generating the appropriate SQL.
  334. *
  335. * @param AST\LikeExpression $likeExpr
  336. *
  337. * @return string The SQL.
  338. */
  339. public function walkLikeExpression($likeExpr);
  340. /**
  341. * Walks down a StateFieldPathExpression AST node, thereby generating the appropriate SQL.
  342. *
  343. * @param AST\PathExpression $stateFieldPathExpression
  344. *
  345. * @return string The SQL.
  346. */
  347. public function walkStateFieldPathExpression($stateFieldPathExpression);
  348. /**
  349. * Walks down a ComparisonExpression AST node, thereby generating the appropriate SQL.
  350. *
  351. * @param AST\ComparisonExpression $compExpr
  352. *
  353. * @return string The SQL.
  354. */
  355. public function walkComparisonExpression($compExpr);
  356. /**
  357. * Walks down an InputParameter AST node, thereby generating the appropriate SQL.
  358. *
  359. * @param AST\InputParameter $inputParam
  360. *
  361. * @return string The SQL.
  362. */
  363. public function walkInputParameter($inputParam);
  364. /**
  365. * Walks down an ArithmeticExpression AST node, thereby generating the appropriate SQL.
  366. *
  367. * @param AST\ArithmeticExpression $arithmeticExpr
  368. *
  369. * @return string The SQL.
  370. */
  371. public function walkArithmeticExpression($arithmeticExpr);
  372. /**
  373. * Walks down an ArithmeticTerm AST node, thereby generating the appropriate SQL.
  374. *
  375. * @param mixed $term
  376. *
  377. * @return string The SQL.
  378. */
  379. public function walkArithmeticTerm($term);
  380. /**
  381. * Walks down a StringPrimary that represents an AST node, thereby generating the appropriate SQL.
  382. *
  383. * @param mixed $stringPrimary
  384. *
  385. * @return string The SQL.
  386. */
  387. public function walkStringPrimary($stringPrimary);
  388. /**
  389. * Walks down an ArithmeticFactor that represents an AST node, thereby generating the appropriate SQL.
  390. *
  391. * @param mixed $factor
  392. *
  393. * @return string The SQL.
  394. */
  395. public function walkArithmeticFactor($factor);
  396. /**
  397. * Walks down an SimpleArithmeticExpression AST node, thereby generating the appropriate SQL.
  398. *
  399. * @param AST\SimpleArithmeticExpression $simpleArithmeticExpr
  400. *
  401. * @return string The SQL.
  402. */
  403. public function walkSimpleArithmeticExpression($simpleArithmeticExpr);
  404. /**
  405. * Walks down a PathExpression AST node, thereby generating the appropriate SQL.
  406. *
  407. * @param mixed $pathExpr
  408. *
  409. * @return string The SQL.
  410. */
  411. public function walkPathExpression($pathExpr);
  412. /**
  413. * Walks down a ResultVariable that represents an AST node, thereby generating the appropriate SQL.
  414. *
  415. * @param string $resultVariable
  416. *
  417. * @return string The SQL.
  418. */
  419. public function walkResultVariable($resultVariable);
  420. /**
  421. * Gets an executor that can be used to execute the result of this walker.
  422. *
  423. * @param AST\DeleteStatement|AST\UpdateStatement|AST\SelectStatement $AST
  424. *
  425. * @return Exec\AbstractSqlExecutor
  426. */
  427. public function getExecutor($AST);
  428. }