You are here

class CdnServiceProvider in CDN 8.3

Hierarchy

Expanded class hierarchy of CdnServiceProvider

See also

\Drupal\cdn\EventSubscriber\ConfigSubscriber::onSave()

File

src/CdnServiceProvider.php, line 16

Namespace

Drupal\cdn
View source
class CdnServiceProvider implements ServiceProviderInterface {

  /**
   * {@inheritdoc}
   */
  public function register(ContainerBuilder $container) {
    if ($this
      ->cdnStatusIsEnabled()) {
      $container
        ->register('http_middleware.cdn.duplicate_content_prevention', DuplicateContentPreventionMiddleware::class)
        ->addArgument(new Reference('request_stack'))
        ->addTag('http_middleware', [
        'priority' => 230,
      ]);
    }

    // @todo Delete this when dropping Drupal 8 support in https://www.drupal.org/project/cdn/issues/3103682.
    if (version_compare(\Drupal::VERSION, '9.0', '<')) {

      // @see https://www.drupal.org/project/drupal/issues/3074585
      $container
        ->getDefinition('cdn.file_url_generator')
        ->setArgument(0, '@app.root');
    }
  }

  /**
   * @return bool
   */
  protected function cdnStatusIsEnabled() : bool {
    $cdn_settings = BootstrapConfigStorageFactory::get()
      ->read('cdn.settings');

    // In Kernel tests it's possible this code is called before cdn.settings
    // exists. In such cases behave as though the CDN status is "disabled". This
    // is also the default value in cdn.settings.yml.
    if ($cdn_settings === FALSE) {
      return FALSE;
    }
    return $cdn_settings['status'] === TRUE;
  }

}

Members