You are here

function composer_manager_fetch_data in Composer Manager 7.2

Same name and namespace in other branches
  1. 6.2 composer_manager.writer.inc \composer_manager_fetch_data()
  2. 6 composer_manager.writer.inc \composer_manager_fetch_data()
  3. 7 composer_manager.writer.inc \composer_manager_fetch_data()

Fetches the data in each module's composer.json file.

Return value

array

Throws

\RuntimeException

2 calls to composer_manager_fetch_data()
composer_manager_required_packages in ./composer_manager.admin.inc
Returns the packages, versions, and the modules that require them in the composer.json files contained in contributed modules.
composer_manager_write_file in ./composer_manager.module
Writes the consolidated composer.json file for all modules that require third-party packages managed by Composer.

File

./composer_manager.writer.inc, line 15
Functions related to the creation of the consolidated composer.json file.

Code

function composer_manager_fetch_data() {
  $data = array();
  foreach (module_list() as $module) {
    $module_dir = drupal_get_path('module', $module);
    $composer_file = $module_dir . '/composer.json';
    $args = array(
      '@file' => $composer_file,
    );
    if (!file_exists($composer_file)) {
      continue;
    }
    if (!($filedata = @file_get_contents($composer_file))) {
      throw new \RuntimeException(t('Error reading file: @file', $args));
    }
    if (!($json = @drupal_json_decode($filedata))) {
      throw new \UnexpectedValueException(t('Expecting contents of file to be valid JSON: @file', $args));
    }
    $data[$module] = $json;
  }
  return $data;
}