summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Query/TreeWalkerChain.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/orm/src/Query/TreeWalkerChain.php')
-rw-r--r--vendor/doctrine/orm/src/Query/TreeWalkerChain.php88
1 files changed, 88 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Query/TreeWalkerChain.php b/vendor/doctrine/orm/src/Query/TreeWalkerChain.php
new file mode 100644
index 0000000..7bb3051
--- /dev/null
+++ b/vendor/doctrine/orm/src/Query/TreeWalkerChain.php
@@ -0,0 +1,88 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Query;
6
7use Doctrine\ORM\AbstractQuery;
8use Generator;
9
10/**
11 * Represents a chain of tree walkers that modify an AST and finally emit output.
12 * Only the last walker in the chain can emit output. Any previous walkers can modify
13 * the AST to influence the final output produced by the last walker.
14 *
15 * @psalm-import-type QueryComponent from Parser
16 */
17class TreeWalkerChain implements TreeWalker
18{
19 /**
20 * The tree walkers.
21 *
22 * @var string[]
23 * @psalm-var list<class-string<TreeWalker>>
24 */
25 private array $walkers = [];
26
27 /**
28 * {@inheritDoc}
29 */
30 public function __construct(
31 private readonly AbstractQuery $query,
32 private readonly ParserResult $parserResult,
33 private array $queryComponents,
34 ) {
35 }
36
37 /**
38 * Returns the internal queryComponents array.
39 *
40 * {@inheritDoc}
41 */
42 public function getQueryComponents(): array
43 {
44 return $this->queryComponents;
45 }
46
47 /**
48 * Adds a tree walker to the chain.
49 *
50 * @param string $walkerClass The class of the walker to instantiate.
51 * @psalm-param class-string<TreeWalker> $walkerClass
52 */
53 public function addTreeWalker(string $walkerClass): void
54 {
55 $this->walkers[] = $walkerClass;
56 }
57
58 public function walkSelectStatement(AST\SelectStatement $selectStatement): void
59 {
60 foreach ($this->getWalkers() as $walker) {
61 $walker->walkSelectStatement($selectStatement);
62
63 $this->queryComponents = $walker->getQueryComponents();
64 }
65 }
66
67 public function walkUpdateStatement(AST\UpdateStatement $updateStatement): void
68 {
69 foreach ($this->getWalkers() as $walker) {
70 $walker->walkUpdateStatement($updateStatement);
71 }
72 }
73
74 public function walkDeleteStatement(AST\DeleteStatement $deleteStatement): void
75 {
76 foreach ($this->getWalkers() as $walker) {
77 $walker->walkDeleteStatement($deleteStatement);
78 }
79 }
80
81 /** @psalm-return Generator<int, TreeWalker> */
82 private function getWalkers(): Generator
83 {
84 foreach ($this->walkers as $walkerClass) {
85 yield new $walkerClass($this->query, $this->parserResult, $this->queryComponents);
86 }
87 }
88}