You are here

function composer_manager_requirements in Composer Manager 7.2

Same name and namespace in other branches
  1. 8 composer_manager.install \composer_manager_requirements()
  2. 6.2 composer_manager.install \composer_manager_requirements()
  3. 6 composer_manager.install \composer_manager_requirements()
  4. 7 composer_manager.install \composer_manager_requirements()

Implements hook_requirements().

File

./composer_manager.install, line 29
Install, update, and uninstall functions for the Composer Manager module.

Code

function composer_manager_requirements($phase) {
  if ('runtime' != $phase) {
    return array();
  }
  $t = get_t();
  if (variable_get('composer_manager_autobuild_file', 1)) {
    $file_dir = composer_manager_file_dir();
  }
  else {
    $scheme = file_default_scheme();
    if (!in_array($scheme, array(
      'public',
      'private',
    ))) {
      $scheme = 'public';
    }
    $file_dir = variable_get('composer_manager_file_dir', $scheme . '://composer');
  }
  $vendor_dir = composer_manager_vendor_dir();
  $requirements = array(
    'composer_manager' => array(
      'title' => $t('Composer Manager'),
    ),
  );

  // Change the message slightly if we are on the package status page.
  if ('admin/config/system/composer-manager' == current_path()) {
    $instructions = $t('Run <code>drush composer-json-rebuild</code> on the command line or submit the <em>Rebuild composer.json file</em> button on this page to build the file.');
  }
  else {
    $instructions = $t('Run <code>drush composer-json-rebuild</code> on the command line or submit the <em>Rebuild composer.json file</em> button on the <a href="@url">package status page</a> to build the file.', array(
      '@url' => url('admin/config/system/composer-manager'),
    ));
  }
  if (!file_exists($file_dir . '/composer.json')) {
    $requirements['composer_manager']['value'] = $t('Missing composer.json file');
    $requirements['composer_manager']['description'] = $t('The composer.json file was not found.') . '<br/>' . $instructions;
    $requirements['composer_manager']['severity'] = REQUIREMENT_ERROR;
  }
  elseif (!json_decode(@file_get_contents($file_dir . '/composer.json'))) {
    $requirements['composer_manager']['value'] = $t('Invalid composer.json file');
    $requirements['composer_manager']['description'] = $t('The composer.json file is invalid.') . '<br/>' . $instructions;
    $requirements['composer_manager']['severity'] = REQUIREMENT_ERROR;
  }
  elseif (!file_exists($vendor_dir . '/autoload.php')) {
    $requirements['composer_manager']['value'] = $t('Dependencies not installed');
    $args = array(
      '!command' => 'install',
      '@url' => url('http://drupal.org/project/composer_manager', array(
        'absolute' => TRUE,
      )),
    );
    $requirements['composer_manager']['description'] = $t('Composer\'s <code>!command</code> command must be run to generate the autoloader and install the required packages.<br/>Refer to the instructions on the <a href="@url" target="_blank">Composer Manager project page</a> for installing packages.', $args);
    $requirements['composer_manager']['severity'] = REQUIREMENT_ERROR;
  }
  elseif ($packages = composer_manager_packages_to_install()) {
    $requirements['composer_manager']['value'] = $t('Dependencies not installed');
    $args = array(
      '@packages' => join(', ', $packages),
      '@url' => url('http://drupal.org/project/composer_manager', array(
        'absolute' => TRUE,
      )),
    );
    $requirements['composer_manager']['description'] = $t('The following packages must be installed: @packages<br/>Refer to the instructions on the <a href="@url" target="_blank">Composer Manager project page</a> for updating packages.', $args);
    $requirements['composer_manager']['severity'] = REQUIREMENT_ERROR;
  }
  else {
    $requirements['composer_manager']['value'] = $t('Dependencies installed');
    $requirements['composer_manager']['description'] = $t('Visit the <a href="@url">package status page</a> to view the status of individual packages.', array(
      '@url' => url('admin/config/system/composer-manager'),
    ));
    $requirements['composer_manager']['severity'] = REQUIREMENT_OK;
  }
  return $requirements;
}