generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
ReactionType
data type, fixed typing
- Loading branch information
1 parent
5e3cd22
commit a21eada
Showing
9 changed files
with
163 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DefStudio\Telegraph\DTO; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
/** | ||
* @implements Arrayable<string, string|null> | ||
*/ | ||
class ReactionType implements Arrayable | ||
{ | ||
public const TYPE_EMOJI = 'emoji'; | ||
public const TYPE_CUSTOM_EMOJI = 'custom_emoji'; | ||
public const TYPE_PAID_EMOJI = 'paid'; | ||
|
||
private string $type; | ||
private string $emoji; | ||
private ?string $customEmojiId = null; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param array{ | ||
* type: string, | ||
* emoji: string, | ||
* custom_emoji_id?: string | ||
* } $data | ||
*/ | ||
public static function fromArray(array $data): ReactionType | ||
{ | ||
$reaction = new self(); | ||
|
||
$reaction->type = $data['type']; | ||
$reaction->emoji = $data['emoji']; | ||
$reaction->customEmojiId = $data['custom_emoji_id'] ?? null; | ||
|
||
return $reaction; | ||
} | ||
|
||
public function type(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function emoji(): string | ||
{ | ||
return $this->emoji; | ||
} | ||
|
||
public function customEmojiId(): ?string | ||
{ | ||
return $this->customEmojiId; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'type' => $this->type, | ||
'emoji' => $this->emoji, | ||
'custom_emoji_id' => $this->customEmojiId, | ||
], fn ($value) => $value !== null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters