You are here

class ResourceFetcher in Media Migration 8

Simple oEmbed resource fetcher replacement for remote media migration tests.

Hierarchy

Expanded class hierarchy of ResourceFetcher

File

tests/modules/media_migration_test_oembed/src/ResourceFetcher.php, line 13

Namespace

Drupal\media_migration_test_oembed
View source
class ResourceFetcher extends BaseResourceFetcher {

  /**
   * {@inheritdoc}
   */
  public function fetchResource($oembed_url) {
    $hashed = Crypt::hashBase64($oembed_url);
    $resource_array = \Drupal::state()
      ->get("media_migration_test_oembed.{$hashed}", [
      'type' => 'video',
      'html' => urlencode($oembed_url),
      'width' => 320,
      'height' => 180,
    ]);
    $type = $resource_array['type'];
    unset($resource_array['type']);
    try {
      $resource = call_user_func_array([
        Resource::class,
        $type,
      ], $resource_array);
    } catch (\Exception $e) {
      throw new ResourceException(sprintf('Test media oembed resource %s cannot be fetched', $oembed_url), $oembed_url);
    }
    assert($resource instanceof Resource);
    return $resource;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResourceFetcher::$httpClient protected property The HTTP client.
ResourceFetcher::$providers protected property The oEmbed provider repository service.
ResourceFetcher::createResource protected function Creates a Resource object from raw resource data.
ResourceFetcher::fetchResource public function Fetches an oEmbed resource. Overrides ResourceFetcher::fetchResource
ResourceFetcher::parseResourceXml protected function Parses XML resource data.
ResourceFetcher::__construct public function Constructs a ResourceFetcher object.
UseCacheBackendTrait::$cacheBackend protected property Cache backend instance.
UseCacheBackendTrait::$useCaches protected property Flag whether caches should be used or skipped.
UseCacheBackendTrait::cacheGet protected function Fetches from the cache backend, respecting the use caches flag. 1
UseCacheBackendTrait::cacheSet protected function Stores data in the persistent cache, respecting the use caches flag.