Skip to content

Commit

Permalink
Added factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
TiiFuchs committed May 10, 2022
1 parent 4b994bf commit a731fc6
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Telegram/BotCommandScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@ abstract class BotCommandScope extends \Tii\Telepath\Type
{
/** Scope type */
public string $type;


public static function factory(array $data): static
{
return match($data['type']) {
'default' => new BotCommandScopeDefault($data)
'all_private_chats' => new BotCommandScopeAllPrivateChats($data)
'all_group_chats' => new BotCommandScopeAllGroupChats($data)
'all_chat_administrators' => new BotCommandScopeAllChatAdministrators($data)
'chat' => new BotCommandScopeChat($data)
'chat_administrators' => new BotCommandScopeChatAdministrators($data)
'chat_member' => new BotCommandScopeChatMember($data)
};
}
}
13 changes: 13 additions & 0 deletions src/Telegram/ChatMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@ abstract class ChatMember extends \Tii\Telepath\Type

/** Information about the user */
public User $user;


public static function factory(array $data): static
{
return match($data['status']) {
'creator' => new ChatMemberOwner($data)
'administrator' => new ChatMemberAdministrator($data)
'member' => new ChatMemberMember($data)
'restricted' => new ChatMemberRestricted($data)
'left' => new ChatMemberLeft($data)
'kicked' => new ChatMemberBanned($data)
};
}
}
20 changes: 20 additions & 0 deletions src/Telegram/InlineQueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,24 @@ abstract class InlineQueryResult extends \Tii\Telepath\Type

/** Optional. Inline keyboard attached to the message */
public ?InlineKeyboardMarkup $reply_markup = null;


public static function factory(array $data): static
{
return match($data['type']) {
'audio' => new InlineQueryResultAudio($data)
'document' => new InlineQueryResultDocument($data)
'gif' => new InlineQueryResultGif($data)
'mpeg4_gif' => new InlineQueryResultMpeg4Gif($data)
'photo' => new InlineQueryResultPhoto($data)
'sticker' => new InlineQueryResultCachedSticker($data)
'video' => new InlineQueryResultVideo($data)
'voice' => new InlineQueryResultVoice($data)
'article' => new InlineQueryResultArticle($data)
'contact' => new InlineQueryResultContact($data)
'game' => new InlineQueryResultGame($data)
'location' => new InlineQueryResultLocation($data)
'venue' => new InlineQueryResultVenue($data)
};
}
}
12 changes: 12 additions & 0 deletions src/Telegram/InputMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ abstract class InputMedia extends \Tii\Telepath\Type
* @var MessageEntity[]
*/
public ?array $caption_entities = null;


public static function factory(array $data): static
{
return match($data['type']) {
'animation' => new InputMediaAnimation($data)
'document' => new InputMediaDocument($data)
'audio' => new InputMediaAudio($data)
'photo' => new InputMediaPhoto($data)
'video' => new InputMediaVideo($data)
};
}
}
6 changes: 6 additions & 0 deletions src/Telegram/InputMessageContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@
*/
abstract class InputMessageContent extends \Tii\Telepath\Type
{
public static function factory(array $data): static
{
return match($data[null]) {
'' => new InputInvoiceMessageContent($data)
};
}
}
10 changes: 10 additions & 0 deletions src/Telegram/MenuButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ abstract class MenuButton extends \Tii\Telepath\Type
{
/** Type of the button */
public string $type;


public static function factory(array $data): static
{
return match($data['type']) {
'commands' => new MenuButtonCommands($data)
'web_app' => new MenuButtonWebApp($data)
'default' => new MenuButtonDefault($data)
};
}
}
16 changes: 16 additions & 0 deletions src/Telegram/PassportElementError.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,20 @@ abstract class PassportElementError extends \Tii\Telepath\Type

/** Error message */
public string $message;


public static function factory(array $data): static
{
return match($data['source']) {
'data' => new PassportElementErrorDataField($data)
'front_side' => new PassportElementErrorFrontSide($data)
'reverse_side' => new PassportElementErrorReverseSide($data)
'selfie' => new PassportElementErrorSelfie($data)
'file' => new PassportElementErrorFile($data)
'files' => new PassportElementErrorFiles($data)
'translation_file' => new PassportElementErrorTranslationFile($data)
'translation_files' => new PassportElementErrorTranslationFiles($data)
'unspecified' => new PassportElementErrorUnspecified($data)
};
}
}
Binary file modified telepathy
Binary file not shown.

0 comments on commit a731fc6

Please sign in to comment.