You are here

function composer_manager_read_composer_file in Composer Manager 7

Same name and namespace in other branches
  1. 6.2 composer_manager.admin.inc \composer_manager_read_composer_file()
  2. 6 composer_manager.admin.inc \composer_manager_read_composer_file()
  3. 7.2 composer_manager.admin.inc \composer_manager_read_composer_file()

Parses a JSON file into a PHP array.

Parameters

string $file_uri: The URI of the JSON sile being parsed.

Return value

array The parsed JSON, and empty array if the file doesn't exist.

Throws

\RuntimeException

2 calls to composer_manager_read_composer_file()
composer_manager_installed_packages_load in ./composer_manager.admin.inc
Loads the composer.lock file if it exists.
composer_manager_lockfile_load in ./composer_manager.admin.inc
Loads the composer.lock file if it exists.

File

./composer_manager.admin.inc, line 256
Administrative settings for the Composer Manager module.

Code

function composer_manager_read_composer_file($file_uri) {
  $json = array();
  if (file_exists($file_uri)) {
    if (!($filedata = @file_get_contents($file_uri))) {
      throw new \RuntimeException(t('Error reading file: @file', array(
        '@file' => $file_uri,
      )));
    }
    $json = @drupal_json_decode($filedata);
    if ($json === NULL) {
      throw new \RuntimeException(t('Error parsing file: @file', array(
        '@file' => $file_uri,
      )));
    }
    elseif ($json === FALSE) {
      $json = array();
    }
  }
  return $json;
}