Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / lib / Doctrine / ORM / Query / TreeWalkerChain.php
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;
21
22 /**
23  * Represents a chain of tree walkers that modify an AST and finally emit output.
24  * Only the last walker in the chain can emit output. Any previous walkers can modify
25  * the AST to influence the final output produced by the last walker.
26  *
27  * @author Roman Borschel <roman@code-factory.org>
28  * @since 2.0
29  */
30 class TreeWalkerChain implements TreeWalker
31 {
32     /** The tree walkers. */
33     private $_walkers = array();
34     /** The original Query. */
35     private $_query;
36     /** The ParserResult of the original query that was produced by the Parser. */
37     private $_parserResult;
38     /** The query components of the original query (the "symbol table") that was produced by the Parser. */
39     private $_queryComponents;
40
41     /**
42      * @inheritdoc
43      */
44     public function __construct($query, $parserResult, array $queryComponents)
45     {
46         $this->_query = $query;
47         $this->_parserResult = $parserResult;
48         $this->_queryComponents = $queryComponents;
49     }
50
51     /**
52      * Adds a tree walker to the chain.
53      *
54      * @param string $walkerClass The class of the walker to instantiate.
55      */
56     public function addTreeWalker($walkerClass)
57     {
58         $this->_walkers[] = new $walkerClass($this->_query, $this->_parserResult, $this->_queryComponents);
59     }
60
61     /**
62      * Walks down a SelectStatement AST node, thereby generating the appropriate SQL.
63      *
64      * @return string The SQL.
65      */
66     public function walkSelectStatement(AST\SelectStatement $AST)
67     {
68         foreach ($this->_walkers as $walker) {
69             $walker->walkSelectStatement($AST);
70         }
71     }
72
73     /**
74      * Walks down a SelectClause AST node, thereby generating the appropriate SQL.
75      *
76      * @return string The SQL.
77      */
78     public function walkSelectClause($selectClause)
79     {
80         foreach ($this->_walkers as $walker) {
81             $walker->walkSelectClause($selectClause);
82         }
83     }
84
85     /**
86      * Walks down a FromClause AST node, thereby generating the appropriate SQL.
87      *
88      * @return string The SQL.
89      */
90     public function walkFromClause($fromClause)
91     {
92         foreach ($this->_walkers as $walker) {
93             $walker->walkFromClause($fromClause);
94         }
95     }
96
97     /**
98      * Walks down a FunctionNode AST node, thereby generating the appropriate SQL.
99      *
100      * @return string The SQL.
101      */
102     public function walkFunction($function)
103     {
104         foreach ($this->_walkers as $walker) {
105             $walker->walkFunction($function);
106         }
107     }
108
109     /**
110      * Walks down an OrderByClause AST node, thereby generating the appropriate SQL.
111      *
112      * @param OrderByClause
113      * @return string The SQL.
114      */
115     public function walkOrderByClause($orderByClause)
116     {
117         foreach ($this->_walkers as $walker) {
118             $walker->walkOrderByClause($orderByClause);
119         }
120     }
121
122     /**
123      * Walks down an OrderByItem AST node, thereby generating the appropriate SQL.
124      *
125      * @param OrderByItem
126      * @return string The SQL.
127      */
128     public function walkOrderByItem($orderByItem)
129     {
130         foreach ($this->_walkers as $walker) {
131             $walker->walkOrderByItem($orderByItem);
132         }
133     }
134
135     /**
136      * Walks down a HavingClause AST node, thereby generating the appropriate SQL.
137      *
138      * @param HavingClause
139      * @return string The SQL.
140      */
141     public function walkHavingClause($havingClause)
142     {
143         foreach ($this->_walkers as $walker) {
144             $walker->walkHavingClause($havingClause);
145         }
146     }
147
148     /**
149      * Walks down a Join AST node and creates the corresponding SQL.
150      *
151      * @param Join $join
152      * @return string The SQL.
153      */
154     public function walkJoin($join)
155     {
156         foreach ($this->_walkers as $walker) {
157             $walker->walkJoin($join);
158         }
159     }
160
161     /**
162      * Walks down a SelectExpression AST node and generates the corresponding SQL.
163      *
164      * @param SelectExpression $selectExpression
165      * @return string The SQL.
166      */
167     public function walkSelectExpression($selectExpression)
168     {
169         foreach ($this->_walkers as $walker) {
170             $walker->walkSelectExpression($selectExpression);
171         }
172     }
173
174     /**
175      * Walks down a QuantifiedExpression AST node, thereby generating the appropriate SQL.
176      *
177      * @param QuantifiedExpression
178      * @return string The SQL.
179      */
180     public function walkQuantifiedExpression($qExpr)
181     {
182         foreach ($this->_walkers as $walker) {
183             $walker->walkQuantifiedExpression($qExpr);
184         }
185     }
186
187     /**
188      * Walks down a Subselect AST node, thereby generating the appropriate SQL.
189      *
190      * @param Subselect
191      * @return string The SQL.
192      */
193     public function walkSubselect($subselect)
194     {
195         foreach ($this->_walkers as $walker) {
196             $walker->walkSubselect($subselect);
197         }
198     }
199
200     /**
201      * Walks down a SubselectFromClause AST node, thereby generating the appropriate SQL.
202      *
203      * @param SubselectFromClause
204      * @return string The SQL.
205      */
206     public function walkSubselectFromClause($subselectFromClause)
207     {
208         foreach ($this->_walkers as $walker) {
209             $walker->walkSubselectFromClause($subselectFromClause);
210         }
211     }
212
213     /**
214      * Walks down a SimpleSelectClause AST node, thereby generating the appropriate SQL.
215      *
216      * @param SimpleSelectClause
217      * @return string The SQL.
218      */
219     public function walkSimpleSelectClause($simpleSelectClause)
220     {
221         foreach ($this->_walkers as $walker) {
222             $walker->walkSimpleSelectClause($simpleSelectClause);
223         }
224     }
225
226     /**
227      * Walks down a SimpleSelectExpression AST node, thereby generating the appropriate SQL.
228      *
229      * @param SimpleSelectExpression
230      * @return string The SQL.
231      */
232     public function walkSimpleSelectExpression($simpleSelectExpression)
233     {
234         foreach ($this->_walkers as $walker) {
235             $walker->walkSimpleSelectExpression($simpleSelectExpression);
236         }
237     }
238
239     /**
240      * Walks down an AggregateExpression AST node, thereby generating the appropriate SQL.
241      *
242      * @param AggregateExpression
243      * @return string The SQL.
244      */
245     public function walkAggregateExpression($aggExpression)
246     {
247         foreach ($this->_walkers as $walker) {
248             $walker->walkAggregateExpression($aggExpression);
249         }
250     }
251
252     /**
253      * Walks down a GroupByClause AST node, thereby generating the appropriate SQL.
254      *
255      * @param GroupByClause
256      * @return string The SQL.
257      */
258     public function walkGroupByClause($groupByClause)
259     {
260         foreach ($this->_walkers as $walker) {
261             $walker->walkGroupByClause($groupByClause);
262         }
263     }
264
265     /**
266      * Walks down a GroupByItem AST node, thereby generating the appropriate SQL.
267      *
268      * @param GroupByItem
269      * @return string The SQL.
270      */
271     public function walkGroupByItem($groupByItem)
272     {
273         foreach ($this->_walkers as $walker) {
274             $walker->walkGroupByItem($groupByItem);
275         }
276     }
277
278     /**
279      * Walks down an UpdateStatement AST node, thereby generating the appropriate SQL.
280      *
281      * @param UpdateStatement
282      * @return string The SQL.
283      */
284     public function walkUpdateStatement(AST\UpdateStatement $AST)
285     {
286         foreach ($this->_walkers as $walker) {
287             $walker->walkUpdateStatement($AST);
288         }
289     }
290
291     /**
292      * Walks down a DeleteStatement AST node, thereby generating the appropriate SQL.
293      *
294      * @param DeleteStatement
295      * @return string The SQL.
296      */
297     public function walkDeleteStatement(AST\DeleteStatement $AST)
298     {
299         foreach ($this->_walkers as $walker) {
300             $walker->walkDeleteStatement($AST);
301         }
302     }
303
304     /**
305      * Walks down a DeleteClause AST node, thereby generating the appropriate SQL.
306      *
307      * @param DeleteClause
308      * @return string The SQL.
309      */
310     public function walkDeleteClause(AST\DeleteClause $deleteClause)
311     {
312         foreach ($this->_walkers as $walker) {
313             $walker->walkDeleteClause($deleteClause);
314         }
315     }
316
317     /**
318      * Walks down an UpdateClause AST node, thereby generating the appropriate SQL.
319      *
320      * @param UpdateClause
321      * @return string The SQL.
322      */
323     public function walkUpdateClause($updateClause)
324     {
325         foreach ($this->_walkers as $walker) {
326             $walker->walkUpdateClause($updateClause);
327         }
328     }
329
330     /**
331      * Walks down an UpdateItem AST node, thereby generating the appropriate SQL.
332      *
333      * @param UpdateItem
334      * @return string The SQL.
335      */
336     public function walkUpdateItem($updateItem)
337     {
338         foreach ($this->_walkers as $walker) {
339             $walker->walkUpdateItem($updateItem);
340         }
341     }
342
343     /**
344      * Walks down a WhereClause AST node, thereby generating the appropriate SQL.
345      *
346      * @param WhereClause
347      * @return string The SQL.
348      */
349     public function walkWhereClause($whereClause)
350     {
351         foreach ($this->_walkers as $walker) {
352             $walker->walkWhereClause($whereClause);
353         }
354     }
355
356     /**
357      * Walks down a ConditionalExpression AST node, thereby generating the appropriate SQL.
358      *
359      * @param ConditionalExpression
360      * @return string The SQL.
361      */
362     public function walkConditionalExpression($condExpr)
363     {
364         foreach ($this->_walkers as $walker) {
365             $walker->walkConditionalExpression($condExpr);
366         }
367     }
368
369     /**
370      * Walks down a ConditionalTerm AST node, thereby generating the appropriate SQL.
371      *
372      * @param ConditionalTerm
373      * @return string The SQL.
374      */
375     public function walkConditionalTerm($condTerm)
376     {
377         foreach ($this->_walkers as $walker) {
378             $walker->walkConditionalTerm($condTerm);
379         }
380     }
381
382     /**
383      * Walks down a ConditionalFactor AST node, thereby generating the appropriate SQL.
384      *
385      * @param ConditionalFactor
386      * @return string The SQL.
387      */
388     public function walkConditionalFactor($factor)
389     {
390         foreach ($this->_walkers as $walker) {
391             $walker->walkConditionalFactor($factor);
392         }
393     }
394
395     /**
396      * Walks down a ConditionalPrimary AST node, thereby generating the appropriate SQL.
397      *
398      * @param ConditionalPrimary
399      * @return string The SQL.
400      */
401     public function walkConditionalPrimary($condPrimary)
402     {
403         foreach ($this->_walkers as $walker) {
404             $walker->walkConditionalPrimary($condPrimary);
405         }
406     }
407
408     /**
409      * Walks down an ExistsExpression AST node, thereby generating the appropriate SQL.
410      *
411      * @param ExistsExpression
412      * @return string The SQL.
413      */
414     public function walkExistsExpression($existsExpr)
415     {
416         foreach ($this->_walkers as $walker) {
417             $walker->walkExistsExpression($existsExpr);
418         }
419     }
420
421     /**
422      * Walks down a CollectionMemberExpression AST node, thereby generating the appropriate SQL.
423      *
424      * @param CollectionMemberExpression
425      * @return string The SQL.
426      */
427     public function walkCollectionMemberExpression($collMemberExpr)
428     {
429         foreach ($this->_walkers as $walker) {
430             $walker->walkCollectionMemberExpression($collMemberExpr);
431         }
432     }
433
434     /**
435      * Walks down an EmptyCollectionComparisonExpression AST node, thereby generating the appropriate SQL.
436      *
437      * @param EmptyCollectionComparisonExpression
438      * @return string The SQL.
439      */
440     public function walkEmptyCollectionComparisonExpression($emptyCollCompExpr)
441     {
442         foreach ($this->_walkers as $walker) {
443             $walker->walkEmptyCollectionComparisonExpression($emptyCollCompExpr);
444         }
445     }
446
447     /**
448      * Walks down a NullComparisonExpression AST node, thereby generating the appropriate SQL.
449      *
450      * @param NullComparisonExpression
451      * @return string The SQL.
452      */
453     public function walkNullComparisonExpression($nullCompExpr)
454     {
455         foreach ($this->_walkers as $walker) {
456             $walker->walkNullComparisonExpression($nullCompExpr);
457         }
458     }
459
460     /**
461      * Walks down an InExpression AST node, thereby generating the appropriate SQL.
462      *
463      * @param InExpression
464      * @return string The SQL.
465      */
466     public function walkInExpression($inExpr)
467     {
468         foreach ($this->_walkers as $walker) {
469             $walker->walkInExpression($inExpr);
470         }
471     }
472
473     /**
474      * Walks down an InstanceOfExpression AST node, thereby generating the appropriate SQL.
475      *
476      * @param InstanceOfExpression
477      * @return string The SQL.
478      */
479     function walkInstanceOfExpression($instanceOfExpr)
480     {
481         foreach ($this->_walkers as $walker) {
482             $walker->walkInstanceOfExpression($instanceOfExpr);
483         }
484     }
485
486     /**
487      * Walks down a literal that represents an AST node, thereby generating the appropriate SQL.
488      *
489      * @param mixed
490      * @return string The SQL.
491      */
492     public function walkLiteral($literal)
493     {
494         foreach ($this->_walkers as $walker) {
495             $walker->walkLiteral($literal);
496         }
497     }
498
499     /**
500      * Walks down a BetweenExpression AST node, thereby generating the appropriate SQL.
501      *
502      * @param BetweenExpression
503      * @return string The SQL.
504      */
505     public function walkBetweenExpression($betweenExpr)
506     {
507         foreach ($this->_walkers as $walker) {
508             $walker->walkBetweenExpression($betweenExpr);
509         }
510     }
511
512     /**
513      * Walks down a LikeExpression AST node, thereby generating the appropriate SQL.
514      *
515      * @param LikeExpression
516      * @return string The SQL.
517      */
518     public function walkLikeExpression($likeExpr)
519     {
520         foreach ($this->_walkers as $walker) {
521             $walker->walkLikeExpression($likeExpr);
522         }
523     }
524
525     /**
526      * Walks down a StateFieldPathExpression AST node, thereby generating the appropriate SQL.
527      *
528      * @param StateFieldPathExpression
529      * @return string The SQL.
530      */
531     public function walkStateFieldPathExpression($stateFieldPathExpression)
532     {
533         foreach ($this->_walkers as $walker) {
534             $walker->walkStateFieldPathExpression($stateFieldPathExpression);
535         }
536     }
537
538     /**
539      * Walks down a ComparisonExpression AST node, thereby generating the appropriate SQL.
540      *
541      * @param ComparisonExpression
542      * @return string The SQL.
543      */
544     public function walkComparisonExpression($compExpr)
545     {
546         foreach ($this->_walkers as $walker) {
547             $walker->walkComparisonExpression($compExpr);
548         }
549     }
550
551     /**
552      * Walks down an InputParameter AST node, thereby generating the appropriate SQL.
553      *
554      * @param InputParameter
555      * @return string The SQL.
556      */
557     public function walkInputParameter($inputParam)
558     {
559         foreach ($this->_walkers as $walker) {
560             $walker->walkInputParameter($inputParam);
561         }
562     }
563
564     /**
565      * Walks down an ArithmeticExpression AST node, thereby generating the appropriate SQL.
566      *
567      * @param ArithmeticExpression
568      * @return string The SQL.
569      */
570     public function walkArithmeticExpression($arithmeticExpr)
571     {
572         foreach ($this->_walkers as $walker) {
573             $walker->walkArithmeticExpression($arithmeticExpr);
574         }
575     }
576
577     /**
578      * Walks down an ArithmeticTerm AST node, thereby generating the appropriate SQL.
579      *
580      * @param mixed
581      * @return string The SQL.
582      */
583     public function walkArithmeticTerm($term)
584     {
585         foreach ($this->_walkers as $walker) {
586             $walker->walkArithmeticTerm($term);
587         }
588     }
589
590     /**
591      * Walks down a StringPrimary that represents an AST node, thereby generating the appropriate SQL.
592      *
593      * @param mixed
594      * @return string The SQL.
595      */
596     public function walkStringPrimary($stringPrimary)
597     {
598         foreach ($this->_walkers as $walker) {
599             $walker->walkStringPrimary($stringPrimary);
600         }
601     }
602
603     /**
604      * Walks down an ArithmeticFactor that represents an AST node, thereby generating the appropriate SQL.
605      *
606      * @param mixed
607      * @return string The SQL.
608      */
609     public function walkArithmeticFactor($factor)
610     {
611         foreach ($this->_walkers as $walker) {
612             $walker->walkArithmeticFactor($factor);
613         }
614     }
615
616     /**
617      * Walks down an SimpleArithmeticExpression AST node, thereby generating the appropriate SQL.
618      *
619      * @param SimpleArithmeticExpression
620      * @return string The SQL.
621      */
622     public function walkSimpleArithmeticExpression($simpleArithmeticExpr)
623     {
624         foreach ($this->_walkers as $walker) {
625             $walker->walkSimpleArithmeticExpression($simpleArithmeticExpr);
626         }
627     }
628
629     /**
630      * Walks down an PathExpression AST node, thereby generating the appropriate SQL.
631      *
632      * @param mixed
633      * @return string The SQL.
634      */
635     public function walkPathExpression($pathExpr)
636     {
637         foreach ($this->_walkers as $walker) {
638             $walker->walkPathExpression($pathExpr);
639         }
640     }
641
642     /**
643      * Walks down an ResultVariable AST node, thereby generating the appropriate SQL.
644      *
645      * @param string $resultVariable
646      * @return string The SQL.
647      */
648     public function walkResultVariable($resultVariable)
649     {
650         foreach ($this->_walkers as $walker) {
651             $walker->walkResultVariable($resultVariable);
652         }
653     }
654
655     /**
656      * Gets an executor that can be used to execute the result of this walker.
657      *
658      * @return AbstractExecutor
659      */
660     public function getExecutor($AST)
661     {}
662 }