/** * @param InputInterface $input * @param OutputInterface $output * * @return bool */ public function execute(InputInterface $input, OutputInterface $output) { $filePath = $input->getArgument('file'); if (!file_exists($filePath)) { throw new \Exception($filePath . ' not found.', 1); } if (!is_readable($filePath)) { throw new \Exception($filePath . ' is not readable.', 1); } $jsonManager = new JsonManager($filePath); $schema = file_get_contents(realpath(__DIR__ . FilesManager::SCHEMA_FILE_PATH)); $json = $jsonManager->getJsonFromFile(); if (!is_string($json)) { $output->writeln("<error>Can't read json from file.</error>"); return false; } try { $jsonManager->validateSchema($json, $schema); } catch (JsonException $e) { $output->writeln('<comment>' . $e->getMessage() . '</comment>'); foreach ((array) $e->getErrors() as $error) { $output->writeln('<error>' . $error . '</error>'); } return false; } $output->writeln('<info>* Syntax of a JSON string is valid!</info>'); $output->writeln('<info>* JSON validates against the schema!</info>'); $packageSpec = json_decode($json, true); $output->writeln('<info>Package version:</info> ' . $packageSpec['version']); $output->writeln('<info>Package description:</info> ' . $packageSpec['description']); $output->writeln('<info>Package maintainer:</info> ' . $packageSpec['maintainer']); $output->writeln('<info>Package changelog:</info> ' . implode(', ', $packageSpec['changelog'])); $output->writeln('<info>* All is valid!</info>'); return true; }
/** * @param InputInterface $input * @param OutputInterface $output * * @return boolean */ public function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument('file'); if (!file_exists($file)) { throw new \Exception($file . ' not found.', 1); } if (!is_readable($file)) { throw new \Exception($file . ' is not readable.', 1); } $jsonManager = new JsonManager(); $schema = file_get_contents(realpath(__DIR__ . '/../../../schema/') . '/updater-schema.json'); $json = $jsonManager->getJsonFromFile('update.json', realpath($file)); $validationResult = $jsonManager->validateJson($json); if (true !== $validationResult) { $output->writeln('<error>* JSON inside update package isn\'t valid!</error>'); $output->writeln('<error>' . $validationResult->getMessage() . '<error>'); return true; } else { $output->writeln('<info>* JSON inside update package is valid!</info>'); } $schemaResult = $jsonManager->validateSchema($json, $schema); if (true !== $schemaResult) { $output->writeln('<error>* JSON does not validate!</error>'); } else { $output->writeln('<info>* JSON validates against the schema!</info>'); } $packageSpec = json_decode($json, true); $output->writeln('<info>Package version:</info> ' . $packageSpec['version']); $output->writeln('<info>Package description:</info> ' . $packageSpec['description']); $output->writeln('<info>Package maintainer:</info> ' . $packageSpec['maintainer']); $output->writeln('<info>Package changelog:</info> ' . implode(', ', $packageSpec['changelog'])); $output->writeln('<info>* All valid!</info>'); return true; }