X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FValidateDebugCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FValidateDebugCommand.php;h=8ee48d0f88404270191ed367af265af660f6cb19;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Config/ValidateDebugCommand.php b/vendor/drupal/console/src/Command/Config/ValidateDebugCommand.php new file mode 100644 index 000000000..8ee48d0f8 --- /dev/null +++ b/vendor/drupal/console/src/Command/Config/ValidateDebugCommand.php @@ -0,0 +1,109 @@ +setName('config:validate:debug') + ->setDescription($this->trans('commands.config.validate.debug.description')) + ->addArgument('config.filepath', InputArgument::REQUIRED) + ->addArgument('config.schema.filepath', InputArgument::REQUIRED) + ->addOption('schema-name', 'sch', InputOption::VALUE_REQUIRED); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + + /** + * @var TypedConfigManagerInterface $typedConfigManager + */ + $typedConfigManager = $this->get('config.typed'); + + $io = new DrupalStyle($input, $output); + + //Validate config file path + $configFilePath = $input->getArgument('config.filepath'); + if (!file_exists($configFilePath)) { + $io->info($this->trans('commands.config.validate.debug.messages.noConfFile')); + return 1; + } + + //Validate schema path + $configSchemaFilePath = $input->getArgument('config.schema.filepath'); + if (!file_exists($configSchemaFilePath)) { + $io->info($this->trans('commands.config.validate.debug.messages.noConfSchema')); + return 1; + } + + $config = Yaml::decode(file_get_contents($configFilePath)); + $schema = Yaml::decode(file_get_contents($configSchemaFilePath)); + + //Get the schema name and check it exists in the schema array + $schemaName = $this->getSchemaName($input, $configFilePath); + if (!array_key_exists($schemaName, $schema)) { + $io->warning($this->trans('commands.config.validate.debug.messages.noSchemaName') . $schemaName); + return 1; + } + + return $this->printResults($this->manualCheckConfigSchema($typedConfigManager, $config, $schema[$schemaName]), $io); + } + + private function getSchemaName(InputInterface $input, $configFilePath) + { + $schemaName = $input->getOption('schema-name'); + if ($schemaName === null) { + $schema_name = end(explode('/', $configFilePath)); + $schemaName = substr($schema_name, 0, -4); + } + return $schemaName; + } + + private function manualCheckConfigSchema(TypedConfigManagerInterface $typed_config, $config_data, $config_schema) + { + $data_definition = $typed_config->buildDataDefinition($config_schema, $config_data); + $this->schema = $typed_config->create($data_definition, $config_data); + $errors = []; + foreach ($config_data as $key => $value) { + $errors = array_merge($errors, $this->checkValue($key, $value)); + } + if (empty($errors)) { + return true; + } + + return $errors; + } +}