Skip to content

Commit

Permalink
Commands as services
Browse files Browse the repository at this point in the history
  • Loading branch information
jmleroux committed Feb 27, 2023
1 parent 4e9a2ad commit f54d6f9
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions app/Application.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<?php

use Akeneo\Command\InfoTranslatedProgressCommand;
use Akeneo\Command\PullTranslationsCommand;
use Akeneo\Command\PushTranslationKeysCommand;
use Akeneo\Command\RefreshPackagesCommand;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand Down Expand Up @@ -44,14 +39,16 @@ public function __construct($name = 'crowdin', $version = 'UNKNOWN')

if (!file_exists(sprintf($configFilePath))) {
$output = new ConsoleOutput();
$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
));
$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);
Expand All @@ -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));
}
}

/**
Expand Down

0 comments on commit f54d6f9

Please sign in to comment.