Skip to content

Commit e2a6cdb

Browse files
committed
Fixed the connection options config + updated tests + updated dependencies from php-etl
1 parent 37b293b commit e2a6cdb

File tree

13 files changed

+310
-204
lines changed

13 files changed

+310
-204
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"nikic/php-parser": "^4.10",
1717
"symfony/config": "^5.2",
1818
"symfony/expression-language": "^5.2",
19-
"php-etl/configurator-contracts": "^0.4.0",
19+
"php-etl/configurator-contracts": "0.4.x-dev",
2020
"php-etl/satellite-toolbox": "^0.2.0",
2121
"php-etl/fast-map-plugin": "^0.6.0"
2222
},

composer.lock

Lines changed: 55 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Configuration.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Kiboko\Plugin\SQL;
44

55
use Kiboko\Contract\Configurator\PluginConfigurationInterface;
6+
use Kiboko\Plugin\SQL;
67
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
78
use function Kiboko\Component\SatelliteToolbox\Configuration\asExpression;
89
use function Kiboko\Component\SatelliteToolbox\Configuration\isExpression;
@@ -58,19 +59,7 @@ public function getConfigTreeBuilder()
5859
->then(asExpression())
5960
->end()
6061
->end()
61-
->arrayNode('options')
62-
->arrayPrototype()
63-
->children()
64-
->booleanNode('persistent')
65-
->defaultFalse()
66-
->validate()
67-
->ifTrue(isExpression())
68-
->then(asExpression())
69-
->end()
70-
->end()
71-
->end()
72-
->end()
73-
->end()
62+
->append((new SQL\Configuration\Connection\Options())->getConfigTreeBuilder()->getRootNode())
7463
->end()
7564
->end()
7665
->arrayNode('before')
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Kiboko\Plugin\SQL\Configuration\Connection;
4+
5+
use Kiboko\Plugin\FastMap;
6+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7+
use Symfony\Component\Config\Definition\ConfigurationInterface;
8+
use function Kiboko\Component\SatelliteToolbox\Configuration\asExpression;
9+
use function Kiboko\Component\SatelliteToolbox\Configuration\isExpression;
10+
11+
final class Options implements ConfigurationInterface
12+
{
13+
public function getConfigTreeBuilder()
14+
{
15+
$builder = new TreeBuilder('options');
16+
17+
/** @phpstan-ignore-next-line */
18+
$builder->getRootNode()
19+
->validate()
20+
->ifTrue(function (array $data) {
21+
return count($data) <= 0;
22+
})
23+
->thenUnset()
24+
->end()
25+
->children()
26+
->booleanNode('persistent')
27+
->validate()
28+
->ifTrue(isExpression())
29+
->then(asExpression())
30+
->end()
31+
->end()
32+
->end()
33+
;
34+
35+
return $builder;
36+
}
37+
38+
private function getConditionalTreeBuilder(): TreeBuilder
39+
{
40+
$builder = new TreeBuilder('conditional');
41+
42+
/** @phpstan-ignore-next-line */
43+
$builder->getRootNode()
44+
->cannotBeEmpty()
45+
->requiresAtLeastOneElement()
46+
->validate()
47+
->ifTrue(fn ($data) => count($data) <= 0)
48+
->thenUnset()
49+
->end()
50+
->arrayPrototype()
51+
->children()
52+
->variableNode('condition')
53+
->validate()
54+
->ifTrue(isExpression())
55+
->then(asExpression())
56+
->end()
57+
->end()
58+
->append((new Query())->getConfigTreeBuilder()->getRootNode())
59+
->append((new Parameters())->getConfigTreeBuilder()->getRootNode())
60+
->append((new FastMap\Configuration('merge'))->getConfigTreeBuilder()->getRootNode())
61+
->end()
62+
->end()
63+
->end();
64+
65+
return $builder;
66+
}
67+
}

src/Configuration/Parameters.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,23 @@ public function getConfigTreeBuilder()
2323
})
2424
->thenUnset()
2525
->end()
26-
->useAttributeAsKey('key')
27-
->variablePrototype()
28-
->isRequired()
29-
->cannotBeEmpty()
30-
->validate()
31-
->ifTrue(isExpression())
32-
->then(asExpression())
26+
->arrayPrototype()
27+
->children()
28+
->scalarNode('key')
29+
->isRequired()
30+
->validate()
31+
->ifTrue(isExpression())
32+
->then(asExpression())
33+
->end()
34+
->end()
35+
->scalarNode('value')
36+
->isRequired()
37+
->validate()
38+
->ifTrue(isExpression())
39+
->then(asExpression())
40+
->end()
41+
->end()
42+
->scalarNode('type')->end()
3343
->end()
3444
->end();
3545

src/Configuration/Query.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ class Query implements ConfigurationInterface
1111
{
1212
public function getConfigTreeBuilder()
1313
{
14-
$builder = new TreeBuilder('query', 'scalar');
15-
16-
return $builder;
14+
return new TreeBuilder('query', 'scalar');
1715
}
1816
}

src/Factory/Extractor.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Symfony\Component\Config\Definition\Processor;
1010
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1111
use Symfony\Component\Config\Definition\Exception as Symfony;
12-
use function Kiboko\Component\SatelliteToolbox\Configuration\compileValue;
1312
use function Kiboko\Component\SatelliteToolbox\Configuration\compileValueWhenExpression;
1413

1514
final class Extractor implements FactoryInterface
@@ -54,9 +53,9 @@ public function compile(array $config): SQL\Factory\Repository\Extractor
5453
compileValueWhenExpression($this->interpreter, $config['query']),
5554
);
5655

57-
if ($config['parameters'] != null) {
58-
foreach ($config["parameters"] as $key => $value) {
59-
$extractor->addParameter($key, compileValue($this->interpreter, $value));
56+
if ($config['parameters'] !== null) {
57+
foreach ($config["parameters"] as $key => $parameter) {
58+
$extractor->addParameter($key, compileValueWhenExpression($this->interpreter, $parameter));
6059
}
6160
}
6261

src/Factory/Loader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public function compile(array $config): SQL\Factory\Repository\Loader
5555
compileValueWhenExpression($this->interpreter, $config["query"]),
5656
);
5757

58-
if ($config['parameters'] != null) {
59-
foreach ($config["parameters"] as $parameter) {
60-
$loader->addParameter($parameter['key'], compileValue($this->interpreter, $parameter['value']));
58+
if ($config['parameters'] !== null) {
59+
foreach ($config["parameters"] as $key => $parameter) {
60+
$loader->addParameter($key, compileValue($this->interpreter, $parameter));
6161
}
6262
}
6363
} else {
@@ -69,8 +69,8 @@ public function compile(array $config): SQL\Factory\Repository\Loader
6969
);
7070

7171
if (array_key_exists('parameters', $alternative)) {
72-
foreach ($alternative["parameters"] as $param) {
73-
$alternativeLoaderBuilder->addParam($param["key"], compileValueWhenExpression($this->interpreter, $param["value"]));
72+
foreach ($alternative["parameters"] as $key => $parameter) {
73+
$alternativeLoaderBuilder->addParam($key, compileValueWhenExpression($this->interpreter, $parameter));
7474
}
7575
}
7676

src/Factory/Lookup.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
use Kiboko\Contract\Configurator\InvalidConfigurationException;
88
use Kiboko\Plugin\SQL;
99
use Kiboko\Contract\Configurator\FactoryInterface;
10-
use Kiboko\Contract\Configurator\RepositoryInterface;
1110
use Symfony\Component\Config\Definition\ConfigurationInterface;
1211
use Symfony\Component\Config\Definition\Processor;
1312
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1413
use Symfony\Component\Config\Definition\Exception as Symfony;
15-
use function Kiboko\Component\SatelliteToolbox\Configuration\compileValue;
1614
use function Kiboko\Component\SatelliteToolbox\Configuration\compileValueWhenExpression;
1715

1816
final class Lookup implements FactoryInterface
@@ -82,8 +80,8 @@ public function compile(array $config): SQL\Factory\Repository\Lookup
8280
$lookup = new SQL\Builder\Lookup($alternativeBuilder);
8381

8482
if (array_key_exists('parameters', $config)) {
85-
foreach ($config["parameters"] as $parameter) {
86-
$alternativeBuilder->addParam($parameter["key"], compileValueWhenExpression($this->interpreter, $parameter["value"]));
83+
foreach ($config["parameters"] as $key => $parameter) {
84+
$alternativeBuilder->addParam($key, compileValueWhenExpression($this->interpreter, $parameter));
8785
}
8886
}
8987

@@ -97,8 +95,8 @@ public function compile(array $config): SQL\Factory\Repository\Lookup
9795
);
9896

9997
if (array_key_exists('parameters', $alternative)) {
100-
foreach ($alternative["parameters"] as $param) {
101-
$alternativeBuilder->addParam($param["key"], compileValueWhenExpression($this->interpreter, $param["value"]));
98+
foreach ($alternative["parameters"] as $key => $parameter) {
99+
$alternativeBuilder->addParam($key, compileValueWhenExpression($this->interpreter, $parameter));
102100
}
103101
}
104102

tests/functional/Builder/ExtractorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace functional\Kiboko\Plugin\SQL;
44

55
use Kiboko\Component\PHPUnitExtension\Assert;
6+
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
67
use Kiboko\Plugin\SQL\Factory\Extractor;
78
use PHPUnit\Framework\TestCase;
89
use Symfony\Component\ExpressionLanguage\Expression;
@@ -50,4 +51,9 @@ public function testNormalizingConfiguration(): void
5051
]),
5152
);
5253
}
54+
55+
public function pipelineRunner(): PipelineRunnerInterface
56+
{
57+
return new PipelineRunner();
58+
}
5359
}

0 commit comments

Comments
 (0)