Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Develop / GenerateDocDataCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Develop\GenerateDocDataCommand.
6  */
7
8 namespace Drupal\Console\Command\Develop;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Style\DrupalStyle;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16
17 class GenerateDocDataCommand extends Command
18 {
19     use CommandTrait;
20
21
22     /**
23      * {@inheritdoc}
24      */
25     protected function configure()
26     {
27         $this
28             ->setName('generate:doc:data')
29             ->setDescription(
30                 $this->trans('commands.generate.doc.data.description')
31             )
32             ->addOption(
33                 'file',
34                 null,
35                 InputOption::VALUE_OPTIONAL,
36                 $this->trans('commands.generate.doc.data.options.file')
37             );
38         ;
39     }
40
41     /**
42      * {@inheritdoc}
43      */
44     protected function execute(InputInterface $input, OutputInterface $output)
45     {
46         $io = new DrupalStyle($input, $output);
47         $file = null;
48         if ($input->hasOption('file')) {
49             $file = $input->getOption('file');
50         }
51
52         $data = $this->getApplication()->getData();
53         if ($file) {
54             file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT));
55
56             return 0;
57         }
58
59         $io->write(json_encode($data, JSON_PRETTY_PRINT));
60     }
61 }