5 * Contains \Drupal\Console\Core\Command\Settings\SetCommand.
8 namespace Drupal\Console\Core\Command\Settings;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Yaml\Dumper;
14 use Symfony\Component\Yaml\Parser;
15 use Drupal\Console\Core\Command\Command;
16 use Drupal\Console\Core\Utils\ConfigurationManager;
17 use Drupal\Console\Core\Utils\NestedArray;
22 * @package Drupal\Console\Core\Command\Settings
24 class SetCommand extends Command
27 * @var ConfigurationManager
29 protected $configurationManager;
34 protected $nestedArray;
37 * CheckCommand constructor.
39 * @param ConfigurationManager $configurationManager
40 * @param NestedArray $nestedArray
42 public function __construct(
43 ConfigurationManager $configurationManager,
44 NestedArray $nestedArray
46 $this->configurationManager = $configurationManager;
47 $this->nestedArray = $nestedArray;
49 parent::__construct();
55 protected function configure()
58 ->setName('settings:set')
61 InputArgument::REQUIRED,
62 $this->trans('commands.settings.set.arguments.name'),
67 InputArgument::REQUIRED,
68 $this->trans('commands.settings.set.arguments.value'),
71 ->setDescription($this->trans('commands.settings.set.description'));
77 protected function execute(InputInterface $input, OutputInterface $output)
79 $parser = new Parser();
80 $dumper = new Dumper();
82 $settingName = $input->getArgument('name');
83 $settingValue = $input->getArgument('value');
85 $userConfigFile = sprintf(
86 '%s/.console/config.yml',
87 $this->configurationManager->getHomeDirectory()
90 if (!file_exists($userConfigFile)) {
91 $this->getIo()->error(
93 $this->trans('commands.settings.set.messages.missing-file'),
101 $userConfigFileParsed = $parser->parse(
102 file_get_contents($userConfigFile)
104 } catch (\Exception $e) {
105 $this->getIo()->error(
107 'commands.settings.set.messages.error-parsing'
108 ) . ': ' . $e->getMessage()
113 $parents = array_merge(['application'], explode(".", $settingName));
115 $this->nestedArray->setValue(
116 $userConfigFileParsed,
123 $userConfigFileDump = $dumper->dump($userConfigFileParsed, 10);
124 } catch (\Exception $e) {
125 $this->getIo()->error(
127 $this->trans('commands.settings.set.messages.error-generating'),
135 if ($settingName == 'language') {
136 $this->getApplication()
138 ->changeCoreLanguage($settingValue);
140 $translatorLanguage = $this->getApplication()->getTranslator()->getLanguage();
141 if ($translatorLanguage != $settingValue) {
142 $this->getIo()->error(
144 $this->trans('commands.settings.set.messages.missing-language'),
154 file_put_contents($userConfigFile, $userConfigFileDump);
155 } catch (\Exception $e) {
156 $this->getIo()->error(
158 $this->trans('commands.settings.set.messages.error-writing'),
166 $this->getIo()->success(
168 $this->trans('commands.settings.set.messages.success'),