ModalBuilder
extends Builder
in package
implements
JsonSerializable
Helper class used to build messages.
Tags
Table of Contents
Interfaces
- JsonSerializable
Properties
- $components : array<string|int, ComponentObject>
- Between 1 and 5 (inclusive) components that make up the modal.
- $custom_id : string
- Developer-defined identifier for the component, max 100 characters.
- $title : string
- The title of the popup modal, max 45 characters.
- $type : int
- Interaction type.
Methods
- __get() : mixed
- Handles dynamic get calls onto the part.
- __set() : void
- Handles dynamic set calls onto the part.
- addComponent() : $this
- Add a component to the modal.
- fromPart() : self
- Creates a new instance of the builder from a given Part.
- getComponents() : array<string|int, ComponentObject>
- Returns the components of the modal.
- getCustomId() : string
- Returns the custom ID of the modal.
- getTitle() : string
- Returns the title of the modal.
- jsonSerialize() : array<string|int, mixed>
- new() : static
- Creates a new message builder.
- removeComponent() : $this
- Removes a component from the builder.
- setComponents() : $this
- Sets the components of the modal.
- setCustomId() : $this
- Sets the custom ID of the modal.
- setTitle() : $this
- Set the title of the modal.
- 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.
- studly() : string
- Converts a string to studlyCase.
Properties
$components
Between 1 and 5 (inclusive) components that make up the modal.
protected
array<string|int, ComponentObject>
$components
$custom_id
Developer-defined identifier for the component, max 100 characters.
protected
string
$custom_id
$title
The title of the popup modal, max 45 characters.
protected
string
$title
$type
Interaction type.
protected
int
$type
= \Discord\Parts\Interactions\Interaction::RESPONSE_TYPE_MODAL
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.
__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
addComponent()
Add a component to the modal.
public
addComponent(ComponentObject $component) : $this
Only ActionRow, TextDisplay, and Label components are allowed.
Using ActionRow in modals is now deprecated. Use Component::Label
as the top level component.
Parameters
- $component : ComponentObject
Return values
$thisfromPart()
Creates a new instance of the builder from a given Part.
public
static fromPart(Part $part) : self
Parameters
- $part : Part
Return values
selfgetComponents()
Returns the components of the modal.
public
getComponents() : array<string|int, ComponentObject>
Return values
array<string|int, ComponentObject>getCustomId()
Returns the custom ID of the modal.
public
getCustomId() : string
Return values
stringgetTitle()
Returns the title of the modal.
public
getTitle() : string
Return values
stringjsonSerialize()
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>new()
Creates a new message builder.
public
static new(string $title, string $custom_id, array<string|int, ComponentObject> $components) : static
Parameters
- $title : string
- $custom_id : string
- $components : array<string|int, ComponentObject>
Return values
staticremoveComponent()
Removes a component from the builder.
public
removeComponent(ComponentObject $component) : $this
Parameters
- $component : ComponentObject
-
Component to remove.
Return values
$thissetComponents()
Sets the components of the modal.
public
setComponents(array<string|int, ComponentObject> ...$components) : $this
Parameters
- $components : array<string|int, ComponentObject>
Return values
$thissetCustomId()
Sets the custom ID of the modal.
public
setCustomId(string $custom_id) : $this
Parameters
- $custom_id : string
Tags
Return values
$thissetTitle()
Set the title of the modal.
public
setTitle(string $title) : $this
Parameters
- $title : string
-
Maximum length is 45 characters.
Tags
Return values
$thischeckForGetMutator()
Checks if there is a get mutator present.
private
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.
private
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.
private
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.
private
setProperty(string $key, mixed $value) : void
Parameters
- $key : string
-
The name of the property.
- $value : mixed
-
The value of the property.
studly()
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.