Skip to content

Commit 530c338

Browse files
committed
2 parents aa60d60 + 4bbee4d commit 530c338

File tree

17 files changed

+129
-67
lines changed

17 files changed

+129
-67
lines changed

src/Discord/Builders/Components/ActionRow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ActionRow extends Layout
3838
*
3939
* @var ComponentObject[]
4040
*/
41-
private $components = [];
41+
protected $components = [];
4242

4343
/**
4444
* Creates a new action row.

src/Discord/Builders/Components/Button.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,56 +53,56 @@ class Button extends Interactive
5353
*
5454
* @var int
5555
*/
56-
private $style = 1;
56+
protected $style = 1;
5757

5858
/**
5959
* Label for the button.
6060
*
6161
* @var string|null
6262
*/
63-
private $label;
63+
protected $label;
6464

6565
/**
6666
* Emoji to display on the button.
6767
*
6868
* @var array|null
6969
*/
70-
private $emoji;
70+
protected $emoji;
7171

7272
/**
7373
* Identifier for a purchasable SKU, only available when using premium-style buttons.
7474
*
7575
* @var string|null
7676
*/
77-
private $sku_id;
77+
protected $sku_id;
7878

7979
/**
8080
* URL to send as the button. Only for link buttons.
8181
*
8282
* @var string|null
8383
*/
84-
private $url;
84+
protected $url;
8585

8686
/**
8787
* Whether the button is disabled.
8888
*
8989
* @var bool
9090
*/
91-
private $disabled = false;
91+
protected $disabled = false;
9292

9393
/**
9494
* Listener for when the button is pressed.
9595
*
9696
* @var callable|null
9797
*/
98-
private $listener;
98+
protected $listener;
9999

100100
/**
101101
* Discord instance when the listener is set.
102102
*
103103
* @var Discord|null
104104
*/
105-
private $discord;
105+
protected $discord;
106106

107107
/**
108108
* Creates a new button.

src/Discord/Builders/Components/Component.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,44 @@ abstract class Component implements JsonSerializable
4747
/** @deprecated 7.4.0 Use `Component::TYPE_STRING_SELECT` */
4848
public const TYPE_SELECT_MENU = 3;
4949

50+
public const TYPE_CLASSES = [
51+
self::TYPE_ACTION_ROW => ActionRow::class,
52+
self::TYPE_BUTTON => Button::class,
53+
self::TYPE_STRING_SELECT => StringSelect::class,
54+
self::TYPE_TEXT_INPUT => TextInput::class,
55+
self::TYPE_USER_SELECT => UserSelect::class,
56+
self::TYPE_ROLE_SELECT => RoleSelect::class,
57+
self::TYPE_MENTIONABLE_SELECT => MentionableSelect::class,
58+
self::TYPE_CHANNEL_SELECT => ChannelSelect::class,
59+
self::TYPE_SECTION => Section::class,
60+
self::TYPE_TEXT_DISPLAY => TextDisplay::class,
61+
self::TYPE_THUMBNAIL => Thumbnail::class,
62+
self::TYPE_MEDIA_GALLERY => MediaGallery::class,
63+
self::TYPE_FILE => File::class,
64+
self::TYPE_SEPARATOR => Separator::class,
65+
self::TYPE_CONTAINER => Container::class
66+
];
67+
68+
69+
/**
70+
* Fills the properties of the current object with values from the provided associative array.
71+
*
72+
* Iterates over each key-value pair in the input array and assigns the value to the corresponding
73+
* property of the object if the property exists.
74+
*
75+
* @param array $data
76+
*
77+
* @return void
78+
*/
79+
public function fill(array $data): void
80+
{
81+
foreach ($data as $key => $value) {
82+
if (property_exists($this, $key)) {
83+
$this->{$key} = $value;
84+
}
85+
}
86+
}
87+
5088
/**
5189
* Generates a UUID which can be used for component custom IDs.
5290
*

src/Discord/Builders/Components/Container.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ class Container extends Layout implements Contracts\ComponentV2
3535
*
3636
* @var ComponentObject[]
3737
*/
38-
private $components = [];
38+
protected $components = [];
3939

4040
/**
4141
* Accent color for the container.
4242
*
4343
* @var int|null
4444
*/
45-
private $accent_color;
45+
protected $accent_color;
4646

4747
/**
4848
* Whether the container is a spoiler.
4949
*
5050
* @var bool
5151
*/
52-
private $spoiler = false;
52+
protected $spoiler = false;
5353

5454
/**
5555
* Creates a new container.

src/Discord/Builders/Components/File.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class File extends Content implements Contracts\ComponentV2
3636
*
3737
* @var array
3838
*/
39-
private $file;
39+
protected $file;
4040

4141
/**
4242
* Whether the file is a spoiler.
4343
*
4444
* @var bool
4545
*/
46-
private $spoiler = false;
46+
protected $spoiler = false;
4747

4848
/**
4949
* Creates a new file component.

src/Discord/Builders/Components/MediaGallery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MediaGallery extends Content implements Contracts\ComponentV2
3434
*
3535
* @var MediaGalleryItem[]
3636
*/
37-
private $items = [];
37+
protected $items = [];
3838

3939
/**
4040
* Creates a new media gallery.

src/Discord/Builders/Components/MediaGalleryItem.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ class MediaGalleryItem implements JsonSerializable
2929
*
3030
* @var UnfurledMediaItem
3131
*/
32-
private $media;
32+
protected $media;
3333

3434
/**
3535
* Description for the gallery item.
3636
*
3737
* @var string|null
3838
*/
39-
private $description;
39+
protected $description;
4040

4141
/**
4242
* Whether the gallery item is a spoiler.
4343
*
4444
* @var bool
4545
*/
46-
private $spoiler = false;
46+
protected $spoiler = false;
4747

4848
/**
4949
* Creates a new media gallery item.

src/Discord/Builders/Components/Option.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,35 @@ class Option extends Component
3131
*
3232
* @var string
3333
*/
34-
private $label;
34+
protected $label;
3535

3636
/**
3737
* Developer value for the option. Maximum 100 characters.
3838
*
3939
* @var string
4040
*/
41-
private $value;
41+
protected $value;
4242

4343
/**
4444
* Description for the option. Maximum 50 characters.
4545
*
4646
* @var string|null
4747
*/
48-
private $description;
48+
protected $description;
4949

5050
/**
5151
* Emoji to display alongside the option.
5252
*
5353
* @var array|null
5454
*/
55-
private $emoji;
55+
protected $emoji;
5656

5757
/**
5858
* Whether the option should be enabled as default.
5959
*
6060
* @var bool
6161
*/
62-
private $default = false;
62+
protected $default = false;
6363

6464
/**
6565
* Creates a new select menu option.

src/Discord/Builders/Components/Section.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ class Section extends Layout implements Contracts\ComponentV2
3434
*
3535
* @var TextDisplay[]
3636
*/
37-
private $components = [];
37+
protected $components = [];
3838

3939
/**
4040
* Accessory component (Thumbnail or Button).
4141
*
4242
* @var Thumbnail|Button|null
4343
*/
44-
private $accessory;
44+
protected $accessory;
4545

4646
/**
4747
* Creates a new section.

src/Discord/Builders/Components/Separator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ class Separator extends Layout implements Contracts\ComponentV2
4141
*
4242
* @var bool
4343
*/
44-
private $divider = true;
44+
protected $divider = true;
4545

4646
/**
4747
* Spacing size for the separator.
4848
*
4949
* @var int
5050
*/
51-
private $spacing = self::SPACING_SMALL;
51+
protected $spacing = self::SPACING_SMALL;
5252

5353
/**
5454
* Creates a new separator.

0 commit comments

Comments
 (0)