From 41117ba90e71ccc266b94c34fde02bd14d4908d3 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 4 Feb 2018 13:53:42 +0100 Subject: [PATCH 1/7] Inject depedencies to the commands --- Command/BundleTrait.php | 2 + Command/DeleteObsoleteCommand.php | 61 +++++++++++++-- Command/DownloadCommand.php | 54 ++++++++++--- Command/ExtractCommand.php | 81 ++++++++++++++++---- Command/StatusCommand.php | 53 ++++++++++--- Command/SyncCommand.php | 28 +++++-- DependencyInjection/TranslationExtension.php | 2 + Resources/config/console.yml | 25 ++++++ Resources/config/services.yml | 3 + Service/StorageManager.php | 75 ++++++++++++++++++ 10 files changed, 335 insertions(+), 49 deletions(-) create mode 100644 Service/StorageManager.php diff --git a/Command/BundleTrait.php b/Command/BundleTrait.php index e555a8bc..37397d1e 100644 --- a/Command/BundleTrait.php +++ b/Command/BundleTrait.php @@ -12,6 +12,7 @@ namespace Translation\Bundle\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\HttpKernel\Bundle\Bundle; use Translation\Bundle\Model\Configuration; trait BundleTrait @@ -27,6 +28,7 @@ private function configureBundleDirs(InputInterface $input, Configuration $confi } } + /** @var Bundle $bundle */ $bundle = $this->getApplication() ->getKernel() ->getBundle($bundleName) diff --git a/Command/DeleteObsoleteCommand.php b/Command/DeleteObsoleteCommand.php index 215cb62e..75623e82 100644 --- a/Command/DeleteObsoleteCommand.php +++ b/Command/DeleteObsoleteCommand.php @@ -12,24 +12,71 @@ namespace Translation\Bundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; +use Translation\Bundle\Catalogue\CatalogueFetcher; +use Translation\Bundle\Catalogue\CatalogueManager; +use Translation\Bundle\Service\ConfigurationManager; +use Translation\Bundle\Service\StorageManager; /** * @author Tobias Nyholm */ -class DeleteObsoleteCommand extends ContainerAwareCommand +class DeleteObsoleteCommand extends Command { use BundleTrait; + protected static $defaultName = 'translation:delete-obsolete'; + + /** + * @var StorageManager + */ + private $storageManager; + + /** + * @var ConfigurationManager + */ + private $configurationManager; + + /** + * @var CatalogueManager + */ + private $catalogueManager; + + /** + * @var CatalogueFetcher + */ + private $catalogueFetcher; + + /** + * + * @param StorageManager $storageManager + * @param ConfigurationManager $configurationManager + * @param CatalogueManager $catalogueManager + * @param CatalogueFetcher $catalogueFetcher + */ + public function __construct( + StorageManager $storageManager, + ConfigurationManager $configurationManager, + CatalogueManager $catalogueManager, + CatalogueFetcher $catalogueFetcher + ) { + $this->storageManager = $storageManager; + $this->configurationManager = $configurationManager; + $this->catalogueManager = $catalogueManager; + $this->catalogueFetcher = $catalogueFetcher; + parent::__construct(); + } + + protected function configure() { $this - ->setName('translation:delete-obsolete') ->setDescription('Delete all translations marked as obsolete.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', null) @@ -39,20 +86,18 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $container = $this->getContainer(); $configName = $input->getArgument('configuration'); $locales = []; if (null !== $inputLocale = $input->getArgument('locale')) { $locales = [$inputLocale]; } - $catalogueManager = $container->get('php_translation.catalogue_manager'); - $config = $container->get('php_translation.configuration_manager')->getConfiguration($configName); + $config = $this->configurationManager->getConfiguration($configName); $this->configureBundleDirs($input, $config); - $catalogueManager->load($container->get('php_translation.catalogue_fetcher')->getCatalogues($config, $locales)); + $this->catalogueManager->load($this->catalogueFetcher->getCatalogues($config, $locales)); - $storage = $container->get('php_translation.storage.'.$configName); - $messages = $catalogueManager->findMessages(['locale' => $inputLocale, 'isObsolete' => true]); + $storage = $this->storageManager->getStorage($configName); + $messages = $this->catalogueManager->findMessages(['locale' => $inputLocale, 'isObsolete' => true]); $messageCount = count($messages); if (0 === $messageCount) { diff --git a/Command/DownloadCommand.php b/Command/DownloadCommand.php index 3e3ced85..061fffe0 100644 --- a/Command/DownloadCommand.php +++ b/Command/DownloadCommand.php @@ -12,25 +12,63 @@ namespace Translation\Bundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\Finder; +use Translation\Bundle\Service\CacheClearer; +use Translation\Bundle\Service\ConfigurationManager; +use Translation\Bundle\Service\StorageManager; use Translation\Bundle\Service\StorageService; use Translation\Bundle\Model\Configuration; /** * @author Tobias Nyholm */ -class DownloadCommand extends ContainerAwareCommand +class DownloadCommand extends Command { use BundleTrait; + protected static $defaultName = 'translation:download'; + + /** + * @var StorageManager + */ + private $storageManager; + + /** + * @var ConfigurationManager + */ + private $configurationManager; + + /** + * @var CacheClearer + */ + private $cacheCleaner; + + /** + * + * @param StorageManager $storageManager + * @param ConfigurationManager $configurationManager + * @param CacheClearer $cacheCleaner + */ + public function __construct( + StorageManager $storageManager, + ConfigurationManager $configurationManager, + CacheClearer $cacheCleaner + ) { + $this->storageManager = $storageManager; + $this->configurationManager = $configurationManager; + $this->cacheCleaner = $cacheCleaner; + parent::__construct(); + } + + protected function configure() { $this - ->setName('translation:download') ->setDescription('Replace local messages with messages from remote') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addOption('cache', null, InputOption::VALUE_NONE, 'Clear the cache if the translations have changed') @@ -40,15 +78,10 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $container = $this->getContainer(); $configName = $input->getArgument('configuration'); + $storage = $this->storageManager->getStorage($configName); + $configuration = $this->configurationManager->getConfiguration($configName); - /** @var StorageService $storage */ - $storage = $container->get('php_translation.storage.'.$configName); - - /** @var Configuration $configuration */ - $configuration = $container->get('php_translation.configuration_manager') - ->getConfiguration($input->getArgument('configuration')); $this->configureBundleDirs($input, $configuration); if ($input->getOption('cache')) { @@ -58,8 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $md5AfterDownload = $this->hashDirectory($translationsDirectory); if ($md5BeforeDownload !== $md5AfterDownload) { - $cacheClearer = $this->getContainer()->get('php_translation.cache_clearer'); - $cacheClearer->clearAndWarmUp(); + $this->cacheCleaner->clearAndWarmUp(); } } else { $storage->download(); diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index 4a81aad5..81696e64 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -12,26 +12,83 @@ namespace Translation\Bundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Finder\Finder; +use Translation\Bundle\Catalogue\CatalogueCounter; +use Translation\Bundle\Catalogue\CatalogueFetcher; +use Translation\Bundle\Catalogue\CatalogueWriter; use Translation\Bundle\Model\Configuration; +use Translation\Bundle\Service\ConfigurationManager; +use Translation\Bundle\Service\Importer; use Translation\Extractor\Model\Error; /** * @author Tobias Nyholm */ -class ExtractCommand extends ContainerAwareCommand +class ExtractCommand extends Command { use BundleTrait; + protected static $defaultName = 'translation:extract'; + + /** + * @var CatalogueFetcher + */ + private $catalogueFetcher; + + /** + * @var CatalogueWriter + */ + private $catalogueWriter; + + /** + * @var CatalogueCounter + */ + private $catalogueCounter; + + /** + * @var Importer + */ + private $importer; + + /** + * @var ConfigurationManager + */ + private $configurationManager; + + /** + * + * @param CatalogueFetcher $catalogueFetcher + * @param CatalogueWriter $catalogueWriter + * @param CatalogueCounter $catalogueCounter + * @param Importer $importer + * @param ConfigurationManager $configurationManager + */ + public function __construct( + CatalogueFetcher $catalogueFetcher, + CatalogueWriter $catalogueWriter, + CatalogueCounter $catalogueCounter, + Importer $importer, + ConfigurationManager $configurationManager + ) { + $this->catalogueFetcher = $catalogueFetcher; + $this->catalogueWriter = $catalogueWriter; + $this->catalogueCounter = $catalogueCounter; + $this->importer = $importer; + $this->configurationManager = $configurationManager; + + parent::__construct(); + } + + protected function configure() { $this - ->setName('translation:extract') ->setDescription('Extract translations from source code.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false) @@ -42,35 +99,29 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $container = $this->getContainer(); - $importer = $container->get('php_translation.importer'); - $config = $container->get('php_translation.configuration_manager') - ->getConfiguration($input->getArgument('configuration')); + + $config = $this->configurationManager->getConfiguration($input->getArgument('configuration')); $locales = []; if ($inputLocale = $input->getArgument('locale')) { $locales = [$inputLocale]; } - $catalogues = $container->get('php_translation.catalogue_fetcher') - ->getCatalogues($config, $locales); - + $catalogues = $this->catalogueFetcher->getCatalogues($config, $locales); $this->configureBundleDirs($input, $config); $finder = $this->getConfiguredFinder($config); - $result = $importer->extractToCatalogues($finder, $catalogues, [ + $result = $this->importer->extractToCatalogues($finder, $catalogues, [ 'blacklist_domains' => $config->getBlacklistDomains(), 'whitelist_domains' => $config->getWhitelistDomains(), 'project_root' => $config->getProjectRoot(), ]); $errors = $result->getErrors(); - $container->get('php_translation.catalogue_writer') - ->writeCatalogues($config, $result->getMessageCatalogues()); + $this->catalogueWriter->writeCatalogues($config, $result->getMessageCatalogues()); - $catalogueCounter = $container->get('php_translation.catalogue_counter'); - $definedBefore = $catalogueCounter->getNumberOfDefinedMessages($catalogues[0]); - $definedAfter = $catalogueCounter->getNumberOfDefinedMessages($result->getMessageCatalogues()[0]); + $definedBefore = $this->catalogueCounter->getNumberOfDefinedMessages($catalogues[0]); + $definedAfter = $this->catalogueCounter->getNumberOfDefinedMessages($result->getMessageCatalogues()[0]); /* * Print results diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index 17682d78..f72c4c81 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -12,23 +12,62 @@ namespace Translation\Bundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Translation\Bundle\Catalogue\CatalogueCounter; +use Translation\Bundle\Catalogue\CatalogueFetcher; +use Translation\Bundle\Service\ConfigurationManager; /** * @author Tobias Nyholm */ -class StatusCommand extends ContainerAwareCommand +class StatusCommand extends Command { use BundleTrait; + protected static $defaultName = 'translation:status'; + + /** + * @var CatalogueCounter + */ + private $catalogueCounter; + + /** + * @var ConfigurationManager + */ + private $configurationManager; + + /** + * @var CatalogueFetcher + */ + private $catalogueFetcher; + + /** + * + * @param CatalogueCounter $catalogueCounter + * @param ConfigurationManager $configurationManager + * @param CatalogueFetcher $catalogueFetcher + */ + public function __construct( + CatalogueCounter $catalogueCounter, + ConfigurationManager $configurationManager, + CatalogueFetcher $catalogueFetcher + ) { + $this->catalogueCounter = $catalogueCounter; + $this->configurationManager = $configurationManager; + $this->catalogueFetcher = $catalogueFetcher; + + parent::__construct(); + } + + protected function configure() { $this - ->setName('translation:status') ->setDescription('Show status about your translations.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false) @@ -39,10 +78,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $container = $this->getContainer(); - $counter = $container->get('php_translation.catalogue_counter'); - $config = $container->get('php_translation.configuration_manager') - ->getConfiguration($input->getArgument('configuration')); + $config = $this->configurationManager->getConfiguration($input->getArgument('configuration')); $this->configureBundleDirs($input, $config); $locales = []; @@ -50,12 +86,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $locales = [$inputLocale]; } - $catalogues = $container->get('php_translation.catalogue_fetcher') - ->getCatalogues($config, $locales); + $catalogues = $this->catalogueFetcher->getCatalogues($config, $locales); $stats = []; foreach ($catalogues as $catalogue) { - $stats[$catalogue->getLocale()] = $counter->getCatalogueStatistics($catalogue); + $stats[$catalogue->getLocale()] = $this->catalogueCounter->getCatalogueStatistics($catalogue); } if ($input->getOption('json')) { diff --git a/Command/SyncCommand.php b/Command/SyncCommand.php index badfc958..c93d6e43 100644 --- a/Command/SyncCommand.php +++ b/Command/SyncCommand.php @@ -12,30 +12,46 @@ namespace Translation\Bundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Translation\Bundle\Service\StorageManager; use Translation\Bundle\Service\StorageService; /** * @author Tobias Nyholm */ -class SyncCommand extends ContainerAwareCommand +class SyncCommand extends Command { + protected static $defaultName = 'translation:sync'; + + /** + * @var StorageManager + */ + private $storageManager; + + /** + * + * @param StorageManager $storageManager + */ + public function __construct(StorageManager $storageManager) + { + $this->storageManager = $storageManager; + + parent::__construct(); + } + protected function configure() { $this - ->setName('translation:sync') ->setDescription('Sync the translations with the remote storage') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default'); } protected function execute(InputInterface $input, OutputInterface $output) { - $container = $this->getContainer(); $configName = $input->getArgument('configuration'); - /** @var StorageService $storage */ - $storage = $container->get('php_translation.storage.'.$configName); - $storage->sync(); + $this->storageManager->getStorage($configName)->sync(); } } diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index 4f9f0ac6..b7848507 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -92,6 +92,7 @@ public function load(array $configs, ContainerBuilder $container) */ private function handleConfigNode(ContainerBuilder $container, array $config) { + $storageManager = $container->getDefinition('php_translation.storage_manager'); $configurationManager = $container->getDefinition('php_translation.configuration_manager'); // $first will be the "default" configuration. $first = null; @@ -117,6 +118,7 @@ private function handleConfigNode(ContainerBuilder $container, array $config) $storageDefinition->replaceArgument(2, new Reference($configurationServiceId)); $storageDefinition->setPublic(true); $container->setDefinition('php_translation.storage.'.$name, $storageDefinition); + $storageManager->addMethodCall('addStorage', [$name, new Reference('php_translation.storage.'.$name)]); // Add storages foreach ($c['remote_storage'] as $serviceId) { diff --git a/Resources/config/console.yml b/Resources/config/console.yml index 60f25741..956eb4d2 100644 --- a/Resources/config/console.yml +++ b/Resources/config/console.yml @@ -2,25 +2,50 @@ services: php_translator.console.delete_obsolete: class: Translation\Bundle\Command\DeleteObsoleteCommand public: true + arguments: + - '@php_translation.storage_manager' + - '@php_translation.configuration_manager' + - '@php_translation.catalogue_manager' + - '@php_translation.catalogue_fetcher' tags: - { name: console.command, command: translation:delete-obsolete} + php_translator.console.download: class: Translation\Bundle\Command\DownloadCommand public: true + arguments: + - '@php_translation.storage_manager' + - '@php_translation.configuration_manager' + - '@php_translation.cache_clearer' tags: - { name: console.command, command: translation:download } + php_translator.console.extract: class: Translation\Bundle\Command\ExtractCommand public: true + arguments: + - '@php_translation.catalogue_fetcher' + - '@php_translation.catalogue_writer' + - '@php_translation.catalogue_counter' + - '@php_translation.importer' + - '@php_translation.configuration_manager' tags: - { name: console.command, command: translation:extract } + php_translator.console.status: class: Translation\Bundle\Command\StatusCommand public: true + arguments: + - '@php_translation.catalogue_counter' + - '@php_translation.configuration_manager' + - '@php_translation.catalogue_fetcher' tags: - { name: console.command, command: translation:status } + php_translator.console.sync: class: Translation\Bundle\Command\SyncCommand public: true + arguments: + - '@php_translation.storage_manager' tags: - { name: console.command, command: translation:sync } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 732e93cf..2134db5a 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -21,6 +21,9 @@ services: php_translation.extractor: class: Translation\Extractor\Extractor + php_translation.storage_manager: + class: Translation\Bundle\Service\StorageManager + php_translation.configuration_manager: public: true class: Translation\Bundle\Service\ConfigurationManager diff --git a/Service/StorageManager.php b/Service/StorageManager.php new file mode 100644 index 00000000..98a93ae3 --- /dev/null +++ b/Service/StorageManager.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Translation\Bundle\Service; + +/** + * A service to easily access different storage services. + * + * @author Tobias Nyholm + */ +final class StorageManager +{ + /** + * @var StorageService[] + */ + private $storages = []; + + /** + * @param string $name + * @param StorageService $storage + */ + public function addStorage($name, StorageService $storage) + { + $this->storages[$name] = $storage; + } + + /** + * @param string $name + * + * @return null|StorageService + */ + public function getStorage($name = null) + { + if (empty($name)) { + return $this->getStorage('default'); + } + + if (isset($this->storages[$name])) { + return $this->storages[$name]; + } + + if ('default' === $name) { + $name = $this->getFirstName(); + if (isset($this->storages[$name])) { + return $this->storages[$name]; + } + } + } + + /** + * @return string|null + */ + public function getFirstName() + { + foreach ($this->storages as $name => $config) { + return $name; + } + } + + /** + * @return array + */ + public function getNames() + { + return array_keys($this->storages); + } +} From e26bd8eaeef72e7ef1a7f45ad2bdd603001bfdfa Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 4 Feb 2018 13:57:18 +0100 Subject: [PATCH 2/7] cs and test fix --- Command/DeleteObsoleteCommand.php | 9 +++------ Command/DownloadCommand.php | 8 ++------ Command/ExtractCommand.php | 12 ++++-------- Command/StatusCommand.php | 7 ++----- Command/SyncCommand.php | 3 --- Tests/Functional/Command/ExtractCommandTest.php | 3 ++- Tests/Functional/Command/StatusCommandTest.php | 3 ++- 7 files changed, 15 insertions(+), 30 deletions(-) diff --git a/Command/DeleteObsoleteCommand.php b/Command/DeleteObsoleteCommand.php index 75623e82..b6ee18ed 100644 --- a/Command/DeleteObsoleteCommand.php +++ b/Command/DeleteObsoleteCommand.php @@ -11,7 +11,6 @@ namespace Translation\Bundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; @@ -54,11 +53,10 @@ class DeleteObsoleteCommand extends Command private $catalogueFetcher; /** - * - * @param StorageManager $storageManager + * @param StorageManager $storageManager * @param ConfigurationManager $configurationManager - * @param CatalogueManager $catalogueManager - * @param CatalogueFetcher $catalogueFetcher + * @param CatalogueManager $catalogueManager + * @param CatalogueFetcher $catalogueFetcher */ public function __construct( StorageManager $storageManager, @@ -73,7 +71,6 @@ public function __construct( parent::__construct(); } - protected function configure() { $this diff --git a/Command/DownloadCommand.php b/Command/DownloadCommand.php index 061fffe0..c6c543e7 100644 --- a/Command/DownloadCommand.php +++ b/Command/DownloadCommand.php @@ -11,7 +11,6 @@ namespace Translation\Bundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -21,7 +20,6 @@ use Translation\Bundle\Service\CacheClearer; use Translation\Bundle\Service\ConfigurationManager; use Translation\Bundle\Service\StorageManager; -use Translation\Bundle\Service\StorageService; use Translation\Bundle\Model\Configuration; /** @@ -49,10 +47,9 @@ class DownloadCommand extends Command private $cacheCleaner; /** - * - * @param StorageManager $storageManager + * @param StorageManager $storageManager * @param ConfigurationManager $configurationManager - * @param CacheClearer $cacheCleaner + * @param CacheClearer $cacheCleaner */ public function __construct( StorageManager $storageManager, @@ -65,7 +62,6 @@ public function __construct( parent::__construct(); } - protected function configure() { $this diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index 81696e64..56dc3fec 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -11,7 +11,6 @@ namespace Translation\Bundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -62,11 +61,10 @@ class ExtractCommand extends Command private $configurationManager; /** - * - * @param CatalogueFetcher $catalogueFetcher - * @param CatalogueWriter $catalogueWriter - * @param CatalogueCounter $catalogueCounter - * @param Importer $importer + * @param CatalogueFetcher $catalogueFetcher + * @param CatalogueWriter $catalogueWriter + * @param CatalogueCounter $catalogueCounter + * @param Importer $importer * @param ConfigurationManager $configurationManager */ public function __construct( @@ -85,7 +83,6 @@ public function __construct( parent::__construct(); } - protected function configure() { $this @@ -99,7 +96,6 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $config = $this->configurationManager->getConfiguration($input->getArgument('configuration')); $locales = []; diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index f72c4c81..1cba3dfd 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -11,7 +11,6 @@ namespace Translation\Bundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -47,10 +46,9 @@ class StatusCommand extends Command private $catalogueFetcher; /** - * - * @param CatalogueCounter $catalogueCounter + * @param CatalogueCounter $catalogueCounter * @param ConfigurationManager $configurationManager - * @param CatalogueFetcher $catalogueFetcher + * @param CatalogueFetcher $catalogueFetcher */ public function __construct( CatalogueCounter $catalogueCounter, @@ -64,7 +62,6 @@ public function __construct( parent::__construct(); } - protected function configure() { $this diff --git a/Command/SyncCommand.php b/Command/SyncCommand.php index c93d6e43..fd4c114c 100644 --- a/Command/SyncCommand.php +++ b/Command/SyncCommand.php @@ -11,13 +11,11 @@ namespace Translation\Bundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Translation\Bundle\Service\StorageManager; -use Translation\Bundle\Service\StorageService; /** * @author Tobias Nyholm @@ -32,7 +30,6 @@ class SyncCommand extends Command private $storageManager; /** - * * @param StorageManager $storageManager */ public function __construct(StorageManager $storageManager) diff --git a/Tests/Functional/Command/ExtractCommandTest.php b/Tests/Functional/Command/ExtractCommandTest.php index 35da666a..5eae473c 100644 --- a/Tests/Functional/Command/ExtractCommandTest.php +++ b/Tests/Functional/Command/ExtractCommandTest.php @@ -67,7 +67,8 @@ public function testExecute() $this->bootKernel(); $application = new Application($this->kernel); - $application->add(new ExtractCommand()); + $container = $this->getContainer(); + $application->add($container->get('php_translator.console.extract')); $command = $application->find('translation:extract'); $commandTester = new CommandTester($command); diff --git a/Tests/Functional/Command/StatusCommandTest.php b/Tests/Functional/Command/StatusCommandTest.php index 36b32b1a..1dfbae30 100644 --- a/Tests/Functional/Command/StatusCommandTest.php +++ b/Tests/Functional/Command/StatusCommandTest.php @@ -29,7 +29,8 @@ public function testExecute() $this->bootKernel(); $application = new Application($this->kernel); - $application->add(new StatusCommand()); + $container = $this->getContainer(); + $application->add($container->get('php_translator.console.status')); $command = $application->find('translation:status'); $commandTester = new CommandTester($command); From 962c0916dda90cd2dca02014a31d7d33f810baad Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 4 Feb 2018 13:59:04 +0100 Subject: [PATCH 3/7] cs --- Tests/Functional/Command/ExtractCommandTest.php | 1 - Tests/Functional/Command/StatusCommandTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/Tests/Functional/Command/ExtractCommandTest.php b/Tests/Functional/Command/ExtractCommandTest.php index 5eae473c..963255b8 100644 --- a/Tests/Functional/Command/ExtractCommandTest.php +++ b/Tests/Functional/Command/ExtractCommandTest.php @@ -13,7 +13,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Translation\Bundle\Command\ExtractCommand; use Translation\Bundle\Model\Metadata; use Translation\Bundle\Tests\Functional\BaseTestCase; diff --git a/Tests/Functional/Command/StatusCommandTest.php b/Tests/Functional/Command/StatusCommandTest.php index 1dfbae30..0de0ccb1 100644 --- a/Tests/Functional/Command/StatusCommandTest.php +++ b/Tests/Functional/Command/StatusCommandTest.php @@ -13,7 +13,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Translation\Bundle\Command\StatusCommand; use Translation\Bundle\Tests\Functional\BaseTestCase; class StatusCommandTest extends BaseTestCase From 105ad36a50d3c4d0a9d9cbbbab9958cf9d7ce467 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 4 Feb 2018 14:02:17 +0100 Subject: [PATCH 4/7] Access storage from storage service --- Controller/EditInPlaceController.php | 2 +- Controller/WebUIController.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Controller/EditInPlaceController.php b/Controller/EditInPlaceController.php index f737786f..f3f7395f 100644 --- a/Controller/EditInPlaceController.php +++ b/Controller/EditInPlaceController.php @@ -39,7 +39,7 @@ public function editAction(Request $request, $configName, $locale) } /** @var StorageService $storage */ - $storage = $this->get('php_translation.storage.'.$configName); + $storage = $this->get('php_translation.storage_manager')->getStorage($configName); foreach ($messages as $message) { $storage->update($message); } diff --git a/Controller/WebUIController.php b/Controller/WebUIController.php index ed1a11ab..f397b540 100644 --- a/Controller/WebUIController.php +++ b/Controller/WebUIController.php @@ -137,7 +137,7 @@ public function createAction(Request $request, $configName, $locale, $domain) } /** @var StorageService $storage */ - $storage = $this->get('php_translation.storage.'.$configName); + $storage = $this->get('php_translation.storage_manager')->getStorage($configName); try { $message = $this->getMessageFromRequest($request); @@ -188,7 +188,7 @@ public function editAction(Request $request, $configName, $locale, $domain) } /** @var StorageService $storage */ - $storage = $this->get('php_translation.storage.'.$configName); + $storage = $this->get('php_translation.storage_manager')->getStorage($configName); $storage->update($message); return new Response('Translation updated'); @@ -218,7 +218,7 @@ public function deleteAction(Request $request, $configName, $locale, $domain) } /** @var StorageService $storage */ - $storage = $this->get('php_translation.storage.'.$configName); + $storage = $this->get('php_translation.storage_manager')->getStorage($configName); $storage->delete($locale, $domain, $message->getKey()); return new Response('Message was deleted'); From 8e88b470837ace3ab5064c3c73eb3058cb017a8a Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 12 Feb 2018 10:03:00 +0100 Subject: [PATCH 5/7] Support for sf3.2 --- Command/DeleteObsoleteCommand.php | 1 + Command/DownloadCommand.php | 1 + Command/ExtractCommand.php | 1 + Command/StatusCommand.php | 1 + Command/SyncCommand.php | 1 + 5 files changed, 5 insertions(+) diff --git a/Command/DeleteObsoleteCommand.php b/Command/DeleteObsoleteCommand.php index b6ee18ed..bf635514 100644 --- a/Command/DeleteObsoleteCommand.php +++ b/Command/DeleteObsoleteCommand.php @@ -74,6 +74,7 @@ public function __construct( protected function configure() { $this + ->getName(self::$defaultName) ->setDescription('Delete all translations marked as obsolete.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', null) diff --git a/Command/DownloadCommand.php b/Command/DownloadCommand.php index c6c543e7..cf2909f5 100644 --- a/Command/DownloadCommand.php +++ b/Command/DownloadCommand.php @@ -65,6 +65,7 @@ public function __construct( protected function configure() { $this + ->getName(self::$defaultName) ->setDescription('Replace local messages with messages from remote') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addOption('cache', null, InputOption::VALUE_NONE, 'Clear the cache if the translations have changed') diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index 56dc3fec..f2d5cd47 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -86,6 +86,7 @@ public function __construct( protected function configure() { $this + ->getName(self::$defaultName) ->setDescription('Extract translations from source code.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false) diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index 1cba3dfd..34f3e8bd 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -65,6 +65,7 @@ public function __construct( protected function configure() { $this + ->getName(self::$defaultName) ->setDescription('Show status about your translations.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false) diff --git a/Command/SyncCommand.php b/Command/SyncCommand.php index fd4c114c..14ba8805 100644 --- a/Command/SyncCommand.php +++ b/Command/SyncCommand.php @@ -42,6 +42,7 @@ public function __construct(StorageManager $storageManager) protected function configure() { $this + ->getName(self::$defaultName) ->setDescription('Sync the translations with the remote storage') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default'); } From 3ae3688ad698dcbfdefd240f7d783e6e21b03a8e Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 12 Feb 2018 10:05:50 +0100 Subject: [PATCH 6/7] Make "php_translation.storage_manager" public --- Resources/config/services.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 2134db5a..3c8c913d 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -22,6 +22,7 @@ services: class: Translation\Extractor\Extractor php_translation.storage_manager: + public: true class: Translation\Bundle\Service\StorageManager php_translation.configuration_manager: From 659581aaffa691a3bd74c1b57e6fef7121ddb761 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 12 Feb 2018 11:26:19 +0100 Subject: [PATCH 7/7] Fixed typo --- Command/DeleteObsoleteCommand.php | 2 +- Command/DownloadCommand.php | 2 +- Command/ExtractCommand.php | 2 +- Command/StatusCommand.php | 2 +- Command/SyncCommand.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Command/DeleteObsoleteCommand.php b/Command/DeleteObsoleteCommand.php index bf635514..911af231 100644 --- a/Command/DeleteObsoleteCommand.php +++ b/Command/DeleteObsoleteCommand.php @@ -74,7 +74,7 @@ public function __construct( protected function configure() { $this - ->getName(self::$defaultName) + ->setName(self::$defaultName) ->setDescription('Delete all translations marked as obsolete.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', null) diff --git a/Command/DownloadCommand.php b/Command/DownloadCommand.php index cf2909f5..1b201c8c 100644 --- a/Command/DownloadCommand.php +++ b/Command/DownloadCommand.php @@ -65,7 +65,7 @@ public function __construct( protected function configure() { $this - ->getName(self::$defaultName) + ->setName(self::$defaultName) ->setDescription('Replace local messages with messages from remote') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addOption('cache', null, InputOption::VALUE_NONE, 'Clear the cache if the translations have changed') diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index f2d5cd47..8da04b4d 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -86,7 +86,7 @@ public function __construct( protected function configure() { $this - ->getName(self::$defaultName) + ->setName(self::$defaultName) ->setDescription('Extract translations from source code.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false) diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index 34f3e8bd..a4617121 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -65,7 +65,7 @@ public function __construct( protected function configure() { $this - ->getName(self::$defaultName) + ->setName(self::$defaultName) ->setDescription('Show status about your translations.') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false) diff --git a/Command/SyncCommand.php b/Command/SyncCommand.php index 14ba8805..dccaf929 100644 --- a/Command/SyncCommand.php +++ b/Command/SyncCommand.php @@ -42,7 +42,7 @@ public function __construct(StorageManager $storageManager) protected function configure() { $this - ->getName(self::$defaultName) + ->setName(self::$defaultName) ->setDescription('Sync the translations with the remote storage') ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default'); }