class ProviderRepository

Same name in this branch
  1. 10 core/modules/media/src/OEmbed/ProviderRepository.php \Drupal\media\OEmbed\ProviderRepository
Same name in other branches
  1. 9 core/modules/media/src/OEmbed/ProviderRepository.php \Drupal\media\OEmbed\ProviderRepository
  2. 9 core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php \Drupal\media_test_oembed\ProviderRepository
  3. 8.9.x core/modules/media/src/OEmbed/ProviderRepository.php \Drupal\media\OEmbed\ProviderRepository
  4. 8.9.x core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php \Drupal\media_test_oembed\ProviderRepository
  5. 11.x core/modules/media/src/OEmbed/ProviderRepository.php \Drupal\media\OEmbed\ProviderRepository
  6. 11.x 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

  • class \Drupal\media\OEmbed\ProviderRepository implements \Drupal\media\OEmbed\ProviderRepositoryInterface
    • class \Drupal\media_test_oembed\ProviderRepository extends \Drupal\media\OEmbed\ProviderRepository

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

Title Sort descending Modifiers Object type Summary Overriden Title
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 Overrides ProviderRepository::get
ProviderRepository::getAll public function Overrides ProviderRepository::getAll
ProviderRepository::setProvider public function Stores an oEmbed provider value object in state.
ProviderRepository::__construct public function Constructs a ProviderRepository instance.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.