class PerformanceLinks extends GroupedTagBuilder

Methods

static string
key()

Get the builder key.

overlayOn(TagBuilder|null $base)

Overlay these resource hints onto the lower layer.

bool
isEmpty()

Determine whether no resource hints are defined.

static string
headArrayKey()

Get the key used in the head array.

static mixed
headArrayDefault()

Get the empty resource hint groups.

static array
routeAttributeKeys()

Get the supported route attribute names.

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

Build resource hints from a route attribute.

static bool
rendersWhenEmpty(ResolvedHead $head)

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

asDefaults()

Mark the builder's data as belonging to the defaults layer.

mixed
toHeadArray(ResolvedHead $head)

Get the resource hints for the head array.

array
toTags(ResolvedHead $head, TagRenderer $tags)

Render the resource hint 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 $preloads = [], array $prefetches = [], array $preconnects = [], array $dnsPrefetches = [])

Create the resource hint definitions.

static PerformanceLinks|null
fromPreloadAttributes(string|array $preloads)

Build preload hints from route values.

static PerformanceLinks|null
fromPrefetchAttributes(string|array $prefetches)

Build prefetch hints from route values.

static PerformanceLinks|null
fromPreconnectAttributes(string|array $preconnects)

Build preconnect hints from route values.

static PerformanceLinks|null
fromDnsPrefetchAttributes(string|array $dnsPrefetches)

Build DNS prefetch hints from route values.

preload(string $href, string|null $as = null, bool|string|null $crossorigin = null, ImageType|string|null $type = null, Media|string|null $media = null)

Add or replace a preload hint by URL.

preloadAsset(string $path, string|null $as = null, bool|string|null $crossorigin = null, ImageType|string|null $type = null, Media|string|null $media = null)

Preload an asset, inferring its resource type when omitted.

prefetch(string $href, string|null $as = null)

Add or replace a prefetch hint by URL.

prefetchAsset(string $path, string|null $as = null)

Prefetch an asset, inferring its resource type when omitted.

preconnect(string $href, bool|string|null $crossorigin = null)

Add or replace a preconnect hint by origin.

dnsPrefetch(string $href)

Add a DNS prefetch hint.

array
headArray()

Get ordered definitions for each resource hint group.

static string|null
detectAs(string $path)

Infer a resource type from its file extension.

static bool|string|null
boolOrString(mixed $value)

Return a boolean or string attribute value.

Details

at line 39
static string key()

Get the builder key.

Return Value

string

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

Overlay these resource hints onto the lower layer.

Parameters

TagBuilder|null $base

Return Value

TagBuilder

at line 259
bool isEmpty()

Determine whether no resource hints are defined.

Return Value

bool

at line 47
static string headArrayKey()

Get the key used in the head array.

Return Value

string

at line 55
static mixed headArrayDefault()

Get the empty resource hint groups.

Return Value

mixed

at line 70
static array routeAttributeKeys()

Get the supported route attribute names.

Return Value

array

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

Build resource hints 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

in TagBuilder at line 74
TagBuilder asDefaults()

Mark the builder's data as belonging to the defaults layer.

Return Value

TagBuilder

at line 272
mixed toHeadArray(ResolvedHead $head)

Get the resource hints for the head array.

Parameters

ResolvedHead $head

Return Value

mixed

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

Render the resource hint 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 28
__construct(array $preloads = [], array $prefetches = [], array $preconnects = [], array $dnsPrefetches = [])

Create the resource hint definitions.

Parameters

array $preloads
array $prefetches
array $preconnects
array $dnsPrefetches

at line 94
static PerformanceLinks|null fromPreloadAttributes(string|array $preloads)

Build preload hints from route values.

Parameters

string|array $preloads

Return Value

PerformanceLinks|null

at line 112
static PerformanceLinks|null fromPrefetchAttributes(string|array $prefetches)

Build prefetch hints from route values.

Parameters

string|array $prefetches

Return Value

PerformanceLinks|null

at line 130
static PerformanceLinks|null fromPreconnectAttributes(string|array $preconnects)

Build preconnect hints from route values.

Parameters

string|array $preconnects

Return Value

PerformanceLinks|null

at line 148
static PerformanceLinks|null fromDnsPrefetchAttributes(string|array $dnsPrefetches)

Build DNS prefetch hints from route values.

Parameters

string|array $dnsPrefetches

Return Value

PerformanceLinks|null

at line 166
PerformanceLinks preload(string $href, string|null $as = null, bool|string|null $crossorigin = null, ImageType|string|null $type = null, Media|string|null $media = null)

Add or replace a preload hint by URL.

Parameters

string $href
string|null $as
bool|string|null $crossorigin
ImageType|string|null $type
Media|string|null $media

Return Value

PerformanceLinks

at line 182
PerformanceLinks preloadAsset(string $path, string|null $as = null, bool|string|null $crossorigin = null, ImageType|string|null $type = null, Media|string|null $media = null)

Preload an asset, inferring its resource type when omitted.

Parameters

string $path
string|null $as
bool|string|null $crossorigin
ImageType|string|null $type
Media|string|null $media

Return Value

PerformanceLinks

at line 198
PerformanceLinks prefetch(string $href, string|null $as = null)

Add or replace a prefetch hint by URL.

Parameters

string $href
string|null $as

Return Value

PerformanceLinks

at line 211
PerformanceLinks prefetchAsset(string $path, string|null $as = null)

Prefetch an asset, inferring its resource type when omitted.

Parameters

string $path
string|null $as

Return Value

PerformanceLinks

at line 219
PerformanceLinks preconnect(string $href, bool|string|null $crossorigin = null)

Add or replace a preconnect hint by origin.

Parameters

string $href
bool|string|null $crossorigin

Return Value

PerformanceLinks

at line 232
PerformanceLinks dnsPrefetch(string $href)

Add a DNS prefetch hint.

Parameters

string $href

Return Value

PerformanceLinks

at line 297
protected array headArray()

Get ordered definitions for each resource hint group.

Return Value

array

at line 310
static protected string|null detectAs(string $path)

Infer a resource type from its file extension.

Parameters

string $path

Return Value

string|null

at line 331
static protected bool|string|null boolOrString(mixed $value)

Return a boolean or string attribute value.

Parameters

mixed $value

Return Value

bool|string|null