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