Exemple #1
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;
 }
Exemple #2
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;
 }