blob: a7948db5c695ebfdb4449eda6c4656579a569313 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
<?php
declare(strict_types=1);
namespace Doctrine\ORM\Query;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\Mapping\ClassMetadata;
use LogicException;
use function array_diff;
use function array_keys;
use function sprintf;
/**
* An adapter implementation of the TreeWalker interface. The methods in this class
* are empty. This class exists as convenience for creating tree walkers.
*
* @psalm-import-type QueryComponent from Parser
*/
abstract class TreeWalkerAdapter implements TreeWalker
{
/**
* {@inheritDoc}
*/
public function __construct(
private readonly AbstractQuery $query,
private readonly ParserResult $parserResult,
private array $queryComponents,
) {
}
/**
* {@inheritDoc}
*/
public function getQueryComponents(): array
{
return $this->queryComponents;
}
public function walkSelectStatement(AST\SelectStatement $selectStatement): void
{
}
public function walkUpdateStatement(AST\UpdateStatement $updateStatement): void
{
}
public function walkDeleteStatement(AST\DeleteStatement $deleteStatement): void
{
}
/**
* Sets or overrides a query component for a given dql alias.
*
* @psalm-param QueryComponent $queryComponent
*/
protected function setQueryComponent(string $dqlAlias, array $queryComponent): void
{
$requiredKeys = ['metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token'];
if (array_diff($requiredKeys, array_keys($queryComponent))) {
throw QueryException::invalidQueryComponent($dqlAlias);
}
$this->queryComponents[$dqlAlias] = $queryComponent;
}
/**
* Retrieves the Query Instance responsible for the current walkers execution.
*/
protected function _getQuery(): AbstractQuery
{
return $this->query;
}
/**
* Retrieves the ParserResult.
*/
protected function _getParserResult(): ParserResult
{
return $this->parserResult;
}
protected function getMetadataForDqlAlias(string $dqlAlias): ClassMetadata
{
return $this->queryComponents[$dqlAlias]['metadata']
?? throw new LogicException(sprintf('No metadata for DQL alias: %s', $dqlAlias));
}
}
|