class Resource implements CacheableDependencyInterface (View source)

internal  This class is an internal part of the oEmbed system and should only be instantiated by \Drupal\media\OEmbed\ResourceFetcherInterface::fetchResource().
 

Value object representing an oEmbed resource.

Data received from an oEmbed provider could be insecure. For example, resources of the 'rich' type provide an HTML representation which is not sanitized by this object in any way. Any values you retrieve from this object should be treated as potentially dangerous user input and carefully validated and sanitized before being displayed or otherwise manipulated by your code.

Valid resource types are defined in the oEmbed specification and represented by the TYPE_* constants in this class.

Traits

Trait for \Drupal\Core\Cache\CacheableDependencyInterface.

Constants

TYPE_LINK

The resource type for link resources.

TYPE_PHOTO

The resource type for photo resources.

TYPE_RICH

The resource type for rich resources.

TYPE_VIDEO

The resource type for video resources.

Properties

protected string[] $cacheContexts

Cache contexts.

from  CacheableDependencyTrait
protected string[] $cacheTags

Cache tags.

from  CacheableDependencyTrait
protected int $cacheMaxAge

Cache max-age.

from  CacheableDependencyTrait
protected string $type

The resource type. Can be one of the static::TYPE_* constants.

protected Provider $provider

The resource provider.

protected string $title

A text title, describing the resource.

protected string $authorName

The name of the author/owner of the resource.

protected string $authorUrl

A URL for the author/owner of the resource.

protected string $thumbnailUrl

A URL to a thumbnail image representing the resource.

protected int $thumbnailWidth

The width of the thumbnail, in pixels.

protected int $thumbnailHeight

The height of the thumbnail, in pixels.

protected int $width

The width of the resource, in pixels.

protected int $height

The height of the resource, in pixels.

protected string $url

The resource URL. Only applies to 'photo' and 'link' resources.

protected string $html

The HTML representation of the resource.

Methods

$this
setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

getCacheTags()

{@inheritdoc}

__construct(Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)

Resource constructor.

static Resource
link(string $url = NULL, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)

Creates a link resource.

static Resource
photo(string $url, int $width, int $height = NULL, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)

Creates a photo resource.

static Resource
rich(string $html, int $width, int $height = NULL, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)

Creates a rich resource.

static Resource
video(string $html, int $width, int $height = NULL, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)

Creates a video resource.

string
getType()

Returns the resource type.

string|null
getTitle()

Returns the title of the resource.

string|null
getAuthorName()

Returns the name of the resource author.

Url|null
getAuthorUrl()

Returns the URL of the resource author.

Provider|null
getProvider()

Returns the resource provider, if known.

Url|null
getThumbnailUrl()

Returns the URL of the resource's thumbnail image.

int|null
getThumbnailWidth()

Returns the width of the resource's thumbnail image.

int|null
getThumbnailHeight()

Returns the height of the resource's thumbnail image.

int|null
getWidth()

Returns the width of the resource.

int|null
getHeight()

Returns the height of the resource.

Url|null
getUrl()

Returns the URL of the resource. Only applies to 'photo' resources.

string|null
getHtml()

Returns the HTML representation of the resource.

setThumbnailDimensions(int $width, int $height)

Sets the thumbnail dimensions.

setDimensions(int|null $width, int|null $height)

Sets the dimensions.

Details

protected $this setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

Parameters

CacheableDependencyInterface $cacheability

The cacheability to set.

Return Value

$this

getCacheTags()

{@inheritdoc}

getCacheContexts()

{@inheritdoc}

getCacheMaxAge()

{@inheritdoc}

protected __construct(Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)

Resource constructor.

Parameters

Provider $provider

(optional) The resource provider.

string $title

(optional) A text title, describing the resource.

string $author_name

(optional) The name of the author/owner of the resource.

string $author_url

(optional) A URL for the author/owner of the resource.

int $cache_age

(optional) The suggested cache lifetime for this resource, in seconds.

string $thumbnail_url

(optional) A URL to a thumbnail image representing the resource. If this parameter is present, $thumbnail_width and $thumbnail_height must also be present.

int $thumbnail_width

(optional) The width of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_height must also be present.

int $thumbnail_height

(optional) The height of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_width must also be present.

Creates a link resource.

Parameters

string $url

(optional) The URL of the resource.

Provider $provider

(optional) The resource provider.

string $title

(optional) A text title, describing the resource.

string $author_name

(optional) The name of the author/owner of the resource.

string $author_url

(optional) A URL for the author/owner of the resource.

int $cache_age

(optional) The suggested cache lifetime for this resource, in seconds.

string $thumbnail_url

(optional) A URL to a thumbnail image representing the resource. If this parameter is present, $thumbnail_width and $thumbnail_height must also be present.

int $thumbnail_width

(optional) The width of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_height must also be present.

int $thumbnail_height

(optional) The height of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_width must also be present.

Return Value

Resource

static Resource photo(string $url, int $width, int $height = NULL, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)

Creates a photo resource.

Parameters

string $url

The URL of the photo.

int $width

The width of the photo, in pixels.

int $height

(optional) The height of the photo, in pixels.

Provider $provider

(optional) The resource provider.

string $title

(optional) A text title, describing the resource.

string $author_name

(optional) The name of the author/owner of the resource.

string $author_url

(optional) A URL for the author/owner of the resource.

int $cache_age

(optional) The suggested cache lifetime for this resource, in seconds.

string $thumbnail_url

(optional) A URL to a thumbnail image representing the resource. If this parameter is present, $thumbnail_width and $thumbnail_height must also be present.

int $thumbnail_width

(optional) The width of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_height must also be present.

int $thumbnail_height

(optional) The height of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_width must also be present.

Return Value

Resource

static Resource rich(string $html, int $width, int $height = NULL, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)

Creates a rich resource.

Parameters

string $html

The HTML representation of the resource.

int $width

The width of the resource, in pixels.

int $height

(optional) The height of the resource, in pixels.

Provider $provider

(optional) The resource provider.

string $title

(optional) A text title, describing the resource.

string $author_name

(optional) The name of the author/owner of the resource.

string $author_url

(optional) A URL for the author/owner of the resource.

int $cache_age

(optional) The suggested cache lifetime for this resource, in seconds.

string $thumbnail_url

(optional) A URL to a thumbnail image representing the resource. If this parameter is present, $thumbnail_width and $thumbnail_height must also be present.

int $thumbnail_width

(optional) The width of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_height must also be present.

int $thumbnail_height

(optional) The height of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_width must also be present.

Return Value

Resource

static Resource video(string $html, int $width, int $height = NULL, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)

Creates a video resource.

Parameters

string $html

The HTML required to display the video.

int $width

The width of the video, in pixels.

int $height

(optional) The height of the video, in pixels.

Provider $provider

(optional) The resource provider.

string $title

(optional) A text title, describing the resource.

string $author_name

(optional) The name of the author/owner of the resource.

string $author_url

(optional) A URL for the author/owner of the resource.

int $cache_age

(optional) The suggested cache lifetime for this resource, in seconds.

string $thumbnail_url

(optional) A URL to a thumbnail image representing the resource. If this parameter is present, $thumbnail_width and $thumbnail_height must also be present.

int $thumbnail_width

(optional) The width of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_height must also be present.

int $thumbnail_height

(optional) The height of the thumbnail, in pixels. If this parameter is present, $thumbnail_url and $thumbnail_width must also be present.

Return Value

Resource

string getType()

Returns the resource type.

Return Value

string

The resource type. Will be one of the self::TYPE_* constants.

string|null getTitle()

Returns the title of the resource.

Return Value

string|null

The title of the resource, if known.

string|null getAuthorName()

Returns the name of the resource author.

Return Value

string|null

The name of the resource author, if known.

Url|null getAuthorUrl()

Returns the URL of the resource author.

Return Value

Url|null

The absolute URL of the resource author, or NULL if none is provided.

Provider|null getProvider()

Returns the resource provider, if known.

Return Value

Provider|null

The resource provider, or NULL if the provider is not known.

Url|null getThumbnailUrl()

Returns the URL of the resource's thumbnail image.

Return Value

Url|null

The absolute URL of the thumbnail image, or NULL if there isn't one.

int|null getThumbnailWidth()

Returns the width of the resource's thumbnail image.

Return Value

int|null

The thumbnail width in pixels, or NULL if there is no thumbnail.

int|null getThumbnailHeight()

Returns the height of the resource's thumbnail image.

Return Value

int|null

The thumbnail height in pixels, or NULL if there is no thumbnail.

int|null getWidth()

Returns the width of the resource.

Return Value

int|null

The width of the resource in pixels, or NULL if the resource has no width.

int|null getHeight()

Returns the height of the resource.

Return Value

int|null

The height of the resource in pixels, or NULL if the resource has no height.

Url|null getUrl()

Returns the URL of the resource. Only applies to 'photo' resources.

Return Value

Url|null

The resource URL, if it has one.

string|null getHtml()

Returns the HTML representation of the resource.

Only applies to 'rich' and 'video' resources.

Return Value

string|null

The HTML representation of the resource, if it has one.

protected setThumbnailDimensions(int $width, int $height)

Sets the thumbnail dimensions.

Parameters

int $width

The width of the resource.

int $height

The height of the resource.

Exceptions

InvalidArgumentException

protected setDimensions(int|null $width, int|null $height)

Sets the dimensions.

Parameters

int|null $width

The width of the resource.

int|null $height

The height of the resource.

Exceptions

InvalidArgumentException