ComponentEmbedBuilder
extends Builder
in package
implements
JsonSerializable
Authors display-only website link previews, without a Discord client or bot.
Put toScript() in the server-rendered HTML head alongside Open Graph fallback tags. This is not a MessageBuilder payload and cannot send interactions.
Tags
Table of Contents
Interfaces
- JsonSerializable
Properties
- $component : array<string|int, mixed>|null
Methods
- __get() : mixed
- Handles dynamic get calls onto the part.
- __isset() : bool
- Handles dynamic isset() and empty() calls onto the part.
- __set() : void
- Handles dynamic set calls onto the part.
- fromPart() : self
- Received previews include fetched media metadata and are not website authoring payloads.
- getComponent() : ?array<string|int, mixed>
- Returns the validated root Container snapshot.
- jsonSerialize() : array<string|int, mixed>
- new() : self
- Creates a website preview from a Container builder or an API-shaped array.
- setComponent() : self
- Snapshots and validates the tree, including the final script-safe JSON byte length.
- toJson() : string
- Returns JSON for inline scripts or a linked JSON document. Escapes count toward 3,000 bytes.
- toScript() : string
- Returns the complete script element for a server-rendered HTML head.
- checkForGetMutator() : string|false
- Checks if there is a get mutator present.
- checkForSetMutator() : string|false
- Checks if there is a set mutator present.
- getProperty() : mixed
- Gets a property on the parent part.
- setProperty() : void
- Sets an property on the parent part.
- encode() : string
- studly() : string
- Converts a string to studlyCase.
Properties
$component
protected
array<string|int, mixed>|null
$component
= null
Validated snapshot of the root Container.
Methods
__get()
Handles dynamic get calls onto the part.
public
__get(string $key) : mixed
Parameters
- $key : string
-
The attributes key.
Tags
Return values
mixed —The value of the attribute.
__isset()
Handles dynamic isset() and empty() calls onto the part.
public
__isset(string $key) : bool
A property is set when reading it yields a non-null value, which is the
contract ?? already has: only properties with a get mutator can be set.
Parameters
- $key : string
-
The attributes key.
Tags
Return values
bool —Whether reading the property yields a non-null value.
__set()
Handles dynamic set calls onto the part.
public
__set(string $key, mixed $value) : void
Parameters
- $key : string
-
The attributes key.
- $value : mixed
-
The attributes value.
Tags
fromPart()
Received previews include fetched media metadata and are not website authoring payloads.
public
static fromPart(Part $part) : self
Parameters
- $part : Part
Tags
Return values
selfgetComponent()
Returns the validated root Container snapshot.
public
getComponent() : ?array<string|int, mixed>
Return values
?array<string|int, mixed>jsonSerialize()
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>new()
Creates a website preview from a Container builder or an API-shaped array.
public
static new(Container|array<string|int, mixed> $component) : self
Parameters
- $component : Container|array<string|int, mixed>
Return values
selfsetComponent()
Snapshots and validates the tree, including the final script-safe JSON byte length.
public
setComponent(Container|array<string|int, mixed> $component) : self
Parameters
- $component : Container|array<string|int, mixed>
Tags
Return values
selftoJson()
Returns JSON for inline scripts or a linked JSON document. Escapes count toward 3,000 bytes.
public
toJson() : string
Return values
stringtoScript()
Returns the complete script element for a server-rendered HTML head.
public
toScript() : string
Return values
stringcheckForGetMutator()
Checks if there is a get mutator present.
protected
checkForGetMutator(string $key) : string|false
Parameters
- $key : string
-
The property name to check.
Return values
string|false —Either a string if it is a method or false.
checkForSetMutator()
Checks if there is a set mutator present.
protected
checkForSetMutator(string $key) : string|false
Parameters
- $key : string
-
The property name to check.
Return values
string|false —Either a string if it is a method or false.
getProperty()
Gets a property on the parent part.
protected
getProperty(string $key) : mixed
Parameters
- $key : string
-
The name of the property.
Tags
Return values
mixed —Either the property if it exists or void.
setProperty()
Sets an property on the parent part.
protected
setProperty(string $key, mixed $value) : void
Parameters
- $key : string
-
The name of the property.
- $value : mixed
-
The value of the property.
encode()
private
static encode(array<string|int, mixed> $component) : string
Parameters
- $component : array<string|int, mixed>
Return values
stringstudly()
Converts a string to studlyCase.
private
static studly(string $string) : string
This is a port of updated Laravel's implementation, a non-regex with static cache. This method is private static as we may move it outside this class in future.
Parameters
- $string : string
-
The string to convert.