ResourceFetcher.php in Media Migration 8
File
tests/modules/media_migration_test_oembed/src/ResourceFetcher.php
View source
<?php
namespace Drupal\media_migration_test_oembed;
use Drupal\Component\Utility\Crypt;
use Drupal\media\OEmbed\ResourceException;
use Drupal\media\OEmbed\ResourceFetcher as BaseResourceFetcher;
use Drupal\media\OEmbed\Resource;
class ResourceFetcher extends BaseResourceFetcher {
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;
}
}
Classes
Name |
Description |
ResourceFetcher |
Simple oEmbed resource fetcher replacement for remote media migration tests. |