Skip to content

Commit 63e7a85

Browse files
committed
Revert to the older config syntaxe
1 parent 90ba0b9 commit 63e7a85

File tree

11 files changed

+299
-106
lines changed

11 files changed

+299
-106
lines changed

src/Builder/AlternativeLoader.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,46 @@ public function addBooleanParam(int|string $key, Node\Expr $param): StepBuilderI
7474
return $this;
7575
}
7676

77+
public function addDateParam(int|string $key, Node\Expr $param): self
78+
{
79+
$this->parameters[$key] = [
80+
'value' => $param,
81+
'type' => 'date',
82+
];
83+
84+
return $this;
85+
}
86+
87+
public function addDateTimeParam(int|string $key, Node\Expr $param): self
88+
{
89+
$this->parameters[$key] = [
90+
'value' => $param,
91+
'type' => 'datetime',
92+
];
93+
94+
return $this;
95+
}
96+
97+
public function addJSONParam(int|string $key, Node\Expr $param): self
98+
{
99+
$this->parameters[$key] = [
100+
'value' => $param,
101+
'type' => 'json',
102+
];
103+
104+
return $this;
105+
}
106+
107+
public function addBinaryParam(int|string $key, Node\Expr $param): self
108+
{
109+
$this->parameters[$key] = [
110+
'value' => $param,
111+
'type' => 'binary',
112+
];
113+
114+
return $this;
115+
}
116+
77117
public function getNode(): Node
78118
{
79119
return new Node\Stmt\Expression(

src/Builder/AlternativeLookup.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,46 @@ public function addBooleanParam(int|string $key, Node\Expr $param): StepBuilderI
7777
return $this;
7878
}
7979

80+
public function addDateParam(int|string $key, Node\Expr $param): self
81+
{
82+
$this->parameters[$key] = [
83+
'value' => $param,
84+
'type' => 'date',
85+
];
86+
87+
return $this;
88+
}
89+
90+
public function addDateTimeParam(int|string $key, Node\Expr $param): self
91+
{
92+
$this->parameters[$key] = [
93+
'value' => $param,
94+
'type' => 'datetime',
95+
];
96+
97+
return $this;
98+
}
99+
100+
public function addJSONParam(int|string $key, Node\Expr $param): self
101+
{
102+
$this->parameters[$key] = [
103+
'value' => $param,
104+
'type' => 'json',
105+
];
106+
107+
return $this;
108+
}
109+
110+
public function addBinaryParam(int|string $key, Node\Expr $param): self
111+
{
112+
$this->parameters[$key] = [
113+
'value' => $param,
114+
'type' => 'binary',
115+
];
116+
117+
return $this;
118+
}
119+
80120
public function withMerge(Builder $merge): self
81121
{
82122
$this->merge = $merge;

src/Builder/Extractor.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,46 @@ public function addBooleanParam(int|string $key, Node\Expr $param): StepBuilderI
115115
return $this;
116116
}
117117

118+
public function addDateParam(int|string $key, Node\Expr $param): self
119+
{
120+
$this->parameters[$key] = [
121+
'value' => $param,
122+
'type' => 'date',
123+
];
124+
125+
return $this;
126+
}
127+
128+
public function addDateTimeParam(int|string $key, Node\Expr $param): self
129+
{
130+
$this->parameters[$key] = [
131+
'value' => $param,
132+
'type' => 'datetime',
133+
];
134+
135+
return $this;
136+
}
137+
138+
public function addJSONParam(int|string $key, Node\Expr $param): self
139+
{
140+
$this->parameters[$key] = [
141+
'value' => $param,
142+
'type' => 'json',
143+
];
144+
145+
return $this;
146+
}
147+
148+
public function addBinaryParam(int|string $key, Node\Expr $param): self
149+
{
150+
$this->parameters[$key] = [
151+
'value' => $param,
152+
'type' => 'binary',
153+
];
154+
155+
return $this;
156+
}
157+
118158
public function getNode(): Node
119159
{
120160
return new Node\Expr\New_(

src/Builder/Loader.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,46 @@ public function addBooleanParam(int|string $key, Node\Expr $param): StepBuilderI
115115
return $this;
116116
}
117117

118+
public function addDateParam(int|string $key, Node\Expr $param): self
119+
{
120+
$this->parameters[$key] = [
121+
'value' => $param,
122+
'type' => 'date',
123+
];
124+
125+
return $this;
126+
}
127+
128+
public function addDateTimeParam(int|string $key, Node\Expr $param): self
129+
{
130+
$this->parameters[$key] = [
131+
'value' => $param,
132+
'type' => 'datetime',
133+
];
134+
135+
return $this;
136+
}
137+
138+
public function addJSONParam(int|string $key, Node\Expr $param): self
139+
{
140+
$this->parameters[$key] = [
141+
'value' => $param,
142+
'type' => 'json',
143+
];
144+
145+
return $this;
146+
}
147+
148+
public function addBinaryParam(int|string $key, Node\Expr $param): self
149+
{
150+
$this->parameters[$key] = [
151+
'value' => $param,
152+
'type' => 'binary',
153+
];
154+
155+
return $this;
156+
}
157+
118158
public function getNode(): Node
119159
{
120160
return new Node\Expr\New_(

src/Configuration/Parameters.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,9 @@ public function getConfigTreeBuilder(): TreeBuilder
2222
})
2323
->thenUnset()
2424
->end()
25+
->useAttributeAsKey('key', false)
2526
->arrayPrototype()
2627
->children()
27-
->variableNode('key')
28-
->isRequired()
29-
->validate()
30-
->ifTrue(isExpression())
31-
->then(asExpression())
32-
->end()
33-
->validate()
34-
->ifTrue(function ($value) {
35-
return !is_string($value) && !is_int($value);
36-
})
37-
->thenInvalid('The parameter\'s key must be of a string or an integer.')
38-
->end()
39-
->end()
4028
->scalarNode('value')
4129
->isRequired()
4230
->validate()
@@ -45,7 +33,7 @@ public function getConfigTreeBuilder(): TreeBuilder
4533
->end()
4634
->end()
4735
->enumNode('type')
48-
->values(['boolean', 'integer', 'string'])
36+
->values(['boolean', 'integer', 'string', 'date', 'datetime', 'json', 'binary'])
4937
->end()
5038
->end()
5139
->end();

src/Factory/Extractor.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,34 @@ public function compile(array $config): SQL\Factory\Repository\Extractor
5454
);
5555

5656
if (array_key_exists('parameters', $config)) {
57-
foreach ($config["parameters"] as $parameter) {
57+
foreach ($config["parameters"] as $key => $parameter) {
5858
match (array_key_exists('type', $parameter) ? $parameter["type"] : null) {
5959
'integer' => $extractor->addIntegerParam(
60-
$parameter["key"],
60+
$key,
6161
compileValueWhenExpression($this->interpreter, $parameter["value"]),
6262
),
6363
'boolean' => $extractor->addBooleanParam(
64-
$parameter["key"],
64+
$key,
65+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
66+
),
67+
'date' => $extractor->addDateParam(
68+
$key,
69+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
70+
),
71+
'datetime' => $extractor->addDateTimeParam(
72+
$key,
73+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
74+
),
75+
'json' => $extractor->addJSONParam(
76+
$key,
77+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
78+
),
79+
'binary' => $extractor->addBinaryParam(
80+
$key,
6581
compileValueWhenExpression($this->interpreter, $parameter["value"]),
6682
),
6783
default => $extractor->addStringParam(
68-
$parameter["key"],
84+
$key,
6985
compileValueWhenExpression($this->interpreter, $parameter["value"]),
7086
),
7187
};

src/Factory/Loader.php

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,34 @@ public function compile(array $config): SQL\Factory\Repository\Loader
5656
);
5757

5858
if (array_key_exists('parameters', $config)) {
59-
foreach ($config["parameters"] as $parameter) {
59+
foreach ($config["parameters"] as $key => $parameter) {
6060
match (array_key_exists('type', $parameter) ? $parameter["type"] : null) {
6161
'integer' => $loader->addIntegerParam(
62-
$parameter["key"],
62+
$key,
6363
compileValueWhenExpression($this->interpreter, $parameter["value"]),
6464
),
6565
'boolean' => $loader->addBooleanParam(
66-
$parameter["key"],
66+
$key,
67+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
68+
),
69+
'date' => $loader->addDateParam(
70+
$key,
71+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
72+
),
73+
'datetime' => $loader->addDateTimeParam(
74+
$key,
75+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
76+
),
77+
'json' => $loader->addJSONParam(
78+
$key,
79+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
80+
),
81+
'binary' => $loader->addBinaryParam(
82+
$key,
6783
compileValueWhenExpression($this->interpreter, $parameter["value"]),
6884
),
6985
default => $loader->addStringParam(
70-
$parameter["key"],
86+
$key,
7187
compileValueWhenExpression($this->interpreter, $parameter["value"]),
7288
),
7389
};
@@ -82,18 +98,34 @@ public function compile(array $config): SQL\Factory\Repository\Loader
8298
);
8399

84100
if (array_key_exists('parameters', $alternative)) {
85-
foreach ($alternative["parameters"] as $parameter) {
101+
foreach ($alternative["parameters"] as $key => $parameter) {
86102
match (array_key_exists('type', $parameter) ? $parameter["type"] : null) {
87103
'integer' => $alternativeLoaderBuilder->addIntegerParam(
88-
$parameter["key"],
104+
$key,
89105
compileValueWhenExpression($this->interpreter, $parameter["value"]),
90106
),
91107
'boolean' => $alternativeLoaderBuilder->addBooleanParam(
92-
$parameter["key"],
108+
$key,
109+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
110+
),
111+
'date' => $alternativeLoaderBuilder->addDateParam(
112+
$key,
113+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
114+
),
115+
'datetime' => $alternativeLoaderBuilder->addDateTimeParam(
116+
$key,
117+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
118+
),
119+
'json' => $alternativeLoaderBuilder->addJSONParam(
120+
$key,
121+
compileValueWhenExpression($this->interpreter, $parameter["value"]),
122+
),
123+
'binary' => $alternativeLoaderBuilder->addBinaryParam(
124+
$key,
93125
compileValueWhenExpression($this->interpreter, $parameter["value"]),
94126
),
95127
default => $alternativeLoaderBuilder->addStringParam(
96-
$parameter["key"],
128+
$key,
97129
compileValueWhenExpression($this->interpreter, $parameter["value"]),
98130
),
99131
};

0 commit comments

Comments
 (0)