5 * Contains \Drupal\Console\Command\Config\ValidateDebugCommand.
8 namespace Drupal\Console\Command\Config;
10 use Drupal\Core\Config\Schema\SchemaCheckTrait;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
17 use Symfony\Component\Console\Input\InputArgument;
18 use Drupal\Core\Config\TypedConfigManagerInterface;
19 use Drupal\Core\Serialization\Yaml;
22 * Class ValidateDebugCommand.
24 *@package Drupal\Console\Command\Config
26 class ValidateDebugCommand extends Command
28 use ContainerAwareCommandTrait;
30 use PrintConfigValidationTrait;
35 protected function configure()
38 ->setName('config:validate:debug')
39 ->setDescription($this->trans('commands.config.validate.debug.description'))
40 ->addArgument('config.filepath', InputArgument::REQUIRED)
41 ->addArgument('config.schema.filepath', InputArgument::REQUIRED)
42 ->addOption('schema-name', 'sch', InputOption::VALUE_REQUIRED);
48 protected function execute(InputInterface $input, OutputInterface $output)
52 * @var TypedConfigManagerInterface $typedConfigManager
54 $typedConfigManager = $this->get('config.typed');
56 $io = new DrupalStyle($input, $output);
58 //Validate config file path
59 $configFilePath = $input->getArgument('config.filepath');
60 if (!file_exists($configFilePath)) {
61 $io->info($this->trans('commands.config.validate.debug.messages.noConfFile'));
65 //Validate schema path
66 $configSchemaFilePath = $input->getArgument('config.schema.filepath');
67 if (!file_exists($configSchemaFilePath)) {
68 $io->info($this->trans('commands.config.validate.debug.messages.noConfSchema'));
72 $config = Yaml::decode(file_get_contents($configFilePath));
73 $schema = Yaml::decode(file_get_contents($configSchemaFilePath));
75 //Get the schema name and check it exists in the schema array
76 $schemaName = $this->getSchemaName($input, $configFilePath);
77 if (!array_key_exists($schemaName, $schema)) {
78 $io->warning($this->trans('commands.config.validate.debug.messages.noSchemaName') . $schemaName);
82 return $this->printResults($this->manualCheckConfigSchema($typedConfigManager, $config, $schema[$schemaName]), $io);
85 private function getSchemaName(InputInterface $input, $configFilePath)
87 $schemaName = $input->getOption('schema-name');
88 if ($schemaName === null) {
89 $schema_name = end(explode('/', $configFilePath));
90 $schemaName = substr($schema_name, 0, -4);
95 private function manualCheckConfigSchema(TypedConfigManagerInterface $typed_config, $config_data, $config_schema)
97 $data_definition = $typed_config->buildDataDefinition($config_schema, $config_data);
98 $this->schema = $typed_config->create($data_definition, $config_data);
100 foreach ($config_data as $key => $value) {
101 $errors = array_merge($errors, $this->checkValue($key, $value));
103 if (empty($errors)) {