Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drupal / console / src / Command / Debug / StateCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Debug\DebugCommand.
6  */
7
8 namespace Drupal\Console\Command\Debug;
9
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Core\Command\Command;
14 use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
15 use Drupal\Core\State\StateInterface;
16 use Drupal\Component\Serialization\Yaml;
17
18 /**
19  * Class DebugCommand
20  *
21  * @package Drupal\Console\Command\Debug
22  */
23 class StateCommand extends Command
24 {
25     /**
26      * @var StateInterface
27      */
28     protected $state;
29
30     /**
31      * @var KeyValueFactoryInterface
32      */
33     protected $keyValue;
34
35     /**
36      * DebugCommand constructor.
37      *
38      * @param StateInterface           $state
39      * @param KeyValueFactoryInterface $keyValue
40      */
41     public function __construct(
42         StateInterface $state,
43         KeyValueFactoryInterface $keyValue
44     ) {
45         $this->state = $state;
46         $this->keyValue = $keyValue;
47         parent::__construct();
48     }
49
50     /**
51      * {@inheritdoc}
52      */
53     protected function configure()
54     {
55         $this
56             ->setName('debug:state')
57             ->setDescription($this->trans('commands.debug.state.description'))
58             ->addArgument(
59                 'key',
60                 InputArgument::OPTIONAL,
61                 $this->trans('commands.debug.state.arguments.key')
62             )
63             ->setHelp($this->trans('commands.debug.state.help'))
64             ->setAliases(['dst']);
65     }
66
67     /**
68      * {@inheritdoc}
69      */
70     protected function execute(InputInterface $input, OutputInterface $output)
71     {
72         $key = $input->getArgument('key');
73
74         if ($key) {
75             $this->getIo()->info($key);
76             $this->getIo()->writeln(Yaml::encode($this->state->get($key)));
77
78             return 0;
79         }
80
81         $tableHeader = [$this->trans('commands.debug.state.messages.key')];
82         $keyStoreStates = array_keys($this->keyValue->get('state')->getAll());
83         $this->getIo()->table($tableHeader, $keyStoreStates);
84
85         return 0;
86     }
87 }