Skip to content

Commit

Permalink
Other Changes pt. 2: Added Factory and NotImplemented class
Browse files Browse the repository at this point in the history
  • Loading branch information
TiiFuchs committed May 13, 2024
1 parent 1d9286f commit 5de1935
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Entities/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Longman\TelegramBot\Entities;

use Longman\TelegramBot\Entities\Games\Game;
use Longman\TelegramBot\Entities\MessageOrigin\Factory as MessageOriginFactory;
use Longman\TelegramBot\Entities\MessageOrigin\MessageOrigin;
use Longman\TelegramBot\Entities\Payments\Invoice;
use Longman\TelegramBot\Entities\Payments\SuccessfulPayment;
Expand Down Expand Up @@ -111,8 +112,7 @@ protected function subEntities(): array
'from' => User::class,
'sender_chat' => Chat::class,
'chat' => Chat::class,
'forward_from' => User::class,
'forward_from_chat' => Chat::class,
'forward_origin' => MessageOriginFactory::class,
'reply_to_message' => ReplyToMessage::class,
'external_reply' => ExternalReplyInfo::class,
'quote' => TextQuote::class,
Expand Down
26 changes: 26 additions & 0 deletions src/Entities/MessageOrigin/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Longman\TelegramBot\Entities\MessageOrigin;

use Longman\TelegramBot\Entities\Entity;

class Factory extends \Longman\TelegramBot\Entities\Factory
{
public static function make(array $data, string $bot_username): Entity
{
$type = [
'user' => MessageOriginUser::class,
'hidden_user' => MessageOriginHiddenUser::class,
'chat' => MessageOriginChat::class,
'channel' => MessageOriginChannel::class,
];

if (!isset($type[$data['type'] ?? ''])) {
return new MessageOriginNotImplemented($data, $bot_username);
}

$class = $type[$data['type']];
return new $class($data, $bot_username);
}

}
2 changes: 0 additions & 2 deletions src/Entities/MessageOrigin/MessageOrigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Longman\TelegramBot\Entities\MessageOrigin;

use Longman\TelegramBot\Entities\Entity;

/**
* This object describes the origin of a message.
*
Expand Down
14 changes: 14 additions & 0 deletions src/Entities/MessageOrigin/MessageOriginNotImplemented.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Longman\TelegramBot\Entities\MessageOrigin;

use Longman\TelegramBot\Entities\Entity;

/**
* @method string getType() Type of the message origin
* @method int getDate() Date the message was sent originally in Unix time
*/
class MessageOriginNotImplemented extends Entity implements MessageOrigin
{

}

0 comments on commit 5de1935

Please sign in to comment.