5 * Contains \Drupal\Console\Command\State\DebugCommand.
8 namespace Drupal\Console\Command\State;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
15 use Drupal\Core\State\StateInterface;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Core\Style\DrupalStyle;
18 use Drupal\Component\Serialization\Yaml;
23 * @package Drupal\Console\Command\State
25 class DebugCommand extends Command
35 * @var KeyValueFactoryInterface
40 * DebugCommand constructor.
42 * @param StateInterface $state
43 * @param KeyValueFactoryInterface $keyValue
45 public function __construct(
46 StateInterface $state,
47 KeyValueFactoryInterface $keyValue
49 $this->state = $state;
50 $this->keyValue = $keyValue;
51 parent::__construct();
57 protected function configure()
60 ->setName('state:debug')
61 ->setDescription($this->trans('commands.state.debug.description'))
62 ->setHelp($this->trans('commands.state.debug.help'))
65 InputArgument::OPTIONAL,
66 $this->trans('commands.state.debug.arguments.key')
73 protected function execute(InputInterface $input, OutputInterface $output)
75 $io = new DrupalStyle($input, $output);
76 $key = $input->getArgument('key');
80 $io->writeln(Yaml::encode($this->state->get($key)));
85 $tableHeader = [$this->trans('commands.state.debug.messages.key')];
86 $keyStoreStates = array_keys($this->keyValue->get('state')->getAll());
87 $io->table($tableHeader, $keyStoreStates);