You are here

function raven_requirements in Raven: Sentry Integration 3.x

Same name and namespace in other branches
  1. 8.2 raven.install \raven_requirements()
  2. 8 raven.install \raven_requirements()
  3. 7.4 raven.install \raven_requirements()
  4. 7 raven.install \raven_requirements()
  5. 7.2 raven.install \raven_requirements()
  6. 7.3 raven.install \raven_requirements()

Implements hook_requirements().

File

./raven.install, line 14
Requirements for Raven module.

Code

function raven_requirements($phase) {
  $requirements['raven_library']['title'] = t('Sentry PHP SDK');
  if (class_exists(SentrySdk::class) && method_exists(Event::class, 'createEvent')) {
    $event = Event::createEvent();
    $requirements['raven_library']['value'] = $event
      ->getSdkVersion();
    if ($phase == 'runtime' && ($client = SentrySdk::getCurrentHub()
      ->getClient())) {
      if ($client
        ->getOptions()
        ->getEnvironment()) {
        $requirements['raven_environment'] = [
          'title' => t('Sentry environment'),
          'value' => $client
            ->getOptions()
            ->getEnvironment(),
        ];
      }
      if ($client
        ->getOptions()
        ->getRelease()) {
        $requirements['raven_release'] = [
          'title' => t('Sentry release'),
          'value' => $client
            ->getOptions()
            ->getRelease(),
        ];
      }
    }
  }
  else {
    $requirements['raven_library']['description'] = t('Sentry PHP SDK version 3.x is required by Raven module, but is not available. Run <code>composer require drupal/raven</code> to install dependencies automatically (or <code>composer require sentry/sdk:^3</code> to install the missing SDK only).');
    $requirements['raven_library']['severity'] = REQUIREMENT_ERROR;
    $requirements['raven_library']['value'] = t('Not found');
  }
  $requirements['raven_trace']['title'] = t('Sentry reflection tracing');
  if (\Drupal::config('raven.settings')
    ->get('trace')) {
    $requirements['raven_trace']['description'] = t('Sentry reflection tracing is enabled, which may result in sensitive data being logged by Sentry.');
    $requirements['raven_trace']['value'] = t('Enabled');
  }
  else {
    $requirements['raven_trace']['value'] = t('Disabled');
  }
  return $requirements;
}