AttachmentRequestBuilder
extends Builder
in package
implements
JsonSerializable
Helper class used to build attachment request payloads.
Tags
Table of Contents
Interfaces
- JsonSerializable
Properties
- $description : string|null
- Description (alt text) for the file (max 1024 characters).
- $duration_secs : float|null
- The duration of the audio or video file (required for voice messages).
- $filename : string|null
- Name of the file attached.
- $id : string
- Attachment id (snowflake or number).
- $is_spoiler : bool|null
- Whether the attachment should be marked as a spoiler and blurred until clicked, this sets the `IS_SPOILER` attachment flag.
- $title : string|null
- The title of the file.
- $waveform : string|null
- Base64 encoded bytearray representing a sampled waveform (required for voice messages).
Methods
- __get() : mixed
- Handles dynamic get calls onto the part.
- __set() : void
- Handles dynamic set calls onto the part.
- fromPart() : self
- Creates a new instance of the builder from a given Part.
- getDescription() : string|null
- Get the description (alt text).
- getDurationSecs() : float|null
- Get the duration in seconds.
- getFilename() : string|null
- Get the filename.
- getId() : string
- Returns the attachment id.
- getIsSpoiler() : bool|null
- Returns whether the attachment is marked as a spoiler.
- getTitle() : string|null
- Get the attachment title.
- getWaveform() : string|null
- Get the waveform data.
- jsonSerialize() : array<string, mixed>
- Returns the array representation of the attachment request used in Message Create/Edit payloads.
- new() : static
- Creates a new attachment request builder with a required `id`.
- setDescription() : self
- Set the description (alt text) for the file.
- setDurationSecs() : self
- Set the duration of the audio or video file in seconds.
- setFilename() : self
- Set the filename of the attachment.
- setId() : self
- Set the attachment id.
- setIsSpoiler() : self
- Mark the attachment as a spoiler.
- setTitle() : self
- Set the title of the file.
- setWaveform() : self
- Set the waveform data for voice messages.
- 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
$description
Description (alt text) for the file (max 1024 characters).
protected
string|null
$description
$duration_secs
The duration of the audio or video file (required for voice messages).
protected
float|null
$duration_secs
$filename
Name of the file attached.
protected
string|null
$filename
$id
Attachment id (snowflake or number).
protected
string
$id
For new attachments this must match the n in files[n].
$is_spoiler
Whether the attachment should be marked as a spoiler and blurred until clicked, this sets the `IS_SPOILER` attachment flag.
protected
bool|null
$is_spoiler
$title
The title of the file.
protected
string|null
$title
$waveform
Base64 encoded bytearray representing a sampled waveform (required for voice messages).
protected
string|null
$waveform
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
fromPart()
Creates a new instance of the builder from a given Part.
public
static fromPart(Part $part) : self
Parameters
- $part : Part
Return values
selfgetDescription()
Get the description (alt text).
public
getDescription() : string|null
Return values
string|nullgetDurationSecs()
Get the duration in seconds.
public
getDurationSecs() : float|null
Return values
float|nullgetFilename()
Get the filename.
public
getFilename() : string|null
Return values
string|nullgetId()
Returns the attachment id.
public
getId() : string
Return values
string —$id Attachment id (or files index for new files).
getIsSpoiler()
Returns whether the attachment is marked as a spoiler.
public
getIsSpoiler() : bool|null
Return values
bool|nullgetTitle()
Get the attachment title.
public
getTitle() : string|null
Return values
string|nullgetWaveform()
Get the waveform data.
public
getWaveform() : string|null
Return values
string|nulljsonSerialize()
Returns the array representation of the attachment request used in Message Create/Edit payloads.
public
jsonSerialize() : array<string, mixed>
Return values
array<string, mixed>new()
Creates a new attachment request builder with a required `id`.
public
static new(string $id) : static
For new attachments this must match the n in files[n].
Parameters
- $id : string
-
Attachment id (or files index for new files).
Return values
staticsetDescription()
Set the description (alt text) for the file.
public
setDescription([string|null $description = null ]) : self
Parameters
- $description : string|null = null
-
Description for the file (max 1024 characters).
Tags
Return values
selfsetDurationSecs()
Set the duration of the audio or video file in seconds.
public
setDurationSecs([float|null $seconds = null ]) : self
Required for voice messages.
Parameters
- $seconds : float|null = null
-
Duration in seconds.
Return values
selfsetFilename()
Set the filename of the attachment.
public
setFilename([string|null $filename = null ]) : self
Parameters
- $filename : string|null = null
-
Name of the file attached.
Return values
selfsetId()
Set the attachment id.
public
setId(string $id) : self
For new attachments this must match the n in files[n].
Parameters
- $id : string
-
Attachment id (or files index for new files).
Return values
selfsetIsSpoiler()
Mark the attachment as a spoiler.
public
setIsSpoiler([bool|null $is_spoiler = null ]) : self
When true, the attachment will be blurred until clicked.
Parameters
- $is_spoiler : bool|null = null
Return values
selfsetTitle()
Set the title of the file.
public
setTitle([string|null $title = null ]) : self
Parameters
- $title : string|null = null
-
The title to set for the attachment.
Return values
selfsetWaveform()
Set the waveform data for voice messages.
public
setWaveform([string|null $waveform = null ]) : self
Parameters
- $waveform : string|null = null
-
Base64 encoded sampled waveform.
Return values
selfcheckForGetMutator()
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.
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.