|
4 | 4 |
|
5 | 5 | namespace PhpKafka\PhpAvroSchemaGenerator\Command;
|
6 | 6 |
|
| 7 | +use PhpKafka\PhpAvroSchemaGenerator\Merger\SchemaMergerInterface; |
7 | 8 | use PhpKafka\PhpAvroSchemaGenerator\Optimizer\FieldOrderOptimizer;
|
8 | 9 | use PhpKafka\PhpAvroSchemaGenerator\Optimizer\FullNameOptimizer;
|
9 | 10 | use PhpKafka\PhpAvroSchemaGenerator\Optimizer\OptimizerInterface;
|
10 | 11 | use PhpKafka\PhpAvroSchemaGenerator\Optimizer\PrimitiveSchemaOptimizer;
|
11 | 12 | use PhpKafka\PhpAvroSchemaGenerator\Registry\SchemaRegistry;
|
12 | 13 | use PhpKafka\PhpAvroSchemaGenerator\Merger\SchemaMerger;
|
| 14 | +use PhpKafka\PhpAvroSchemaGenerator\Registry\SchemaRegistryInterface; |
13 | 15 | use Symfony\Component\Console\Command\Command;
|
14 | 16 | use Symfony\Component\Console\Input\InputArgument;
|
15 | 17 | use Symfony\Component\Console\Input\InputInterface;
|
|
18 | 20 |
|
19 | 21 | class SubSchemaMergeCommand extends Command
|
20 | 22 | {
|
| 23 | + private SchemaRegistryInterface $schemaRegistry; |
| 24 | + private SchemaMergerInterface $schemaMerger; |
| 25 | + |
21 | 26 | /** @var string[] */
|
22 |
| - protected $optimizerOptionMapping = [ |
| 27 | + protected array $optimizerOptionMapping = [ |
23 | 28 | 'optimizeFieldOrder' => FieldOrderOptimizer::class,
|
24 | 29 | 'optimizeFullNames' => FullNameOptimizer::class,
|
25 | 30 | 'optimizePrimitiveSchemas' => PrimitiveSchemaOptimizer::class,
|
26 | 31 | ];
|
| 32 | + |
| 33 | + public function __construct( |
| 34 | + SchemaMergerInterface $schemaMerger, |
| 35 | + SchemaRegistryInterface $schemaRegistry, |
| 36 | + string $name = null |
| 37 | + ) { |
| 38 | + $this->schemaMerger = $schemaMerger; |
| 39 | + $this->schemaRegistry = $schemaRegistry; |
| 40 | + parent::__construct($name); |
| 41 | + } |
| 42 | + |
27 | 43 | protected function configure(): void
|
28 | 44 | {
|
29 | 45 | $this
|
@@ -71,20 +87,19 @@ public function execute(InputInterface $input, OutputInterface $output): int
|
71 | 87 | $templateDirectory = $this->getPath($templateDirectoryArg);
|
72 | 88 | $outputDirectory = $this->getPath($outputDirectoryArg);
|
73 | 89 |
|
74 |
| - $registry = (new SchemaRegistry()) |
75 |
| - ->addSchemaTemplateDirectory($templateDirectory) |
76 |
| - ->load(); |
| 90 | + $registry = $this->schemaRegistry->addSchemaTemplateDirectory($templateDirectory)->load(); |
77 | 91 |
|
78 |
| - $merger = new SchemaMerger($registry, $outputDirectory); |
| 92 | + $this->schemaMerger->setSchemaRegistry($registry); |
| 93 | + $this->schemaMerger->setOutputDirectory($outputDirectory); |
79 | 94 |
|
80 | 95 | /** @var OptimizerInterface $optimizerClass */
|
81 | 96 | foreach ($this->optimizerOptionMapping as $optionName => $optimizerClass) {
|
82 | 97 | if (true === (bool) $input->getOption($optionName)) {
|
83 |
| - $merger->addOptimizer(new $optimizerClass()); |
| 98 | + $this->schemaMerger->addOptimizer(new $optimizerClass()); |
84 | 99 | }
|
85 | 100 | }
|
86 | 101 |
|
87 |
| - $result = $merger->merge( |
| 102 | + $result = $this->schemaMerger->merge( |
88 | 103 | (bool) $input->getOption('prefixWithNamespace'),
|
89 | 104 | (bool) $input->getOption('useFilenameAsSchemaName')
|
90 | 105 | );
|
|
0 commit comments