Exemplo n.º 1
0
 private function decodeFile($path)
 {
     $decoder = new JsonDecoder();
     // 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 = $decoder->decodeFile(Path::canonicalize(__DIR__ . '/../../res/schema/package-schema-1.0.json'));
     $configSchema = $schema->properties->config;
     if (!file_exists($path)) {
         throw FileNotFoundException::forPath($path);
     }
     try {
         return $decoder->decodeFile($path, $configSchema);
     } catch (ValidationFailedException $e) {
         throw new InvalidConfigException(sprintf("The configuration in %s is invalid:\n%s", $path, $e->getErrorsAsString()), 0, $e);
     } catch (DecodingFailedException $e) {
         throw new InvalidConfigException(sprintf("The configuration in %s could not be decoded:\n%s", $path, $e->getMessage()), $e->getCode(), $e);
     }
 }
Exemplo n.º 2
0
 /**
  * Loads the module file for the module at the given install path.
  *
  * @param string $installPath The absolute install path of the module
  *
  * @return ModuleFile|null The loaded module file or `null` if none
  *                         could be found.
  */
 private function loadModuleFile($installPath)
 {
     if (!file_exists($installPath)) {
         throw FileNotFoundException::forPath($installPath);
     }
     if (!is_dir($installPath)) {
         throw new NoDirectoryException(sprintf('The path %s is a file. Expected a directory.', $installPath));
     }
     try {
         return $this->moduleFileStorage->loadModuleFile($installPath . '/puli.json');
     } catch (FileNotFoundException $e) {
         // Modules without module files are ok
         return null;
     }
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * Loads the package file for the package at the given install path.
  *
  * @param string $installPath The absolute install path of the package
  *
  * @return PackageFile The loaded package file.
  */
 private function loadPackageFile($installPath)
 {
     if (!file_exists($installPath)) {
         throw FileNotFoundException::forPath($installPath);
     }
     if (!is_dir($installPath)) {
         throw new NoDirectoryException(sprintf('The path %s is a file. Expected a directory.', $installPath));
     }
     return $this->packageFileStorage->loadPackageFile($installPath . '/puli.json');
 }