class Canonical extends TagBuilder

Properties

static protected null|Closure(): ?string $originResolver

Methods

static string
key()

Get the builder key.

overlayOn(TagBuilder|null $base)

Overlay this URL while inheriting unspecified normalization options.

bool
isEmpty()

Canonical builders always carry a resolution mode, so they are never empty.

static string
headArrayKey()

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

static mixed
headArrayDefault()

Get the value used in Head::toArray() when this builder has no data.

static array
routeAttributeKeys()

Get the route attribute keys this builder accepts values for.

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

Build a canonical URL 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 resolved canonical URL for the head array.

array
toTags(ResolvedHead $head, TagRenderer $tags)

Render the canonical link tag.

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(string $mode, string|null $url = null, bool|null $forceHttps = null, bool|null $trailingSlash = null)

Create a canonical URL definition.

static Canonical
make(string|null $url = null, bool|null $forceHttps = null, bool|null $trailingSlash = null)

Use a null $url to resolve the canonical URL from the current request.

string|null
render(Request|null $request)

Resolve and normalize the canonical URL.

static void
resolveOriginUsing(Closure|null $resolver)

Register a resolver for automatic and relative canonical origins.

string
normalizeUrl(string $url, Request|null $request, bool $forceHttps, bool $trailingSlash)

Normalize the origin and path without changing the query or fragment.

static void
flushState()

Flush all static state.

Details

at line 37
static string key()

Get the builder key.

Return Value

string

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

Overlay this URL while inheriting unspecified normalization options.

Parameters

TagBuilder|null $base

Return Value

TagBuilder

at line 87
bool isEmpty()

Canonical builders always carry a resolution mode, so they are never empty.

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 TagBuilder at line 40
static mixed headArrayDefault()

Get the value used in Head::toArray() when this builder has no data.

Return Value

mixed

in TagBuilder at line 50
static array routeAttributeKeys()

Get the route attribute keys this builder accepts values for.

Return Value

array

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

Build a canonical URL 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 113
mixed toHeadArray(ResolvedHead $head)

Get the resolved canonical URL for the head array.

Parameters

ResolvedHead $head

Return Value

mixed

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

Render the canonical link tag.

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 26
__construct(string $mode, string|null $url = null, bool|null $forceHttps = null, bool|null $trailingSlash = null)

Create a canonical URL definition.

Parameters

string $mode

either "url" for an explicit URL or "auto" to resolve from the request

string|null $url
bool|null $forceHttps
bool|null $trailingSlash

at line 45
static Canonical make(string|null $url = null, bool|null $forceHttps = null, bool|null $trailingSlash = null)

Use a null $url to resolve the canonical URL from the current request.

Parameters

string|null $url
bool|null $forceHttps
bool|null $trailingSlash

Return Value

Canonical

at line 95
string|null render(Request|null $request)

Resolve and normalize the canonical URL.

Parameters

Request|null $request

Return Value

string|null

at line 171
static void resolveOriginUsing(Closure|null $resolver)

Register a resolver for automatic and relative canonical origins.

The callback persists in a static property and affects every request in the worker.

Parameters

Closure|null $resolver

Return Value

void

at line 180
protected string normalizeUrl(string $url, Request|null $request, bool $forceHttps, bool $trailingSlash)

Normalize the origin and path without changing the query or fragment.

Parameters

string $url
Request|null $request
bool $forceHttps
bool $trailingSlash

Return Value

string

at line 219
static void flushState()

Flush all static state.

Return Value

void