class OpenGraph extends GroupedTagBuilder

Properties

protected bool $imagesAreDefaults
protected bool $videosAreDefaults
protected bool $audiosAreDefaults

Methods

static string
key()

Get the builder key.

overlayOn(TagBuilder|null $base)

Overlay properties and media onto the lower layer.

bool
isEmpty()

Determine whether no properties or media are defined.

static string
headArrayKey()

Get the dot-notated key this builder occupies in the Head::toArray() result.

static mixed
headArrayDefault()

Grouped tag builders are represented as an empty array when absent from the Head::toArray() result.

static array
routeAttributeKeys()

Get the supported route attribute names.

static TagBuilder|null
fromRouteAttribute(string $key, mixed $value)

Build Open Graph metadata from a route attribute.

static bool
rendersWhenEmpty(ResolvedHead $head)

Determine if the builder should render even when no data was set.

asDefaults()

Mark all media as fallback values for higher layers.

mixed
toHeadArray(ResolvedHead $head)

Get the resolved Open Graph metadata for the head array.

array
toTags(ResolvedHead $head, TagRenderer $tags)

Render Open Graph properties and grouped media tags.

static string|null
string(mixed $value)

Return the value when it is a string.

static string|null
stringOrBackedEnum(mixed $value)

Resolve a string or string-backed enum value.

static bool|null
bool(mixed $value)

Return the value when it is a boolean.

static int|null
int(mixed $value)

Return the value when it is an integer.

static array
items(mixed $value)

Normalize a route attribute value into a list of items.

static array
named(array $values)

Filter an array down to its string-keyed values.

__construct(array $properties = [], array $images = [], array $videos = [], array $audios = [])

Create the Open Graph properties and media.

static OpenGraph
make(OgType|string|null $type = null, string|null $title = null, string|null $description = null, string|null $url = null, string|null $image = null, string|null $video = null, string|null $audio = null, string|null $siteName = null, string|null $locale = null, string|null $determiner = null)

Create Open Graph metadata from named values.

static OpenGraph
fromAttributes(array $values)

Create Open Graph metadata from an attribute map.

static OpenGraph
fromImageAttributes(mixed $images)

Build Open Graph images from route values.

static OpenGraph
fromVideoAttributes(mixed $videos)

Build Open Graph videos from route values.

static OpenGraph
fromAudioAttributes(mixed $audios)

Build Open Graph audio from route values.

image(string $url, string|null $alt = null, int|null $width = null, int|null $height = null, ImageType|string|null $type = null, string|null $secureUrl = null)

Add or replace an image by URL.

video(string $url, string|null $alt = null, int|null $width = null, int|null $height = null, string|null $type = null, string|null $secureUrl = null)

Add or replace a video by URL.

audio(string $url, string|null $type = null, string|null $secureUrl = null)

Add or replace audio by URL.

array
overlayMedia(array $base, array $overlay, bool $baseIsDefaults)

Media inherited from the defaults layer is a fallback, so media defined by a higher layer replaces it rather than merging with it.

bool
hasMedia()

Determine whether any media is defined.

array
render(string|null $title = null, string|null $description = null, string|null $url = null)

Get the Open Graph properties, falling back to the page title, description, and canonical URL.

array
images()

Get the image definitions keyed by URL.

array
headArray(string|null $title = null, string|null $description = null, string|null $url = null)

Get nonempty Open Graph properties and media lists.

void
set(array $properties)

Set each specified Open Graph property.

static array
media(string $url, string|null $alt = null, int|null $width = null, int|null $height = null, string|null $type = null, string|null $secureUrl = null)

Normalize a media definition, omitting unspecified attributes.

static OgType|string|null
ogType(mixed $value)

Resolve an Open Graph type value.

static string|null
imageType(mixed $value)

Resolve an image MIME type.

array
mediaTags(TagRenderer $tags, string $property, array $media)

Render each media item with its associated attributes.

Details

at line 44
static string key()

Get the builder key.

Return Value

string

at line 259
TagBuilder overlayOn(TagBuilder|null $base)

Overlay properties and media onto the lower layer.

Parameters

TagBuilder|null $base

Return Value

TagBuilder

at line 321
bool isEmpty()

Determine whether no properties or media are defined.

Return Value

bool

in TagBuilder at line 32
static string headArrayKey()

Get the dot-notated key this builder occupies in the Head::toArray() result.

Return Value

string

in GroupedTagBuilder at line 13
static mixed headArrayDefault()

Grouped tag builders are represented as an empty array when absent from the Head::toArray() result.

Return Value

mixed

at line 54
static array routeAttributeKeys()

Get the supported route attribute names.

Return Value

array

at line 104
static TagBuilder|null fromRouteAttribute(string $key, mixed $value)

Build Open Graph metadata from a route attribute.

Parameters

string $key
mixed $value

Return Value

TagBuilder|null

in TagBuilder at line 66
static bool rendersWhenEmpty(ResolvedHead $head)

Determine if the builder should render even when no data was set.

Parameters

ResolvedHead $head

Return Value

bool

at line 283
TagBuilder asDefaults()

Mark all media as fallback values for higher layers.

Return Value

TagBuilder

at line 366
mixed toHeadArray(ResolvedHead $head)

Get the resolved Open Graph metadata for the head array.

Parameters

ResolvedHead $head

Return Value

mixed

at line 376
array toTags(ResolvedHead $head, TagRenderer $tags)

Render Open Graph properties and grouped media tags.

Parameters

ResolvedHead $head
TagRenderer $tags

Return Value

array

in TagBuilder at line 100
static protected string|null string(mixed $value)

Return the value when it is a string.

Parameters

mixed $value

Return Value

string|null

in TagBuilder at line 108
static protected string|null stringOrBackedEnum(mixed $value)

Resolve a string or string-backed enum value.

Parameters

mixed $value

Return Value

string|null

in TagBuilder at line 124
static protected bool|null bool(mixed $value)

Return the value when it is a boolean.

Parameters

mixed $value

Return Value

bool|null

in TagBuilder at line 132
static protected int|null int(mixed $value)

Return the value when it is an integer.

Parameters

mixed $value

Return Value

int|null

in TagBuilder at line 142
static protected array items(mixed $value)

Normalize a route attribute value into a list of items.

Parameters

mixed $value

Return Value

array

in TagBuilder at line 153
static protected array named(array $values)

Filter an array down to its string-keyed values.

Parameters

array $values

Return Value

array

at line 27
__construct(array $properties = [], array $images = [], array $videos = [], array $audios = [])

Create the Open Graph properties and media.

Parameters

array $properties
array $images
array $videos
array $audios

at line 62
static OpenGraph make(OgType|string|null $type = null, string|null $title = null, string|null $description = null, string|null $url = null, string|null $image = null, string|null $video = null, string|null $audio = null, string|null $siteName = null, string|null $locale = null, string|null $determiner = null)

Create Open Graph metadata from named values.

Parameters

OgType|string|null $type
string|null $title
string|null $description
string|null $url
string|null $image
string|null $video
string|null $audio
string|null $siteName
string|null $locale
string|null $determiner

Return Value

OpenGraph

at line 120
static OpenGraph fromAttributes(array $values)

Create Open Graph metadata from an attribute map.

Parameters

array $values

Return Value

OpenGraph

at line 139
static OpenGraph fromImageAttributes(mixed $images)

Build Open Graph images from route values.

Parameters

mixed $images

Return Value

OpenGraph

at line 166
static OpenGraph fromVideoAttributes(mixed $videos)

Build Open Graph videos from route values.

Parameters

mixed $videos

Return Value

OpenGraph

at line 193
static OpenGraph fromAudioAttributes(mixed $audios)

Build Open Graph audio from route values.

Parameters

mixed $audios

Return Value

OpenGraph

at line 217
OpenGraph image(string $url, string|null $alt = null, int|null $width = null, int|null $height = null, ImageType|string|null $type = null, string|null $secureUrl = null)

Add or replace an image by URL.

Parameters

string $url
string|null $alt
int|null $width
int|null $height
ImageType|string|null $type
string|null $secureUrl

Return Value

OpenGraph

at line 233
OpenGraph video(string $url, string|null $alt = null, int|null $width = null, int|null $height = null, string|null $type = null, string|null $secureUrl = null)

Add or replace a video by URL.

Parameters

string $url
string|null $alt
int|null $width
int|null $height
string|null $type
string|null $secureUrl

Return Value

OpenGraph

at line 249
OpenGraph audio(string $url, string|null $type = null, string|null $secureUrl = null)

Add or replace audio by URL.

Parameters

string $url
string|null $type
string|null $secureUrl

Return Value

OpenGraph

at line 301
protected array overlayMedia(array $base, array $overlay, bool $baseIsDefaults)

Media inherited from the defaults layer is a fallback, so media defined by a higher layer replaces it rather than merging with it.

Parameters

array $base
array $overlay
bool $baseIsDefaults

Return Value

array

at line 313
protected bool hasMedia()

Determine whether any media is defined.

Return Value

bool

at line 332
array render(string|null $title = null, string|null $description = null, string|null $url = null)

Get the Open Graph properties, falling back to the page title, description, and canonical URL.

Parameters

string|null $title
string|null $description
string|null $url

Return Value

array

at line 356
array images()

Get the image definitions keyed by URL.

Return Value

array

at line 398
protected array headArray(string|null $title = null, string|null $description = null, string|null $url = null)

Get nonempty Open Graph properties and media lists.

Parameters

string|null $title
string|null $description
string|null $url

Return Value

array

at line 413
protected void set(array $properties)

Set each specified Open Graph property.

Parameters

array $properties

Return Value

void

at line 427
static protected array media(string $url, string|null $alt = null, int|null $width = null, int|null $height = null, string|null $type = null, string|null $secureUrl = null)

Normalize a media definition, omitting unspecified attributes.

Parameters

string $url
string|null $alt
int|null $width
int|null $height
string|null $type
string|null $secureUrl

Return Value

array

at line 448
static protected OgType|string|null ogType(mixed $value)

Resolve an Open Graph type value.

Parameters

mixed $value

Return Value

OgType|string|null

at line 456
static protected string|null imageType(mixed $value)

Resolve an image MIME type.

Parameters

mixed $value

Return Value

string|null

at line 467
protected array mediaTags(TagRenderer $tags, string $property, array $media)

Render each media item with its associated attributes.

Parameters

TagRenderer $tags
string $property
array $media

Return Value

array