Esempio n. 1
0
 private function decodeFile($path)
 {
     $decoder = new JsonDecoder();
     $validator = new JsonValidator();
     // We can't use realpath(), which doesn't work inside PHARs.
     // However, we want to display nice paths if the file is not found.
     $schema = Path::canonicalize(__DIR__ . '/../../res/schema/package-schema-1.0.json');
     if (!file_exists($path)) {
         throw FileNotFoundException::forPath($path);
     }
     try {
         $jsonData = $decoder->decodeFile($path);
     } catch (DecodingFailedException $e) {
         throw new InvalidConfigException(sprintf("The configuration in %s could not be decoded:\n%s", $path, $e->getMessage()), $e->getCode(), $e);
     }
     if (version_compare($jsonData->version, '1.0', '<')) {
         throw UnsupportedVersionException::versionTooLow($jsonData->version, '1.0', $path);
     }
     if (version_compare($jsonData->version, '1.0', '>')) {
         throw UnsupportedVersionException::versionTooHigh($jsonData->version, '1.0', $path);
     }
     $errors = $validator->validate($jsonData, $schema);
     if (count($errors) > 0) {
         throw new InvalidConfigException(sprintf("The configuration in %s is invalid:\n%s", $path, implode("\n", $errors)));
     }
     return $jsonData;
 }
Esempio n. 2
0
 private function assertVersionSupported($version, $path = null)
 {
     if (!in_array($version, $this->knownVersions, true)) {
         throw UnsupportedVersionException::forVersion($version, $this->knownVersions, $path);
     }
 }