Skip to content

Commit 265fe50

Browse files
committed
Merge branch develop into 1049_bot_api_4.6
2 parents 239a998 + 229d884 commit 265fe50

File tree

6 files changed

+46
-64
lines changed

6 files changed

+46
-64
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
1313
- Bot API 4.6 (Polls 2.0).
1414
### Changed
1515
- Save notes an unescaped JSON, to allow easy DB reading and editing of values. (#1005)
16+
- `Request::setClient()` now accepts more flexible `ClientInterface`. (#1068)
1617
### Deprecated
1718
### Removed
19+
- Unnecessary `instanceof` checks for entities. (#1068)
20+
- Unused `Request::$input` variable. (#1068)
1821
### Fixed
1922
- Execution of `/start` command without any custom implementation.
2023
- Return `animation` type for GIF Message (which returns both `animation` and `document`). (#1044)
2124
- Change lowercase function to `mb_strtolower` from `strtolower` because of `latin-extented` characters. (#1051)
2225
- Extend `Request::mediaInputHelper()` to include `thumb` parameter.
26+
- Various docblock annotations. (#1068)
2327
### Security
2428

2529
## [0.61.1] - 2019-11-23

src/DB.php

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Longman\TelegramBot\Entities\Payments\ShippingQuery;
2222
use Longman\TelegramBot\Entities\Poll;
2323
use Longman\TelegramBot\Entities\PollAnswer;
24-
use Longman\TelegramBot\Entities\ReplyToMessage;
2524
use Longman\TelegramBot\Entities\Update;
2625
use Longman\TelegramBot\Entities\User;
2726
use Longman\TelegramBot\Exception\TelegramException;
@@ -423,7 +422,7 @@ public static function insertUser(User $user, $date = null, Chat $chat = null)
423422
}
424423

425424
// Also insert the relationship to the chat into the user_chat table
426-
if ($chat instanceof Chat) {
425+
if ($chat) {
427426
try {
428427
$sth = self::$pdo->prepare('
429428
INSERT IGNORE INTO `' . TB_USER_CHAT . '`
@@ -606,8 +605,7 @@ public static function insertInlineQueryRequest(InlineQuery $inline_query)
606605
$date = self::getTimestamp();
607606
$user_id = null;
608607

609-
$user = $inline_query->getFrom();
610-
if ($user instanceof User) {
608+
if ($user = $inline_query->getFrom()) {
611609
$user_id = $user->getId();
612610
self::insertUser($user, $date);
613611
}
@@ -650,8 +648,7 @@ public static function insertChosenInlineResultRequest(ChosenInlineResult $chose
650648
$date = self::getTimestamp();
651649
$user_id = null;
652650

653-
$user = $chosen_inline_result->getFrom();
654-
if ($user instanceof User) {
651+
if ($user = $chosen_inline_result->getFrom()) {
655652
$user_id = $user->getId();
656653
self::insertUser($user, $date);
657654
}
@@ -694,16 +691,14 @@ public static function insertCallbackQueryRequest(CallbackQuery $callback_query)
694691
$date = self::getTimestamp();
695692
$user_id = null;
696693

697-
$user = $callback_query->getFrom();
698-
if ($user instanceof User) {
694+
if ($user = $callback_query->getFrom()) {
699695
$user_id = $user->getId();
700696
self::insertUser($user, $date);
701697
}
702698

703-
$message = $callback_query->getMessage();
704699
$chat_id = null;
705700
$message_id = null;
706-
if ($message instanceof Message) {
701+
if ($message = $callback_query->getMessage()) {
707702
$chat_id = $message->getChat()->getId();
708703
$message_id = $message->getMessageId();
709704

@@ -763,8 +758,7 @@ public static function insertShippingQueryRequest(ShippingQuery $shipping_query)
763758
$date = self::getTimestamp();
764759
$user_id = null;
765760

766-
$user = $shipping_query->getFrom();
767-
if ($user instanceof User) {
761+
if ($user = $shipping_query->getFrom()) {
768762
$user_id = $user->getId();
769763
self::insertUser($user, $date);
770764
}
@@ -806,8 +800,7 @@ public static function insertPreCheckoutQueryRequest(PreCheckoutQuery $pre_check
806800
$date = self::getTimestamp();
807801
$user_id = null;
808802

809-
$user = $pre_checkout_query->getFrom();
810-
if ($user instanceof User) {
803+
if ($user = $pre_checkout_query->getFrom()) {
811804
$user_id = $user->getId();
812805
self::insertUser($user, $date);
813806
}
@@ -901,8 +894,7 @@ public static function insertPollAnswerRequest(PollAnswer $poll_answer)
901894
$date = self::getTimestamp();
902895
$user_id = null;
903896

904-
$user = $poll_answer->getUser();
905-
if ($user instanceof User) {
897+
if ($user = $poll_answer->getUser()) {
906898
$user_id = $user->getId();
907899
self::insertUser($user, $date);
908900
}
@@ -939,21 +931,18 @@ public static function insertMessageRequest(Message $message)
939931
self::insertChat($chat, $date, $message->getMigrateToChatId());
940932

941933
// Insert user and the relation with the chat
942-
$user = $message->getFrom();
943-
if ($user instanceof User) {
934+
if ($user = $message->getFrom()) {
944935
self::insertUser($user, $date, $chat);
945936
}
946937

947938
// Insert the forwarded message user in users table
948939
$forward_date = $message->getForwardDate() ? self::getTimestamp($message->getForwardDate()) : null;
949940

950-
$forward_from = $message->getForwardFrom();
951-
if ($forward_from instanceof User) {
941+
if ($forward_from = $message->getForwardFrom()) {
952942
self::insertUser($forward_from);
953943
$forward_from = $forward_from->getId();
954944
}
955-
$forward_from_chat = $message->getForwardFromChat();
956-
if ($forward_from_chat instanceof Chat) {
945+
if ($forward_from_chat = $message->getForwardFromChat()) {
957946
self::insertChat($forward_from_chat);
958947
$forward_from_chat = $forward_from_chat->getId();
959948
}
@@ -973,7 +962,7 @@ public static function insertMessageRequest(Message $message)
973962
}
974963
}
975964
$new_chat_members_ids = implode(',', $new_chat_members_ids);
976-
} elseif ($left_chat_member instanceof User) {
965+
} elseif ($left_chat_member) {
977966
// Insert the left chat user
978967
self::insertUser($left_chat_member, $date, $chat);
979968
$left_chat_member_id = $left_chat_member->getId();
@@ -1003,15 +992,11 @@ public static function insertMessageRequest(Message $message)
1003992
)
1004993
');
1005994

1006-
$user_id = null;
1007-
if ($user instanceof User) {
1008-
$user_id = $user->getId();
1009-
}
995+
$user_id = $user ? $user->getId() : null;
1010996
$chat_id = $chat->getId();
1011997

1012-
$reply_to_message = $message->getReplyToMessage();
1013998
$reply_to_message_id = null;
1014-
if ($reply_to_message instanceof ReplyToMessage) {
999+
if ($reply_to_message = $message->getReplyToMessage()) {
10151000
$reply_to_message_id = $reply_to_message->getMessageId();
10161001
// please notice that, as explained in the documentation, reply_to_message don't contain other
10171002
// reply_to_message field so recursion deep is 1
@@ -1101,8 +1086,7 @@ public static function insertEditedMessageRequest(Message $edited_message)
11011086
self::insertChat($chat, $edit_date);
11021087

11031088
// Insert user and the relation with the chat
1104-
$user = $edited_message->getFrom();
1105-
if ($user instanceof User) {
1089+
if ($user = $edited_message->getFrom()) {
11061090
self::insertUser($user, $edit_date, $chat);
11071091
}
11081092

@@ -1113,10 +1097,7 @@ public static function insertEditedMessageRequest(Message $edited_message)
11131097
(:chat_id, :message_id, :user_id, :edit_date, :text, :entities, :caption)
11141098
');
11151099

1116-
$user_id = null;
1117-
if ($user instanceof User) {
1118-
$user_id = $user->getId();
1119-
}
1100+
$user_id = $user ? $user->getId() : null;
11201101

11211102
$sth->bindValue(':chat_id', $chat->getId());
11221103
$sth->bindValue(':message_id', $edited_message->getMessageId());

src/Entities/Chat.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* @method string getUsername() Optional. Username, for private chats, supergroups and channels if available
2525
* @method string getFirstName() Optional. First name of the other party in a private chat
2626
* @method string getLastName() Optional. Last name of the other party in a private chat
27-
* @method bool getAllMembersAreAdministrators() Optional. True if a group has ‘All Members Are Admins’ enabled. {@deprecated} {@see Chat::getPermissions()}
2827
* @method ChatPhoto getPhoto() Optional. Chat photo. Returned only in getChat.
2928
* @method string getDescription() Optional. Description, for groups, supergroups and channel chats. Returned only in getChat.
3029
* @method string getInviteLink() Optional. Chat invite link, for groups, supergroups and channel chats. Each administrator in a chat generates their own invite links, so the bot must first generate the link using exportChatInviteLink. Returned only in getChat.
@@ -115,4 +114,17 @@ public function isChannel()
115114
{
116115
return $this->getType() === 'channel';
117116
}
117+
118+
/**
119+
* Optional. True if a group has 'All Members Are Admins' enabled.
120+
*
121+
* @deprecated
122+
* @see Chat::getPermissions()
123+
*
124+
* @return bool
125+
*/
126+
public function getAllMembersAreAdministrators()
127+
{
128+
return $this->getProperty('all_members_are_administrators');
129+
}
118130
}

src/Entities/KeyboardButton.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
*
2121
* @link https://core.telegram.org/bots/api#keyboardbutton
2222
*
23+
* @property bool $request_contact
24+
* @property bool $request_location
25+
* @property KeyboardButtonPollType $request_poll
26+
*
2327
* @method string getText() Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
2428
* @method bool getRequestContact() Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
2529
* @method bool getRequestLocation() Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only

src/Entities/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @method string getForwardSignature() Optional. For messages forwarded from channels, signature of the post author if present
3232
* @method string getForwardSenderName() Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages
3333
* @method int getForwardDate() Optional. For forwarded messages, date the original message was sent in Unix time
34-
* @method Message getReplyToMessage() Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
34+
* @method ReplyToMessage getReplyToMessage() Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
3535
* @method int getEditDate() Optional. Date the message was last edited in Unix time
3636
* @method string getMediaGroupId() Optional. The unique identifier of a media message group this message belongs to
3737
* @method string getAuthorSignature() Optional. Signature of the post author for messages in channels

src/Request.php

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Longman\TelegramBot;
1313

1414
use GuzzleHttp\Client;
15+
use GuzzleHttp\ClientInterface;
1516
use GuzzleHttp\Exception\RequestException;
1617
use GuzzleHttp\Psr7\Stream;
1718
use Longman\TelegramBot\Entities\File;
@@ -109,17 +110,10 @@ class Request
109110
/**
110111
* Guzzle Client object
111112
*
112-
* @var Client
113+
* @var ClientInterface
113114
*/
114115
private static $client;
115116

116-
/**
117-
* Input value of the request
118-
*
119-
* @var string
120-
*/
121-
private static $input;
122-
123117
/**
124118
* Request limiter
125119
*
@@ -260,32 +254,20 @@ class Request
260254
* Initialize
261255
*
262256
* @param Telegram $telegram
263-
*
264-
* @throws TelegramException
265257
*/
266258
public static function initialize(Telegram $telegram)
267259
{
268-
if (!($telegram instanceof Telegram)) {
269-
throw new TelegramException('Invalid Telegram pointer!');
270-
}
271-
272260
self::$telegram = $telegram;
273261
self::setClient(self::$client ?: new Client(['base_uri' => self::$api_base_uri]));
274262
}
275263

276264
/**
277265
* Set a custom Guzzle HTTP Client object
278266
*
279-
* @param Client $client
280-
*
281-
* @throws TelegramException
267+
* @param ClientInterface $client
282268
*/
283-
public static function setClient(Client $client)
269+
public static function setClient(ClientInterface $client)
284270
{
285-
if (!($client instanceof Client)) {
286-
throw new TelegramException('Invalid GuzzleHttp\Client pointer!');
287-
}
288-
289271
self::$client = $client;
290272
}
291273

@@ -298,7 +280,8 @@ public static function setClient(Client $client)
298280
public static function getInput()
299281
{
300282
// First check if a custom input has been set, else get the PHP input.
301-
if (!($input = self::$telegram->getCustomInput())) {
283+
$input = self::$telegram->getCustomInput();
284+
if (empty($input)) {
302285
$input = file_get_contents('php://input');
303286
}
304287

@@ -307,11 +290,9 @@ public static function getInput()
307290
throw new TelegramException('Input must be a string!');
308291
}
309292

310-
self::$input = $input;
311-
312-
TelegramLog::update(self::$input);
293+
TelegramLog::update($input);
313294

314-
return self::$input;
295+
return $input;
315296
}
316297

317298
/**

0 commit comments

Comments
 (0)