From f54d6f90b17ca9ac18636b1ad1c4f7acdef20277 Mon Sep 17 00:00:00 2001 From: jmleroux Date: Sun, 26 Feb 2023 23:10:18 +0100 Subject: [PATCH] Commands as services --- app/Application.php | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/app/Application.php b/app/Application.php index 2a11ee4..a918c0b 100644 --- a/app/Application.php +++ b/app/Application.php @@ -1,15 +1,10 @@ writeln(sprintf( - "\n The file %s%s%s was not found!". - "\n You need to create your own configuration file.". - "\n You can use --config_file[=CONFIG_FILE] to change default configuration file.\n", - __DIR__, - DIRECTORY_SEPARATOR, - $configFilePath - )); + $output->writeln( + sprintf( + "\n The file %s%s%s was not found!" . + "\n You need to create your own configuration file." . + "\n You can use --config_file[=CONFIG_FILE] to change default configuration file.\n", + __DIR__, + DIRECTORY_SEPARATOR, + $configFilePath + ) + ); } else { $loader = new YamlFileLoader($this->container, new FileLocator(__DIR__)); $loader->load($configFilePath); @@ -66,10 +63,24 @@ public function __construct($name = 'crowdin', $version = 'UNKNOWN') */ protected function registerCommands() { - $this->add($this->container->get(InfoTranslatedProgressCommand::class)); - $this->add($this->container->get(PullTranslationsCommand::class)); - $this->add($this->container->get(PushTranslationKeysCommand::class)); - $this->add($this->container->get(RefreshPackagesCommand::class)); + $finder = new Finder(); + $finder->files() + ->in(__DIR__ . '/../src/Akeneo/Command') + ->name('*Command.php'); + + foreach ($finder as $file) { + $reflection = new ReflectionClass( + sprintf('\\Akeneo\\Command\\%s', $file->getBasename('.php')) + ); + + // Exclude abstract layers + if ($reflection->isAbstract()) { + continue; + } + + $classname = $reflection->getName(); + $this->add($this->container->get($classname)); + } } /**