You are here

public static function JsonFile::read in Composer Manager 8

Reads and decodes a json file into an array.

Return value

array The decoded json data.

Throws

\RuntimeException

\UnexpectedValueException

7 calls to JsonFile::read()
composer_manager_drush_pm_post_download in ./composer_manager.drush.inc
Implements hook_drush_pm_post_download().
composer_manager_initialize in ./composer_manager.module
Initializes Composer Manager.
composer_manager_initialized in ./composer_manager.module
Returns whether Composer Manager has been initialized.
PackageManager::getCorePackage in src/PackageManager.php
Returns the core package.
PackageManager::getExtensionPackages in src/PackageManager.php
Returns the extension packages.

... See full list

File

src/JsonFile.php, line 19

Class

JsonFile
Reads and writes json files.

Namespace

Drupal\composer_manager

Code

public static function read($filename) {
  if (!is_readable($filename)) {
    throw new \RuntimeException(sprintf('%s is not readable.', $filename));
  }
  $json = file_get_contents($filename);
  if ($json === FALSE) {
    throw new \RuntimeException(sprintf('Could not read %s', $filename));
  }
  $data = json_decode($json, TRUE);
  if (JSON_ERROR_NONE !== json_last_error()) {
    throw new \UnexpectedValueException(sprintf('Could not decode JSON file "%s". Error message: %s', $filename, json_last_error_msg()));
  }
  return $data;
}