class UrlResolver implements UrlResolverInterface (View source)

Converts oEmbed media URLs into endpoint-specific resource URLs.

Properties

protected Client $httpClient

The HTTP client.

protected ProviderRepositoryInterface $providers

The OEmbed provider repository service.

protected ResourceFetcherInterface $resourceFetcher

The OEmbed resource fetcher service.

protected ModuleHandlerInterface $moduleHandler

The module handler service.

protected string[] $urlCache

Static cache of discovered oEmbed resource URLs, keyed by canonical URL.

protected CacheBackendInterface $cacheBackend

The cache backend.

Methods

__construct(ProviderRepositoryInterface $providers, ResourceFetcherInterface $resource_fetcher, ClientInterface $http_client, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend = NULL)

Constructs a UrlResolver object.

string|bool
discoverResourceUrl(string $url)

Runs oEmbed discovery and returns the endpoint URL if successful.

bool|string
findUrl(DOMXPath $xpath, string $format)

Tries to find the oEmbed URL in a DOM.

getProviderByUrl(string $url)

Tries to determine the oEmbed provider for a media asset URL.

string
getResourceUrl(string $url, int $max_width = NULL, int $max_height = NULL)

Builds the resource URL for a media asset URL.

string
getEndpointMatchingUrl(string $url, Provider $provider)

For the given media item URL find an endpoint with schemes that match.

Details

__construct(ProviderRepositoryInterface $providers, ResourceFetcherInterface $resource_fetcher, ClientInterface $http_client, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend = NULL)

Constructs a UrlResolver object.

Parameters

ProviderRepositoryInterface $providers

The oEmbed provider repository service.

ResourceFetcherInterface $resource_fetcher

The OEmbed resource fetcher service.

ClientInterface $http_client

The HTTP client.

ModuleHandlerInterface $module_handler

The module handler service.

CacheBackendInterface $cache_backend

The cache backend.

protected string|bool discoverResourceUrl(string $url)

Runs oEmbed discovery and returns the endpoint URL if successful.

Parameters

string $url

The resource's URL.

Return Value

string|bool

URL of the oEmbed endpoint, or FALSE if the discovery was unsuccessful.

protected bool|string findUrl(DOMXPath $xpath, string $format)

Tries to find the oEmbed URL in a DOM.

Parameters

DOMXPath $xpath

Page HTML as DOMXPath.

string $format

Format of oEmbed resource. Possible values are 'json' and 'xml'.

Return Value

bool|string

A URL to an oEmbed resource or FALSE if not found.

Provider getProviderByUrl(string $url)

Tries to determine the oEmbed provider for a media asset URL.

Parameters

string $url

The media asset URL.

Return Value

Provider

The oEmbed provider for the asset.

Exceptions

ResourceException
ProviderException

string getResourceUrl(string $url, int $max_width = NULL, int $max_height = NULL)

Builds the resource URL for a media asset URL.

Parameters

string $url

The media asset URL.

int $max_width

(optional) Maximum width of the oEmbed resource, in pixels.

int $max_height

(optional) Maximum height of the oEmbed resource, in pixels.

Return Value

string

Returns the resource URL corresponding to the given media item URL.

protected string getEndpointMatchingUrl(string $url, Provider $provider)

For the given media item URL find an endpoint with schemes that match.

Parameters

string $url

The media URL used to lookup the matching endpoint.

Provider $provider

The oEmbed provider for the asset.

Return Value

string

The resource url.