1 | <?php |
||
16 | class ScopeParser extends BaseParser implements IScopeParser |
||
17 | { |
||
18 | /** |
||
19 | * The parsed query segments. |
||
20 | * |
||
21 | * @var Queries\ISegment[] |
||
22 | */ |
||
23 | protected $segments = []; |
||
24 | |||
25 | /** |
||
26 | * @var Queries\ISourceInfo |
||
27 | */ |
||
28 | protected $sourceInfo; |
||
29 | |||
30 | public function getScope() |
||
34 | |||
35 | public function buildSourceInterpretation() |
||
39 | |||
40 | public function buildJoinOptionsInterpretation() |
||
44 | |||
45 | public function buildScopeInterpretation() |
||
49 | |||
50 | public function interpretScopeSource(IQueryable $queryable) |
||
54 | |||
55 | /** |
||
56 | * @param IFunction $function |
||
57 | * |
||
58 | * @return Functions\ElementProjection |
||
59 | */ |
||
60 | final protected function buildElementProjection(IFunction $function) |
||
61 | { |
||
62 | return $this->buildFunction( |
||
63 | $function, |
||
64 | Functions\ElementProjection::factory() |
||
65 | ); |
||
66 | } |
||
67 | |||
68 | public function interpretWhere($segmentId, IFunction $predicate) |
||
72 | |||
73 | public function interpretOrderings($segmentId, array $orderings) |
||
74 | { |
||
75 | $orderingSections = []; |
||
76 | |||
77 | foreach ($orderings as $ordering) { |
||
78 | list($projection, $isAscendingId, $isAscendingValue) = $ordering; |
||
79 | $orderingSections[] = new Segments\Ordering( |
||
80 | $this->buildElementProjection($projection), |
||
81 | $isAscendingId); |
||
82 | } |
||
83 | |||
84 | $this->segments[] = new Segments\OrderBy($orderingSections); |
||
85 | } |
||
86 | |||
87 | public function interpretSlice($segmentId, $startId, $start, $amountId, $amount) |
||
88 | { |
||
89 | $this->segments[] = new Segments\Range($startId, $amountId); |
||
90 | } |
||
91 | |||
92 | public function interpretIndexBy($segmentId, IFunction $projection) |
||
93 | { |
||
94 | $this->segments[] = new Segments\IndexBy($this->buildElementProjection($projection)); |
||
95 | } |
||
96 | |||
97 | public function interpretKeys($segmentId) |
||
101 | |||
102 | public function interpretReindex($segmentId) |
||
106 | |||
107 | public function interpretGroupBy($segmentId, IFunction $projection) |
||
108 | { |
||
109 | $this->segments[] = new Segments\GroupBy($this->buildElementProjection($projection)); |
||
110 | } |
||
111 | |||
112 | public function interpretJoin( |
||
113 | $segmentId, |
||
114 | IJoinOptionsInterpretation $joinOptionsInterpretation, |
||
115 | IFunction $joinToFunction |
||
116 | ) { |
||
117 | /* @var $joinOptionsInterpretation IJoinOptionsParser */ |
||
118 | $this->segments[] = new Segments\Join( |
||
119 | $joinOptionsInterpretation->getJoinOptions(), |
||
120 | $this->buildFunction($joinToFunction, Functions\ConnectorProjection::factory())); |
||
121 | } |
||
122 | |||
123 | public function interpretSelect($segmentId, IFunction $projection) |
||
124 | { |
||
125 | $this->segments[] = new Segments\Select($this->buildElementProjection($projection)); |
||
126 | } |
||
127 | |||
128 | public function interpretSelectMany($segmentId, IFunction $projection) |
||
129 | { |
||
130 | $this->segments[] = new Segments\SelectMany($this->buildElementProjection($projection)); |
||
131 | } |
||
132 | |||
133 | public function interpretUnique($segmentId) |
||
137 | |||
138 | public function interpretOperation($segmentId, $operationType, ISourceInterpretation $sourceInterpretation) |
||
139 | { |
||
140 | /* @var $sourceInterpretation ISourceParser */ |
||
141 | $this->segments[] = new Segments\Operation( |
||
142 | $operationType, |
||
143 | $sourceInterpretation->getSource()); |
||
144 | } |
||
145 | } |
||
146 |