1eb0f90b3d9d530a14910544c0edcb7c787a68a5
[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 Drupal\Console\Core\Utils\ConfigurationManager;
13 use Drupal\Console\Core\Utils\RequirementChecker;
14 use Drupal\Console\Core\Utils\ChainQueue;
15
16 /**
17  * Class CheckCommand
18  *
19  * @package Drupal\Console\Core\Command
20  */
21 class CheckCommand extends Command
22 {
23     /**
24      * @var RequirementChecker
25      */
26     protected $requirementChecker;
27
28     /**
29      * @var ChainQueue
30      */
31     protected $chainQueue;
32
33     /**
34      * @var ConfigurationManager
35      */
36     protected $configurationManager;
37
38     /**
39      * CheckCommand constructor.
40      *
41      * @param RequirementChecker   $requirementChecker
42      * @param ChainQueue           $chainQueue
43      * @param ConfigurationManager $configurationManager
44      */
45     public function __construct(
46         RequirementChecker $requirementChecker,
47         ChainQueue $chainQueue,
48         ConfigurationManager $configurationManager
49     ) {
50         $this->requirementChecker = $requirementChecker;
51         $this->chainQueue = $chainQueue;
52         $this->configurationManager = $configurationManager;
53
54         parent::__construct();
55     }
56
57     /**
58      * {@inheritdoc}
59      */
60     protected function configure()
61     {
62         $this
63             ->setName('check')
64             ->setDescription($this->trans('commands.check.description'));
65     }
66
67     /**
68      * {@inheritdoc}
69      */
70     protected function execute(InputInterface $input, OutputInterface $output)
71     {
72         $checks = $this->requirementChecker->getCheckResult();
73         if (!$checks) {
74             $phpCheckFile = $this->configurationManager
75                 ->getVendorCoreDirectory() . 'phpcheck.yml';
76
77             $checks = $this->requirementChecker->validate($phpCheckFile);
78         }
79
80         if (!$checks['php']['valid']) {
81             $this->getIo()->error(
82                 sprintf(
83                     $this->trans('commands.check.messages.php-invalid'),
84                     $checks['php']['current'],
85                     $checks['php']['required']
86                 )
87             );
88
89             return 1;
90         }
91
92         if ($extensions = $checks['extensions']['required']['missing']) {
93             foreach ($extensions as $extension) {
94                 $this->getIo()->error(
95                     sprintf(
96                         $this->trans('commands.check.messages.extension-missing'),
97                         $extension
98                     )
99                 );
100             }
101         }
102
103         if ($extensions = $checks['extensions']['recommended']['missing']) {
104             foreach ($extensions as $extension) {
105                 $this->getIo()->commentBlock(
106                     sprintf(
107                         $this->trans(
108                             'commands.check.messages.extension-recommended'
109                         ),
110                         $extension
111                     )
112                 );
113             }
114         }
115
116         if ($configurations = $checks['configurations']['required']['missing']) {
117             foreach ($configurations as $configuration) {
118                 $this->getIo()->error(
119                     sprintf(
120                         $this->trans('commands.check.messages.configuration-missing'),
121                         $configuration
122                     )
123                 );
124             }
125         }
126
127         if ($configurations = $checks['configurations']['required']['overwritten']) {
128             foreach ($configurations as $configuration => $overwritten) {
129                 $this->getIo()->commentBlock(
130                     sprintf(
131                         $this->trans(
132                             'commands.check.messages.configuration-overwritten'
133                         ),
134                         $configuration,
135                         $overwritten
136                     )
137                 );
138             }
139         }
140
141         if ($this->requirementChecker->isValid() && !$this->requirementChecker->isOverwritten()) {
142             $this->getIo()->success(
143                 $this->trans('commands.check.messages.success')
144             );
145         }
146
147         return $this->requirementChecker->isValid();
148     }
149 }