You are here

class ProviderRepository in Drupal 10

Same name in this branch
  1. 10 core/modules/media/src/OEmbed/ProviderRepository.php \Drupal\media\OEmbed\ProviderRepository
  2. 10 core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php \Drupal\media_test_oembed\ProviderRepository
Same name and namespace in other branches
  1. 8 core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php \Drupal\media_test_oembed\ProviderRepository
  2. 9 core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php \Drupal\media_test_oembed\ProviderRepository

Overrides the oEmbed provider repository service for testing purposes.

This service does not use caching at all, and will always try to retrieve provider data from state before calling the parent methods.

Hierarchy

Expanded class hierarchy of ProviderRepository

File

core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php, line 14

Namespace

Drupal\media_test_oembed
View source
class ProviderRepository extends BaseProviderRepository {

  /**
   * {@inheritdoc}
   */
  public function getAll() {
    return \Drupal::state()
      ->get(static::class) ?: parent::getAll();
  }

  /**
   * {@inheritdoc}
   */
  public function get($provider_name) {
    $providers = \Drupal::state()
      ->get(static::class, []);
    if (isset($providers[$provider_name])) {
      return $providers[$provider_name];
    }
    return parent::get($provider_name);
  }

  /**
   * Stores an oEmbed provider value object in state.
   *
   * @param \Drupal\media\OEmbed\Provider $provider
   *   The provider to store.
   */
  public function setProvider(Provider $provider) {
    $providers = \Drupal::state()
      ->get(static::class, []);
    $name = $provider
      ->getName();
    $providers[$name] = $provider;
    \Drupal::state()
      ->set(static::class, $providers);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ProviderRepository::$httpClient protected property The HTTP client.
ProviderRepository::$keyValue protected property The key-value store.
ProviderRepository::$logger protected property The logger channel.
ProviderRepository::$maxAge protected property How long the provider data should be cached, in seconds.
ProviderRepository::$providersUrl protected property URL of a JSON document which contains a database of oEmbed providers.
ProviderRepository::$time protected property The time service.
ProviderRepository::get public function Returns information for a specific oEmbed provider. Overrides ProviderRepository::get
ProviderRepository::getAll public function Returns information on all available oEmbed providers. Overrides ProviderRepository::getAll
ProviderRepository::setProvider public function Stores an oEmbed provider value object in state.
ProviderRepository::__construct public function Constructs a ProviderRepository instance.