Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console-core / src / Command / CheckCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Core\Command\CheckCommand.
6  */
7
8 namespace Drupal\Console\Core\Command;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command as BaseCommand;
13 use Drupal\Console\Core\Command\Shared\CommandTrait;
14 use Drupal\Console\Core\Utils\ConfigurationManager;
15 use Drupal\Console\Core\Utils\RequirementChecker;
16 use Drupal\Console\Core\Utils\ChainQueue;
17 use Drupal\Console\Core\Style\DrupalStyle;
18
19 /**
20  * Class CheckCommand
21  *
22  * @package Drupal\Console\Core\Command
23  */
24 class CheckCommand extends BaseCommand
25 {
26     use CommandTrait;
27
28     /**
29      * @var RequirementChecker
30      */
31     protected $requirementChecker;
32
33     /**
34      * @var ChainQueue
35      */
36     protected $chainQueue;
37
38     /**
39      * @var ConfigurationManager
40      */
41     protected $configurationManager;
42
43     /**
44      * CheckCommand constructor.
45      *
46      * @param RequirementChecker   $requirementChecker
47      * @param ChainQueue           $chainQueue
48      * @param ConfigurationManager $configurationManager
49      */
50     public function __construct(
51         RequirementChecker $requirementChecker,
52         ChainQueue $chainQueue,
53         ConfigurationManager $configurationManager
54     ) {
55         $this->requirementChecker = $requirementChecker;
56         $this->chainQueue = $chainQueue;
57         $this->configurationManager = $configurationManager;
58
59         parent::__construct();
60     }
61
62     /**
63      * {@inheritdoc}
64      */
65     protected function configure()
66     {
67         $this
68             ->setName('check')
69             ->setDescription($this->trans('commands.check.description'));
70     }
71
72     /**
73      * {@inheritdoc}
74      */
75     protected function execute(InputInterface $input, OutputInterface $output)
76     {
77         $io = new DrupalStyle($input, $output);
78
79         $checks = $this->requirementChecker->getCheckResult();
80         if (!$checks) {
81             $phpCheckFile = $this->configurationManager->getHomeDirectory().'/.console/phpcheck.yml';
82
83             if (!file_exists($phpCheckFile)) {
84                 $phpCheckFile =
85                     $this->configurationManager->getApplicationDirectory().
86                     DRUPAL_CONSOLE_CORE.
87                     'config/dist/phpcheck.yml';
88             }
89
90             $io->newLine();
91             $io->info($this->trans('commands.check.messages.file'));
92             $io->comment($phpCheckFile);
93
94             $checks = $this->requirementChecker->validate($phpCheckFile);
95         }
96
97         if (!$checks['php']['valid']) {
98             $io->error(
99                 sprintf(
100                     $this->trans('commands.check.messages.php_invalid'),
101                     $checks['php']['current'],
102                     $checks['php']['required']
103                 )
104             );
105
106             return 1;
107         }
108
109         if ($extensions = $checks['extensions']['required']['missing']) {
110             foreach ($extensions as $extension) {
111                 $io->error(
112                     sprintf(
113                         $this->trans('commands.check.messages.extension_missing'),
114                         $extension
115                     )
116                 );
117             }
118         }
119
120         if ($extensions = $checks['extensions']['recommended']['missing']) {
121             foreach ($extensions as $extension) {
122                 $io->commentBlock(
123                     sprintf(
124                         $this->trans(
125                             'commands.check.messages.extension_recommended'
126                         ),
127                         $extension
128                     )
129                 );
130             }
131         }
132
133         if ($configurations = $checks['configurations']['required']['missing']) {
134             foreach ($configurations as $configuration) {
135                 $io->error(
136                     sprintf(
137                         $this->trans('commands.check.messages.configuration_missing'),
138                         $configuration
139                     )
140                 );
141             }
142         }
143
144         if ($configurations = $checks['configurations']['required']['overwritten']) {
145             foreach ($configurations as $configuration => $overwritten) {
146                 $io->commentBlock(
147                     sprintf(
148                         $this->trans(
149                             'commands.check.messages.configuration_overwritten'
150                         ),
151                         $configuration,
152                         $overwritten
153                     )
154                 );
155             }
156         }
157
158         if ($this->requirementChecker->isValid() && !$this->requirementChecker->isOverwritten()) {
159             $io->success(
160                 $this->trans('commands.check.messages.success')
161             );
162         }
163
164         return $this->requirementChecker->isValid();
165     }
166 }