TreeWalker.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. /**
  21. * Interface for walkers of DQL ASTs (abstract syntax trees).
  22. *
  23. * @author Roman Borschel <roman@code-factory.org>
  24. * @since 2.0
  25. */
  26. interface TreeWalker
  27. {
  28. /**
  29. * Initializes TreeWalker with important information about the ASTs to be walked.
  30. *
  31. * @param \Doctrine\ORM\AbstractQuery $query The parsed Query.
  32. * @param \Doctrine\ORM\Query\ParserResult $parserResult The result of the parsing process.
  33. * @param array $queryComponents The query components (symbol table).
  34. */
  35. public function __construct($query, $parserResult, array $queryComponents);
  36. /**
  37. * Returns internal queryComponents array.
  38. *
  39. * @return array
  40. */
  41. public function getQueryComponents();
  42. /**
  43. * Sets or overrides a query component for a given dql alias.
  44. *
  45. * @param string $dqlAlias The DQL alias.
  46. * @param array $queryComponent
  47. *
  48. * @return void
  49. */
  50. public function setQueryComponent($dqlAlias, array $queryComponent);
  51. /**
  52. * Walks down a SelectStatement AST node, thereby generating the appropriate SQL.
  53. *
  54. * @param AST\SelectStatement $AST
  55. *
  56. * @return string The SQL.
  57. */
  58. function walkSelectStatement(AST\SelectStatement $AST);
  59. /**
  60. * Walks down a SelectClause AST node, thereby generating the appropriate SQL.
  61. *
  62. * @param AST\SelectClause $selectClause
  63. *
  64. * @return string The SQL.
  65. */
  66. function walkSelectClause($selectClause);
  67. /**
  68. * Walks down a FromClause AST node, thereby generating the appropriate SQL.
  69. *
  70. * @param AST\FromClause $fromClause
  71. *
  72. * @return string The SQL.
  73. */
  74. function walkFromClause($fromClause);
  75. /**
  76. * Walks down a FunctionNode AST node, thereby generating the appropriate SQL.
  77. *
  78. * @param AST\Functions\FunctionNode $function
  79. *
  80. * @return string The SQL.
  81. */
  82. function walkFunction($function);
  83. /**
  84. * Walks down an OrderByClause AST node, thereby generating the appropriate SQL.
  85. *
  86. * @param AST\OrderByClause $orderByClause
  87. *
  88. * @return string The SQL.
  89. */
  90. function walkOrderByClause($orderByClause);
  91. /**
  92. * Walks down an OrderByItem AST node, thereby generating the appropriate SQL.
  93. *
  94. * @param AST\OrderByItem $orderByItem
  95. *
  96. * @return string The SQL.
  97. */
  98. function walkOrderByItem($orderByItem);
  99. /**
  100. * Walks down a HavingClause AST node, thereby generating the appropriate SQL.
  101. *
  102. * @param AST\HavingClause $havingClause
  103. *
  104. * @return string The SQL.
  105. */
  106. function walkHavingClause($havingClause);
  107. /**
  108. * Walks down a Join AST node and creates the corresponding SQL.
  109. *
  110. * @param AST\Join $join
  111. *
  112. * @return string The SQL.
  113. */
  114. function walkJoin($join);
  115. /**
  116. * Walks down a SelectExpression AST node and generates the corresponding SQL.
  117. *
  118. * @param AST\SelectExpression $selectExpression
  119. *
  120. * @return string The SQL.
  121. */
  122. function walkSelectExpression($selectExpression);
  123. /**
  124. * Walks down a QuantifiedExpression AST node, thereby generating the appropriate SQL.
  125. *
  126. * @param AST\QuantifiedExpression $qExpr
  127. *
  128. * @return string The SQL.
  129. */
  130. function walkQuantifiedExpression($qExpr);
  131. /**
  132. * Walks down a Subselect AST node, thereby generating the appropriate SQL.
  133. *
  134. * @param AST\Subselect $subselect
  135. *
  136. * @return string The SQL.
  137. */
  138. function walkSubselect($subselect);
  139. /**
  140. * Walks down a SubselectFromClause AST node, thereby generating the appropriate SQL.
  141. *
  142. * @param AST\SubselectFromClause $subselectFromClause
  143. *
  144. * @return string The SQL.
  145. */
  146. function walkSubselectFromClause($subselectFromClause);
  147. /**
  148. * Walks down a SimpleSelectClause AST node, thereby generating the appropriate SQL.
  149. *
  150. * @param AST\SimpleSelectClause $simpleSelectClause
  151. *
  152. * @return string The SQL.
  153. */
  154. function walkSimpleSelectClause($simpleSelectClause);
  155. /**
  156. * Walks down a SimpleSelectExpression AST node, thereby generating the appropriate SQL.
  157. *
  158. * @param AST\SimpleSelectExpression $simpleSelectExpression
  159. *
  160. * @return string The SQL.
  161. */
  162. function walkSimpleSelectExpression($simpleSelectExpression);
  163. /**
  164. * Walks down an AggregateExpression AST node, thereby generating the appropriate SQL.
  165. *
  166. * @param AST\AggregateExpression $aggExpression
  167. *
  168. * @return string The SQL.
  169. */
  170. function walkAggregateExpression($aggExpression);
  171. /**
  172. * Walks down a GroupByClause AST node, thereby generating the appropriate SQL.
  173. *
  174. * @param AST\GroupByClause $groupByClause
  175. *
  176. * @return string The SQL.
  177. */
  178. function walkGroupByClause($groupByClause);
  179. /**
  180. * Walks down a GroupByItem AST node, thereby generating the appropriate SQL.
  181. *
  182. * @param AST\PathExpression|string $groupByItem
  183. *
  184. * @return string The SQL.
  185. */
  186. function walkGroupByItem($groupByItem);
  187. /**
  188. * Walks down an UpdateStatement AST node, thereby generating the appropriate SQL.
  189. *
  190. * @param AST\UpdateStatement $AST
  191. *
  192. * @return string The SQL.
  193. */
  194. function walkUpdateStatement(AST\UpdateStatement $AST);
  195. /**
  196. * Walks down a DeleteStatement AST node, thereby generating the appropriate SQL.
  197. *
  198. * @param AST\DeleteStatement $AST
  199. *
  200. * @return string The SQL.
  201. */
  202. function walkDeleteStatement(AST\DeleteStatement $AST);
  203. /**
  204. * Walks down a DeleteClause AST node, thereby generating the appropriate SQL.
  205. *
  206. * @param AST\DeleteClause $deleteClause
  207. *
  208. * @return string The SQL.
  209. */
  210. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. function getExecutor($AST);
  428. }