22
33namespace Kiboko \Plugin \SQL ;
44
5- use Kiboko \Component \SatelliteToolbox \Builder \IsolatedCodeBuilder ;
6- use Kiboko \Contract \Configurator \FactoryInterface ;
7- use Kiboko \Contract \Configurator \InvalidConfigurationException ;
8- use Kiboko \Contract \Configurator \RepositoryInterface ;
5+ use Kiboko \Contract \Configurator ;
96use Kiboko \Plugin \SQL \Factory \Connection ;
10- use Kiboko \Plugin \SQL \Factory \InitializerQueries ;
11- use PhpParser \Builder ;
127use Symfony \Component \Config \Definition \ConfigurationInterface ;
138use Symfony \Component \Config \Definition \Processor ;
149use Symfony \Component \ExpressionLanguage \ExpressionLanguage ;
1510use Symfony \Component \Config \Definition \Exception as Symfony ;
1611
17- final class Service implements FactoryInterface
12+ #[Configurator \Pipeline(
13+ name: "sql " ,
14+ dependencies: [
15+ 'ext-pdo ' ,
16+ ],
17+ steps: [
18+ "extractor " => "extractor " ,
19+ "lookup " => "transformer " ,
20+ "loader " => "loader " ,
21+ ],
22+ )]
23+ final class Service implements Configurator \FactoryInterface
1824{
1925 private Processor $ processor ;
2026 private ConfigurationInterface $ configuration ;
@@ -37,7 +43,7 @@ public function normalize(array $config): array
3743 try {
3844 return $ this ->processor ->processConfiguration ($ this ->configuration , $ config );
3945 } catch (Symfony \InvalidTypeException |Symfony \InvalidConfigurationException $ exception ) {
40- throw new InvalidConfigurationException ($ exception ->getMessage (), 0 , $ exception );
46+ throw new Configurator \ InvalidConfigurationException ($ exception ->getMessage (), 0 , $ exception );
4147 }
4248 }
4349
@@ -52,7 +58,7 @@ public function validate(array $config): bool
5258 }
5359 }
5460
55- public function compile (array $ config ): RepositoryInterface
61+ public function compile (array $ config ): Factory \ Repository \ Extractor | Factory \ Repository \ Lookup | Factory \ Repository \ Loader
5662 {
5763 if (array_key_exists ('expression_language ' , $ config )
5864 && is_array ($ config ['expression_language ' ])
@@ -65,38 +71,34 @@ public function compile(array $config): RepositoryInterface
6571
6672 $ connection = (new Connection ($ this ->interpreter ))->compile ($ config ['connection ' ]);
6773
68- try {
69- if (array_key_exists ('extractor ' , $ config )) {
70- $ extractorFactory = new Factory \Extractor ($ this ->interpreter );
74+ if (array_key_exists ('extractor ' , $ config )) {
75+ $ extractorFactory = new Factory \Extractor ($ this ->interpreter );
7176
72- return $ extractorFactory
73- ->compile ($ config ['extractor ' ])
74- ->withConnection ($ connection )
75- ->withBeforeQueries (...($ config ['before ' ]['queries ' ] ?? []))
76- ->withAfterQueries (...($ config ['after ' ]['queries ' ] ?? []));
77- } elseif (array_key_exists ('lookup ' , $ config )) {
78- $ lookupFactory = new Factory \Lookup ($ this ->interpreter );
77+ return $ extractorFactory
78+ ->compile ($ config ['extractor ' ])
79+ ->withConnection ($ connection )
80+ ->withBeforeQueries (...($ config ['before ' ]['queries ' ] ?? []))
81+ ->withAfterQueries (...($ config ['after ' ]['queries ' ] ?? []));
82+ } elseif (array_key_exists ('lookup ' , $ config )) {
83+ $ lookupFactory = new Factory \Lookup ($ this ->interpreter );
7984
80- return $ lookupFactory
81- ->compile ($ config ['lookup ' ])
82- ->withConnection ($ connection )
83- ->withBeforeQueries (...($ config ['before ' ]['queries ' ] ?? []))
84- ->withAfterQueries (...($ config ['after ' ]['queries ' ] ?? []));
85- } elseif (array_key_exists ('loader ' , $ config )) {
86- $ loaderFactory = new Factory \Loader ($ this ->interpreter );
85+ return $ lookupFactory
86+ ->compile ($ config ['lookup ' ])
87+ ->withConnection ($ connection )
88+ ->withBeforeQueries (...($ config ['before ' ]['queries ' ] ?? []))
89+ ->withAfterQueries (...($ config ['after ' ]['queries ' ] ?? []));
90+ } elseif (array_key_exists ('loader ' , $ config )) {
91+ $ loaderFactory = new Factory \Loader ($ this ->interpreter );
8792
88- return $ loaderFactory
89- ->compile ($ config ['loader ' ])
90- ->withConnection ($ connection )
91- ->withBeforeQueries (...($ config ['before ' ]['queries ' ] ?? []))
92- ->withAfterQueries (...($ config ['after ' ]['queries ' ] ?? []));
93- } else {
94- throw new InvalidConfigurationException (
95- 'Could not determine if the factory should build an extractor, a lookup or a loader. '
96- );
97- }
98- } catch (InvalidConfigurationException $ exception ) {
99- throw new InvalidConfigurationException ($ exception ->getMessage (), 0 , $ exception );
93+ return $ loaderFactory
94+ ->compile ($ config ['loader ' ])
95+ ->withConnection ($ connection )
96+ ->withBeforeQueries (...($ config ['before ' ]['queries ' ] ?? []))
97+ ->withAfterQueries (...($ config ['after ' ]['queries ' ] ?? []));
98+ } else {
99+ throw new Configurator \InvalidConfigurationException (
100+ 'Could not determine if the factory should build an extractor, a lookup or a loader. '
101+ );
100102 }
101103 }
102104}
0 commit comments