Skip to content

Commit fa2487d

Browse files
committed
Query properties extracted and ::isPath() method is implemented
1 parent ab0b0e3 commit fa2487d

18 files changed

+189
-90
lines changed

src/Parser/TranslationScheme.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ public function applyProductionActions(Production $production): void
5555
->queryAstBuilder
5656
->setOutput(
5757
$symbols[0]['s.value_list_id'],
58-
$symbols[0]['s.is_definite']
58+
$symbols[0]['s.is_definite'],
59+
$symbols[0]['s.is_path']
5960
);
6061
break;
6162

6263
case SymbolType::NT_JSON_PATH . ".0":
6364
// [ 0:NT_PATH ]
6465
$header['s.value_list_id'] = $symbols[0]['s.value_list_id'];
6566
$header['s.is_definite'] = $symbols[0]['s.is_definite'];
67+
$header['s.is_path'] = $symbols[0]['s.is_path'];
6668
break;
6769

6870
case SymbolType::NT_PATH . ".0":
@@ -71,6 +73,7 @@ public function applyProductionActions(Production $production): void
7173
// [ 0:T_ROOT_RELATIVE, 1:NT_FILTER_LIST ]
7274
$header['s.value_list_id'] = $symbols[1]['s.value_list_id'];
7375
$header['s.is_definite'] = $symbols[1]['s.is_definite'];
76+
$header['s.is_path'] = $symbols[1]['s.is_path'];
7477
break;
7578

7679
case SymbolType::NT_DOT_FILTER_NEXT . ".0":
@@ -82,12 +85,14 @@ public function applyProductionActions(Production $production): void
8285
$header['i.value_list_id']
8386
);
8487
$header['s.is_definite'] = $header['i.is_definite'];
88+
$header['s.is_path'] = false;
8589
break;
8690

8791
case SymbolType::NT_DOT_FILTER_NEXT . ".1":
8892
// [ 0:NT_FILTER_LIST ]
8993
$header['s.value_list_id'] = $symbols[0]['s.value_list_id'];
9094
$header['s.is_definite'] = $symbols[0]['s.is_definite'];
95+
$header['s.is_path'] = $symbols[0]['s.is_path'];
9196
break;
9297

9398
case SymbolType::NT_DOT_FILTER . ".0":
@@ -96,6 +101,7 @@ public function applyProductionActions(Production $production): void
96101
// [ 0:T_STAR, 1:NT_FILTER_LIST ]
97102
$header['s.value_list_id'] = $symbols[1]['s.value_list_id'];
98103
$header['s.is_definite'] = $symbols[1]['s.is_definite'];
104+
$header['s.is_path'] = $symbols[1]['s.is_path'];
99105
break;
100106

101107
case SymbolType::NT_DOUBLE_DOT_FILTER . '.0':
@@ -104,18 +110,21 @@ public function applyProductionActions(Production $production): void
104110
// [ 0:T_STAR, 1:NT_FILTER_LIST ]
105111
$header['s.value_list_id'] = $symbols[1]['s.value_list_id'];
106112
$header['s.is_definite'] = $symbols[1]['s.is_definite'];
113+
$header['s.is_path'] = $symbols[1]['s.is_path'];
107114
break;
108115

109116
case SymbolType::NT_FILTER_LIST . ".0":
110117
// [ 0:T_DOT, 1:NT_DOT_FILTER ]
111118
$header['s.value_list_id'] = $symbols[1]['s.value_list_id'];
112119
$header['s.is_definite'] = $symbols[1]['s.is_definite'];
120+
$header['s.is_path'] = $symbols[1]['s.is_path'];
113121
break;
114122

115123
case SymbolType::NT_FILTER_LIST . ".1":
116124
// [ 0:T_DOUBLE_DOT, 1:NT_DOUBLE_DOT_FILTER ]
117125
$header['s.value_list_id'] = $symbols[1]['s.value_list_id'];
118126
$header['s.is_definite'] = false;
127+
$header['s.is_path'] = $symbols[1]['s.is_path'];
119128
break;
120129

121130
case SymbolType::NT_FILTER_LIST . ".2":
@@ -128,12 +137,14 @@ public function applyProductionActions(Production $production): void
128137
// ]
129138
$header['s.value_list_id'] = $symbols[4]['s.value_list_id'];
130139
$header['s.is_definite'] = $symbols[4]['s.is_definite'];
140+
$header['s.is_path'] = $symbols[4]['s.is_path'];
131141
break;
132142

133143
case SymbolType::NT_FILTER_LIST . ".3":
134144
// [ ]
135145
$header['s.value_list_id'] = $header['i.value_list_id'];
136146
$header['s.is_definite'] = $header['i.is_definite'];
147+
$header['s.is_path'] = $header['i.is_path'];
137148
break;
138149

139150
case SymbolType::NT_EXPR_ARG_SCALAR . ".0":
@@ -596,12 +607,14 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
596607
->queryAstBuilder
597608
->getInput();
598609
$symbols[1]['i.is_definite'] = $header['i.is_definite'];
610+
$symbols[1]['i.is_path'] = true;
599611
break;
600612

601613
case SymbolType::NT_PATH . ".1.1":
602614
// [ 0:T_ROOT_RELATIVE, 1:NT_FILTER_LIST ]
603615
$symbols[1]['i.value_list_id'] = $header['i.value_list_id'];
604616
$symbols[1]['i.is_definite'] = $header['i.is_definite'];
617+
$symbols[1]['i.is_path'] = true;
605618
break;
606619

607620
case SymbolType::NT_BRACKET_FILTER . ".1.0":
@@ -879,11 +892,13 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
879892
// [ 0:T_DOT, 1:NT_DOT_FILTER ]
880893
$symbols[1]['i.value_list_id'] = $header['i.value_list_id'];
881894
$symbols[1]['i.is_definite'] = $header['i.is_definite'];
895+
$symbols[1]['i.is_path'] = $header['i.is_path'];
882896
break;
883897

884898
case SymbolType::NT_FILTER_LIST . ".1.1":
885899
// [ 0:T_DOUBLE_DOT, 1:NT_DOUBLE_DOT_FILTER ]
886900
$symbols[1]['i.value_list_id'] = $header['i.value_list_id'];
901+
$symbols[1]['i.is_path'] = $header['i.is_path'];
887902
break;
888903

889904
case SymbolType::NT_FILTER_LIST . ".2.2":
@@ -908,13 +923,15 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
908923
// ]
909924
$symbols[4]['i.value_list_id'] = $symbols[2]['s.value_list_id'];
910925
$symbols[4]['i.is_definite'] = $symbols[2]['s.is_definite'];
926+
$symbols[4]['i.is_path'] = $header['i.is_path'];
911927
break;
912928

913929
case SymbolType::NT_DOT_FILTER . ".0.1":
914930
// [ 0:T_NAME, 1:NT_DOT_FILTER_NEXT ]
915931
$symbols[1]['i.filter_name'] = $symbols[0]['s.text'];
916932
$symbols[1]['i.value_list_id'] = $header['i.value_list_id'];
917933
$symbols[1]['i.is_definite'] = $header['i.is_definite'];
934+
$symbols[1]['i.is_path'] = $header['i.is_path'];
918935
break;
919936

920937
case SymbolType::NT_DOT_FILTER . ".1.1":
@@ -926,6 +943,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
926943
$this->queryAstBuilder->matchAnyChild($header['i.value_list_id'])
927944
);
928945
$symbols[1]['i.is_definite'] = false;
946+
$symbols[1]['i.is_path'] = $header['i.is_path'];
929947
break;
930948

931949
case SymbolType::NT_DOT_FILTER_NEXT . ".1.0":
@@ -944,6 +962,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
944962
)
945963
);
946964
$symbols[0]['i.is_definite'] = $header['i.is_definite'];
965+
$symbols[0]['i.is_path'] = $header['i.is_path'];
947966
break;
948967

949968
case SymbolType::NT_DOUBLE_DOT_FILTER . '.0.1':
@@ -962,6 +981,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
962981
)
963982
);
964983
$symbols[1]['i.is_definite'] = false;
984+
$symbols[1]['i.is_path'] = $header['i.is_path'];
965985
break;
966986

967987
case SymbolType::NT_DOUBLE_DOT_FILTER . '.1.1':
@@ -973,6 +993,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
973993
$this->queryAstBuilder->matchAnyChild($header['i.value_list_id'])
974994
);
975995
$symbols[1]['i.is_definite'] = false;
996+
$symbols[1]['i.is_path'] = $header['i.is_path'];
976997
break;
977998

978999
case SymbolType::NT_STRING . ".0.1":

src/Query/Exception/IsDefiniteFlagNotFoundException.php renamed to src/Query/Exception/PropertiesNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use LogicException;
77
use Throwable;
88

9-
final class IsDefiniteFlagNotFoundException extends LogicException implements ExceptionInterface
9+
final class PropertiesNotFoundException extends LogicException implements ExceptionInterface
1010
{
1111

1212
public function __construct(Throwable $previous = null)

src/Query/LazyQuery.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,24 @@ public function __invoke(RuntimeInterface $runtime, NodeValueInterface $rootNode
3131
return $this->getLoadedQuery()($runtime, $rootNode);
3232
}
3333

34+
/**
35+
* @return bool
36+
* @deprecated
37+
*/
3438
public function isDefinite(): bool
3539
{
3640
return $this
37-
->getLoadedQuery()
41+
->getProperties()
3842
->isDefinite();
3943
}
4044

45+
public function getProperties(): QueryPropertiesInterface
46+
{
47+
return $this
48+
->getLoadedQuery()
49+
->getProperties();
50+
}
51+
4152
private function getLoadedQuery(): QueryInterface
4253
{
4354
if (!isset($this->loadedQuery)) {

src/Query/Query.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,30 @@ final class Query implements QueryInterface
1313

1414
private $callback;
1515

16-
private $isDefinite;
16+
private $properties;
1717

18-
public function __construct(callable $callback, bool $isDefinite)
18+
public function __construct(callable $callback, QueryPropertiesInterface $properties)
1919
{
2020
$this->callback = $callback;
21-
$this->isDefinite = $isDefinite;
21+
$this->properties = $properties;
2222
}
2323

2424
public function __invoke(RuntimeInterface $runtime, NodeValueInterface $rootNode): ValueListInterface
2525
{
2626
return call_user_func($this->callback, $runtime, $rootNode);
2727
}
2828

29+
/**
30+
* @return bool
31+
* @deprecated
32+
*/
2933
public function isDefinite(): bool
3034
{
31-
return $this->isDefinite;
35+
return $this->properties->isDefinite();
36+
}
37+
38+
public function getProperties(): QueryPropertiesInterface
39+
{
40+
return $this->properties;
3241
}
3342
}

src/Query/QueryAstBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ public function getInput(): int
3636
/**
3737
* @param int $id
3838
* @param bool $isDefinite
39+
* @param bool $isPath
3940
* @throws UniLexException
4041
*/
41-
public function setOutput(int $id, bool $isDefinite): void
42+
public function setOutput(int $id, bool $isDefinite, bool $isPath): void
4243
{
4344
$this
4445
->tree
@@ -48,6 +49,7 @@ public function setOutput(int $id, bool $isDefinite): void
4849
->createNode(QueryAstNodeType::SET_OUTPUT)
4950
->addChild($this->tree->getNode($id))
5051
->setAttribute('is_definite', $isDefinite)
52+
->setAttribute('is_path', $isPath)
5153
);
5254
}
5355

src/Query/QueryAstBuilderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface QueryAstBuilderInterface
88

99
public function getInput(): int;
1010

11-
public function setOutput(int $id, bool $isDefinite): void;
11+
public function setOutput(int $id, bool $isDefinite, bool $isPath): void;
1212

1313
public function createFilterContext(int $id): int;
1414

src/Query/QueryAstTranslator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function buildQuery(Tree $queryAst): QueryInterface
2828

2929
return new Query(
3030
$this->queryCallbackBuilder->getQueryCallback(),
31-
$this->queryCallbackBuilder->isDefinite()
31+
$this->queryCallbackBuilder->getQueryProperties()
3232
);
3333
}
3434
}

src/Query/QueryCallbackBuilder.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class QueryCallbackBuilder extends AbstractTranslatorListener implements Q
4040

4141
private $queryCallback;
4242

43-
private $isDefinite;
43+
private $properties;
4444

4545
public function __construct()
4646
{
@@ -56,13 +56,24 @@ public function getQueryCallback(): callable
5656
throw new Exception\QueryCallbackNotFoundException;
5757
}
5858

59+
/**
60+
* {@inheritDoc}
61+
*
62+
* @return bool
63+
* @deprecated
64+
*/
5965
public function isDefinite(): bool
6066
{
61-
if (isset($this->isDefinite)) {
62-
return $this->isDefinite;
67+
return $this->getQueryProperties()->isDefinite();
68+
}
69+
70+
public function getQueryProperties(): QueryPropertiesInterface
71+
{
72+
if (isset($this->properties)) {
73+
return $this->properties;
6374
}
6475

65-
throw new Exception\IsDefiniteFlagNotFoundException;
76+
throw new Exception\PropertiesNotFoundException;
6677
}
6778

6879
public function onStart(QueryAstNode $node): void
@@ -127,7 +138,10 @@ public function onFinishProduction(QueryAstNode $node): void
127138
break;
128139

129140
case QueryAstNodeType::SET_OUTPUT:
130-
$this->isDefinite = $node->getAttribute('is_definite');
141+
$this->properties = new QueryProperties(
142+
$node->getAttribute('is_definite'),
143+
$node->getAttribute('is_path')
144+
);
131145
$this->stmts[] = new Return_($this->getReference($node->getChild(0)));
132146
break;
133147

src/Query/QueryCallbackBuilderInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ interface QueryCallbackBuilderInterface extends TranslatorListenerInterface
1010

1111
public function getQueryCallback(): callable;
1212

13+
/**
14+
* @return bool
15+
* @deprecated
16+
*/
1317
public function isDefinite(): bool;
18+
19+
public function getQueryProperties(): QueryPropertiesInterface;
1420
}

src/Query/QueryInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ interface QueryInterface
1212

1313
public function __invoke(RuntimeInterface $runtime, NodeValueInterface $rootNode): ValueListInterface;
1414

15+
/**
16+
* @return bool
17+
* @deprecated
18+
*/
1519
public function isDefinite(): bool;
20+
21+
public function getProperties(): QueryPropertiesInterface;
1622
}

0 commit comments

Comments
 (0)