Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Config / ValidateCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Config\ValidateCommand.
6  */
7
8 namespace Drupal\Console\Command\Config;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Drupal\Console\Core\Command\ContainerAwareCommand;
13 use Drupal\Core\Config\TypedConfigManagerInterface;
14 use Symfony\Component\Console\Input\InputArgument;
15 use Drupal\Core\Config\Schema\SchemaCheckTrait;
16
17 /**
18  * Class ValidateCommand.
19  *
20  * @package Drupal\Console\Command\Config
21  */
22 class ValidateCommand extends ContainerAwareCommand
23 {
24     use SchemaCheckTrait;
25     use PrintConfigValidationTrait;
26
27     /**
28    * {@inheritdoc}
29    */
30     protected function configure()
31     {
32         $this
33             ->setName('config:validate')
34             ->setDescription($this->trans('commands.config.validate.description'))
35             ->addArgument(
36                 'name',
37                 InputArgument::REQUIRED
38             )->setAliases(['cv']);
39     }
40
41     /**
42    * {@inheritdoc}
43    */
44     protected function execute(InputInterface $input, OutputInterface $output)
45     {
46         /**
47          * @var TypedConfigManagerInterface $typedConfigManager
48          */
49         $typedConfigManager = $this->get('config.typed');
50
51         //Test the config name and see if a schema exists, if not it will fail
52         $name = $input->getArgument('name');
53         if (!$typedConfigManager->hasConfigSchema($name)) {
54             $this->getIo()->warning($this->trans('commands.config.validate.messages.no-conf'));
55             return 1;
56         }
57
58         //Get the config data from the factory
59         $configFactory = $this->get('config.factory');
60         $config_data = $configFactory->get($name)->get();
61
62         return $this->printResults($this->checkConfigSchema($typedConfigManager, $name, $config_data));
63     }
64 }