use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
+use Drupal\Console\Core\Command\ContainerAwareCommand;
use Drupal\Console\Core\Utils\ConfigurationManager;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Console\Core\Utils\ChainQueue;
-class ModeCommand extends Command
+class ModeCommand extends ContainerAwareCommand
{
- use ContainerAwareCommandTrait;
-
/**
* @var ConfigFactory
*/
'environment',
InputArgument::REQUIRED,
$this->trans('commands.site.mode.arguments.environment')
- );
+ )
+ ->setAliases(['smo']);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
$environment = $input->getArgument('environment');
if (!in_array($environment, ['dev', 'prod'])) {
- $io->error($this->trans('commands.site.mode.messages.invalid-env'));
+ $this->getIo()->error($this->trans('commands.site.mode.messages.invalid-env'));
return 1;
}
);
foreach ($configurationOverrideResult as $configName => $result) {
- $io->info(
+ $this->getIo()->info(
$this->trans('commands.site.mode.messages.configuration') . ':',
false
);
- $io->comment($configName);
+ $this->getIo()->comment($configName);
$tableHeader = [
$this->trans('commands.site.mode.messages.configuration-key'),
$this->trans('commands.site.mode.messages.updated'),
];
- $io->table($tableHeader, $result);
+ $this->getIo()->table($tableHeader, $result);
}
$servicesOverrideResult = $this->processServicesFile(
$environment,
- $loadedConfigurations['services'],
- $io
+ $loadedConfigurations['services']
);
if (!empty($servicesOverrideResult)) {
- $io->info(
+ $this->getIo()->info(
$this->trans('commands.site.mode.messages.new-services-settings')
);
$this->trans('commands.site.mode.messages.service-value'),
];
- $io->table($tableHeaders, $servicesOverrideResult);
+ $this->getIo()->table($tableHeaders, $servicesOverrideResult);
}
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
return $result;
}
- protected function processServicesFile($environment, $servicesSettings, DrupalStyle $io)
+ protected function processServicesFile($environment, $servicesSettings)
{
$directory = sprintf(
'%s/%s',
// Copying default services
$defaultServicesFile = $this->appRoot . '/sites/default/default.services.yml';
if (!copy($defaultServicesFile, $settingsServicesFile)) {
- $io->error(
+ $this->getIo()->error(
sprintf(
'%s: %s/services.yml',
$this->trans('commands.site.mode.messages.error-copying-file'),
}
if (file_put_contents($settingsServicesFile, $yaml->dump($services))) {
- $io->commentBlock(
+ $this->getIo()->commentBlock(
sprintf(
$this->trans('commands.site.mode.messages.services-file-overwritten'),
$settingsServicesFile
)
);
} else {
- $io->error(
+ $this->getIo()->error(
sprintf(
'%s : %s/services.yml',
$this->trans('commands.site.mode.messages.error-writing-file'),
protected function loadConfigurations($env)
{
- $configFile = sprintf(
- '%s/.console/site.mode.yml',
- $this->configurationManager->getHomeDirectory()
- );
-
- if (!file_exists($configFile)) {
- $configFile = sprintf(
- '%s/config/dist/site.mode.yml',
- $this->configurationManager->getApplicationDirectory() . DRUPAL_CONSOLE_CORE
- );
- }
+ $configFile = $this->configurationManager
+ ->getVendorCoreDirectory() . 'site.mode.yml';
$siteModeConfiguration = Yaml::parse(file_get_contents($configFile));
$configKeys = array_keys($siteModeConfiguration);