示例#1
0
 /**
  * Creates JSON file from schema
  *
  * @param string $schemaPath Schema path
  * @param array  $arguments  Array of arguments
  *
  * @return boolean
  */
 public function createJsonFileFromSchema($schemaPath, $arguments)
 {
     $jsonManager = new JsonManager();
     $fs = new Filesystem();
     $schema = file_get_contents($schemaPath);
     $validationResult = $jsonManager->validateJson($schema);
     if (true !== $validationResult) {
         throw new \Exception('JSON schema is not valid', 1);
     }
     $decodedSchema = json_decode($schema, true);
     $fileMapping = $this->getFileContent($arguments['version'] . '.txt', $arguments['target']);
     if (!empty($arguments['exclude'])) {
         $fileMapping = $this->exclude($fileMapping, $arguments['exclude']);
     }
     $decodedSchema['changelog'] = $this->getFileContent($arguments['version'] . '_commits.txt', $arguments['target']);
     $decodedSchema['filemapping'] = $fileMapping;
     foreach ($decodedSchema as $key => $value) {
         if (array_key_exists($key, $arguments)) {
             $decodedSchema[$key] = $arguments[$key];
         }
     }
     $filePath = realpath($arguments['target']) . '/' . self::DIFFFILENAME;
     file_put_contents($filePath, json_encode($decodedSchema, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0), LOCK_EX);
     $zipPath = realpath($arguments['target'] . $arguments['version'] . '.zip');
     if ($jsonManager->addJsonToFile($filePath, $zipPath)) {
         $fs->remove(array($filePath));
         return true;
     }
     return false;
 }
示例#2
0
 /**
  * @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;
 }
示例#3
0
 /**
  * Creates JSON file from schema.
  *
  * @param string $schemaPath Schema path
  * @param array  $arguments  Array of arguments
  *
  * @return bool
  */
 public function createJsonFileFromSchema($schemaPath, $arguments)
 {
     $zipPath = realpath($arguments['target'] . $arguments['version'] . '.zip');
     $jsonManager = new JsonManager($zipPath);
     $fileSystem = new Filesystem();
     $schema = file_get_contents($schemaPath);
     $validationResult = $jsonManager->validateJson($schema);
     if (true !== $validationResult) {
         throw new \Exception('JSON schema is not valid', 1);
     }
     $jsonContent = $this->createJsonContentFrom($schema, $arguments);
     $filePath = realpath($arguments['target']) . '/' . self::DIFF_FILENAME;
     file_put_contents($filePath, json_encode($jsonContent, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0), LOCK_EX);
     if ($jsonManager->addJsonToFile($filePath, $zipPath)) {
         $fileSystem->remove(array($filePath));
         return true;
     }
     return false;
 }