PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/Doctrine/ORM/Query/TreeWalkerChain.php

https://bitbucket.org/gencer/doctrine2
PHP | 575 lines | 312 code | 59 blank | 204 comment | 1 complexity | 5e2b6b22b19bdba2021505b102092cda MD5 | raw file
Possible License(s): Unlicense
  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. * Represents a chain of tree walkers that modify an AST and finally emit output.
  22. * Only the last walker in the chain can emit output. Any previous walkers can modify
  23. * the AST to influence the final output produced by the last walker.
  24. *
  25. * @author Roman Borschel <roman@code-factory.org>
  26. * @since 2.0
  27. */
  28. class TreeWalkerChain implements TreeWalker
  29. {
  30. /**
  31. * The tree walkers.
  32. *
  33. * @var TreeWalker[]
  34. */
  35. private $_walkers;
  36. /**
  37. * The original Query.
  38. *
  39. * @var \Doctrine\ORM\AbstractQuery
  40. */
  41. private $_query;
  42. /**
  43. * The ParserResult of the original query that was produced by the Parser.
  44. *
  45. * @var \Doctrine\ORM\Query\ParserResult
  46. */
  47. private $_parserResult;
  48. /**
  49. * The query components of the original query (the "symbol table") that was produced by the Parser.
  50. *
  51. * @var array
  52. */
  53. private $_queryComponents;
  54. /**
  55. * Returns the internal queryComponents array.
  56. *
  57. * @return array
  58. */
  59. public function getQueryComponents()
  60. {
  61. return $this->_queryComponents;
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function setQueryComponent($dqlAlias, array $queryComponent)
  67. {
  68. $requiredKeys = array('metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token');
  69. if (array_diff($requiredKeys, array_keys($queryComponent))) {
  70. throw QueryException::invalidQueryComponent($dqlAlias);
  71. }
  72. $this->_queryComponents[$dqlAlias] = $queryComponent;
  73. }
  74. /**
  75. * {@inheritdoc}
  76. */
  77. public function __construct($query, $parserResult, array $queryComponents)
  78. {
  79. $this->_query = $query;
  80. $this->_parserResult = $parserResult;
  81. $this->_queryComponents = $queryComponents;
  82. $this->_walkers = new TreeWalkerChainIterator($this, $query, $parserResult);
  83. }
  84. /**
  85. * Adds a tree walker to the chain.
  86. *
  87. * @param string $walkerClass The class of the walker to instantiate.
  88. *
  89. * @return void
  90. */
  91. public function addTreeWalker($walkerClass)
  92. {
  93. $this->_walkers[] = $walkerClass;
  94. }
  95. /**
  96. * {@inheritdoc}
  97. */
  98. public function walkSelectStatement(AST\SelectStatement $AST)
  99. {
  100. foreach ($this->_walkers as $walker) {
  101. $walker->walkSelectStatement($AST);
  102. $this->_queryComponents = $walker->getQueryComponents();
  103. }
  104. }
  105. /**
  106. * {@inheritdoc}
  107. */
  108. public function walkSelectClause($selectClause)
  109. {
  110. foreach ($this->_walkers as $walker) {
  111. $walker->walkSelectClause($selectClause);
  112. }
  113. }
  114. /**
  115. * {@inheritdoc}
  116. */
  117. public function walkFromClause($fromClause)
  118. {
  119. foreach ($this->_walkers as $walker) {
  120. $walker->walkFromClause($fromClause);
  121. }
  122. }
  123. /**
  124. * {@inheritdoc}
  125. */
  126. public function walkFunction($function)
  127. {
  128. foreach ($this->_walkers as $walker) {
  129. $walker->walkFunction($function);
  130. }
  131. }
  132. /**
  133. * {@inheritdoc}
  134. */
  135. public function walkOrderByClause($orderByClause)
  136. {
  137. foreach ($this->_walkers as $walker) {
  138. $walker->walkOrderByClause($orderByClause);
  139. }
  140. }
  141. /**
  142. * {@inheritdoc}
  143. */
  144. public function walkOrderByItem($orderByItem)
  145. {
  146. foreach ($this->_walkers as $walker) {
  147. $walker->walkOrderByItem($orderByItem);
  148. }
  149. }
  150. /**
  151. * {@inheritdoc}
  152. */
  153. public function walkHavingClause($havingClause)
  154. {
  155. foreach ($this->_walkers as $walker) {
  156. $walker->walkHavingClause($havingClause);
  157. }
  158. }
  159. /**
  160. * {@inheritdoc}
  161. */
  162. public function walkJoin($join)
  163. {
  164. foreach ($this->_walkers as $walker) {
  165. $walker->walkJoin($join);
  166. }
  167. }
  168. /**
  169. * {@inheritdoc}
  170. */
  171. public function walkSelectExpression($selectExpression)
  172. {
  173. foreach ($this->_walkers as $walker) {
  174. $walker->walkSelectExpression($selectExpression);
  175. }
  176. }
  177. /**
  178. * {@inheritdoc}
  179. */
  180. public function walkQuantifiedExpression($qExpr)
  181. {
  182. foreach ($this->_walkers as $walker) {
  183. $walker->walkQuantifiedExpression($qExpr);
  184. }
  185. }
  186. /**
  187. * {@inheritdoc}
  188. */
  189. public function walkSubselect($subselect)
  190. {
  191. foreach ($this->_walkers as $walker) {
  192. $walker->walkSubselect($subselect);
  193. }
  194. }
  195. /**
  196. * {@inheritdoc}
  197. */
  198. public function walkSubselectFromClause($subselectFromClause)
  199. {
  200. foreach ($this->_walkers as $walker) {
  201. $walker->walkSubselectFromClause($subselectFromClause);
  202. }
  203. }
  204. /**
  205. * {@inheritdoc}
  206. */
  207. public function walkSimpleSelectClause($simpleSelectClause)
  208. {
  209. foreach ($this->_walkers as $walker) {
  210. $walker->walkSimpleSelectClause($simpleSelectClause);
  211. }
  212. }
  213. /**
  214. * {@inheritdoc}
  215. */
  216. public function walkSimpleSelectExpression($simpleSelectExpression)
  217. {
  218. foreach ($this->_walkers as $walker) {
  219. $walker->walkSimpleSelectExpression($simpleSelectExpression);
  220. }
  221. }
  222. /**
  223. * {@inheritdoc}
  224. */
  225. public function walkAggregateExpression($aggExpression)
  226. {
  227. foreach ($this->_walkers as $walker) {
  228. $walker->walkAggregateExpression($aggExpression);
  229. }
  230. }
  231. /**
  232. * {@inheritdoc}
  233. */
  234. public function walkGroupByClause($groupByClause)
  235. {
  236. foreach ($this->_walkers as $walker) {
  237. $walker->walkGroupByClause($groupByClause);
  238. }
  239. }
  240. /**
  241. * {@inheritdoc}
  242. */
  243. public function walkGroupByItem($groupByItem)
  244. {
  245. foreach ($this->_walkers as $walker) {
  246. $walker->walkGroupByItem($groupByItem);
  247. }
  248. }
  249. /**
  250. * {@inheritdoc}
  251. */
  252. public function walkUpdateStatement(AST\UpdateStatement $AST)
  253. {
  254. foreach ($this->_walkers as $walker) {
  255. $walker->walkUpdateStatement($AST);
  256. }
  257. }
  258. /**
  259. * {@inheritdoc}
  260. */
  261. public function walkDeleteStatement(AST\DeleteStatement $AST)
  262. {
  263. foreach ($this->_walkers as $walker) {
  264. $walker->walkDeleteStatement($AST);
  265. }
  266. }
  267. /**
  268. * {@inheritdoc}
  269. */
  270. public function walkDeleteClause(AST\DeleteClause $deleteClause)
  271. {
  272. foreach ($this->_walkers as $walker) {
  273. $walker->walkDeleteClause($deleteClause);
  274. }
  275. }
  276. /**
  277. * {@inheritdoc}
  278. */
  279. public function walkUpdateClause($updateClause)
  280. {
  281. foreach ($this->_walkers as $walker) {
  282. $walker->walkUpdateClause($updateClause);
  283. }
  284. }
  285. /**
  286. * {@inheritdoc}
  287. */
  288. public function walkUpdateItem($updateItem)
  289. {
  290. foreach ($this->_walkers as $walker) {
  291. $walker->walkUpdateItem($updateItem);
  292. }
  293. }
  294. /**
  295. * {@inheritdoc}
  296. */
  297. public function walkWhereClause($whereClause)
  298. {
  299. foreach ($this->_walkers as $walker) {
  300. $walker->walkWhereClause($whereClause);
  301. }
  302. }
  303. /**
  304. * {@inheritdoc}
  305. */
  306. public function walkConditionalExpression($condExpr)
  307. {
  308. foreach ($this->_walkers as $walker) {
  309. $walker->walkConditionalExpression($condExpr);
  310. }
  311. }
  312. /**
  313. * {@inheritdoc}
  314. */
  315. public function walkConditionalTerm($condTerm)
  316. {
  317. foreach ($this->_walkers as $walker) {
  318. $walker->walkConditionalTerm($condTerm);
  319. }
  320. }
  321. /**
  322. * {@inheritdoc}
  323. */
  324. public function walkConditionalFactor($factor)
  325. {
  326. foreach ($this->_walkers as $walker) {
  327. $walker->walkConditionalFactor($factor);
  328. }
  329. }
  330. /**
  331. * {@inheritdoc}
  332. */
  333. public function walkConditionalPrimary($condPrimary)
  334. {
  335. foreach ($this->_walkers as $walker) {
  336. $walker->walkConditionalPrimary($condPrimary);
  337. }
  338. }
  339. /**
  340. * {@inheritdoc}
  341. */
  342. public function walkExistsExpression($existsExpr)
  343. {
  344. foreach ($this->_walkers as $walker) {
  345. $walker->walkExistsExpression($existsExpr);
  346. }
  347. }
  348. /**
  349. * {@inheritdoc}
  350. */
  351. public function walkCollectionMemberExpression($collMemberExpr)
  352. {
  353. foreach ($this->_walkers as $walker) {
  354. $walker->walkCollectionMemberExpression($collMemberExpr);
  355. }
  356. }
  357. /**
  358. * {@inheritdoc}
  359. */
  360. public function walkEmptyCollectionComparisonExpression($emptyCollCompExpr)
  361. {
  362. foreach ($this->_walkers as $walker) {
  363. $walker->walkEmptyCollectionComparisonExpression($emptyCollCompExpr);
  364. }
  365. }
  366. /**
  367. * {@inheritdoc}
  368. */
  369. public function walkNullComparisonExpression($nullCompExpr)
  370. {
  371. foreach ($this->_walkers as $walker) {
  372. $walker->walkNullComparisonExpression($nullCompExpr);
  373. }
  374. }
  375. /**
  376. * {@inheritdoc}
  377. */
  378. public function walkInExpression($inExpr)
  379. {
  380. foreach ($this->_walkers as $walker) {
  381. $walker->walkInExpression($inExpr);
  382. }
  383. }
  384. /**
  385. * {@inheritdoc}
  386. */
  387. function walkInstanceOfExpression($instanceOfExpr)
  388. {
  389. foreach ($this->_walkers as $walker) {
  390. $walker->walkInstanceOfExpression($instanceOfExpr);
  391. }
  392. }
  393. /**
  394. * {@inheritdoc}
  395. */
  396. public function walkLiteral($literal)
  397. {
  398. foreach ($this->_walkers as $walker) {
  399. $walker->walkLiteral($literal);
  400. }
  401. }
  402. /**
  403. * {@inheritdoc}
  404. */
  405. public function walkBetweenExpression($betweenExpr)
  406. {
  407. foreach ($this->_walkers as $walker) {
  408. $walker->walkBetweenExpression($betweenExpr);
  409. }
  410. }
  411. /**
  412. * {@inheritdoc}
  413. */
  414. public function walkLikeExpression($likeExpr)
  415. {
  416. foreach ($this->_walkers as $walker) {
  417. $walker->walkLikeExpression($likeExpr);
  418. }
  419. }
  420. /**
  421. * {@inheritdoc}
  422. */
  423. public function walkStateFieldPathExpression($stateFieldPathExpression)
  424. {
  425. foreach ($this->_walkers as $walker) {
  426. $walker->walkStateFieldPathExpression($stateFieldPathExpression);
  427. }
  428. }
  429. /**
  430. * {@inheritdoc}
  431. */
  432. public function walkComparisonExpression($compExpr)
  433. {
  434. foreach ($this->_walkers as $walker) {
  435. $walker->walkComparisonExpression($compExpr);
  436. }
  437. }
  438. /**
  439. * {@inheritdoc}
  440. */
  441. public function walkInputParameter($inputParam)
  442. {
  443. foreach ($this->_walkers as $walker) {
  444. $walker->walkInputParameter($inputParam);
  445. }
  446. }
  447. /**
  448. * {@inheritdoc}
  449. */
  450. public function walkArithmeticExpression($arithmeticExpr)
  451. {
  452. foreach ($this->_walkers as $walker) {
  453. $walker->walkArithmeticExpression($arithmeticExpr);
  454. }
  455. }
  456. /**
  457. * {@inheritdoc}
  458. */
  459. public function walkArithmeticTerm($term)
  460. {
  461. foreach ($this->_walkers as $walker) {
  462. $walker->walkArithmeticTerm($term);
  463. }
  464. }
  465. /**
  466. * {@inheritdoc}
  467. */
  468. public function walkStringPrimary($stringPrimary)
  469. {
  470. foreach ($this->_walkers as $walker) {
  471. $walker->walkStringPrimary($stringPrimary);
  472. }
  473. }
  474. /**
  475. * {@inheritdoc}
  476. */
  477. public function walkArithmeticFactor($factor)
  478. {
  479. foreach ($this->_walkers as $walker) {
  480. $walker->walkArithmeticFactor($factor);
  481. }
  482. }
  483. /**
  484. * {@inheritdoc}
  485. */
  486. public function walkSimpleArithmeticExpression($simpleArithmeticExpr)
  487. {
  488. foreach ($this->_walkers as $walker) {
  489. $walker->walkSimpleArithmeticExpression($simpleArithmeticExpr);
  490. }
  491. }
  492. /**
  493. * {@inheritdoc}
  494. */
  495. public function walkPathExpression($pathExpr)
  496. {
  497. foreach ($this->_walkers as $walker) {
  498. $walker->walkPathExpression($pathExpr);
  499. }
  500. }
  501. /**
  502. * {@inheritdoc}
  503. */
  504. public function walkResultVariable($resultVariable)
  505. {
  506. foreach ($this->_walkers as $walker) {
  507. $walker->walkResultVariable($resultVariable);
  508. }
  509. }
  510. /**
  511. * {@inheritdoc}
  512. */
  513. public function getExecutor($AST)
  514. {
  515. }
  516. }