@@ -14,106 +14,106 @@ |
||
| 14 | 14 | class Plugin |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The Update types |
|
| 19 | - * |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected array $update_types = [ |
|
| 23 | - 'Message', |
|
| 24 | - 'EditedMessage', |
|
| 25 | - 'ChannelPost', |
|
| 26 | - 'EditedChannelPost', |
|
| 27 | - 'InlineQuery', |
|
| 28 | - 'ChosenInlineResult', |
|
| 29 | - 'CallbackQuery', |
|
| 30 | - 'ShippingQuery', |
|
| 31 | - 'PreCheckoutQuery', |
|
| 32 | - ]; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var WebhookHandler |
|
| 36 | - */ |
|
| 37 | - protected WebhookHandler $hook; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var \Generator |
|
| 41 | - */ |
|
| 42 | - protected \Generator $returns; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var bool |
|
| 46 | - */ |
|
| 47 | - protected bool $kill_on_yield = false; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Check for the exit of the plugin. |
|
| 51 | - * |
|
| 52 | - * @param \Generator $return |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - public function __checkExit(\Generator $return): void |
|
| 56 | - { |
|
| 57 | - if ($return->valid()) { |
|
| 58 | - if ($return->current() !== null && $this->kill_on_yield === true) { |
|
| 59 | - $this->kill(); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - if ($return->valid()) { |
|
| 64 | - $return->next(); |
|
| 65 | - $this->__checkExit($return); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Identify the update type. e.g. Message, EditedMessage, etc. |
|
| 71 | - * |
|
| 72 | - * @param Update $update |
|
| 73 | - * @return string|null |
|
| 74 | - */ |
|
| 75 | - public function __identify(Update $update): ?string |
|
| 76 | - { |
|
| 77 | - $type = $update->getUpdateType(); |
|
| 78 | - |
|
| 79 | - if ($type === null) { |
|
| 80 | - return null; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return str_replace('_', '', ucwords($type, '_')); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Execute the plugin. |
|
| 88 | - * |
|
| 89 | - * @param WebhookHandler $receiver |
|
| 90 | - * @param Update $update |
|
| 91 | - * @return void |
|
| 92 | - */ |
|
| 93 | - public function __execute(WebhookHandler $receiver, Update $update): void |
|
| 94 | - { |
|
| 95 | - $this->hook = $receiver; |
|
| 96 | - |
|
| 97 | - if (method_exists($this, 'onReceivedUpdate')) { |
|
| 98 | - $return = $this->onReceivedUpdate($update); |
|
| 99 | - $this->__checkExit($return); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $type = $this->__identify($update); |
|
| 103 | - if (method_exists($this, ($method = 'on' . $type)) && $type !== null) { |
|
| 104 | - $return = $this->$method($update); |
|
| 105 | - $this->__checkExit($return); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Kill the plugin. |
|
| 111 | - * |
|
| 112 | - * @return void |
|
| 113 | - */ |
|
| 114 | - public function kill(): void |
|
| 115 | - { |
|
| 116 | - $this->hook->kill(); |
|
| 117 | - } |
|
| 17 | + /** |
|
| 18 | + * The Update types |
|
| 19 | + * |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected array $update_types = [ |
|
| 23 | + 'Message', |
|
| 24 | + 'EditedMessage', |
|
| 25 | + 'ChannelPost', |
|
| 26 | + 'EditedChannelPost', |
|
| 27 | + 'InlineQuery', |
|
| 28 | + 'ChosenInlineResult', |
|
| 29 | + 'CallbackQuery', |
|
| 30 | + 'ShippingQuery', |
|
| 31 | + 'PreCheckoutQuery', |
|
| 32 | + ]; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var WebhookHandler |
|
| 36 | + */ |
|
| 37 | + protected WebhookHandler $hook; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var \Generator |
|
| 41 | + */ |
|
| 42 | + protected \Generator $returns; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var bool |
|
| 46 | + */ |
|
| 47 | + protected bool $kill_on_yield = false; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Check for the exit of the plugin. |
|
| 51 | + * |
|
| 52 | + * @param \Generator $return |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + public function __checkExit(\Generator $return): void |
|
| 56 | + { |
|
| 57 | + if ($return->valid()) { |
|
| 58 | + if ($return->current() !== null && $this->kill_on_yield === true) { |
|
| 59 | + $this->kill(); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + if ($return->valid()) { |
|
| 64 | + $return->next(); |
|
| 65 | + $this->__checkExit($return); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Identify the update type. e.g. Message, EditedMessage, etc. |
|
| 71 | + * |
|
| 72 | + * @param Update $update |
|
| 73 | + * @return string|null |
|
| 74 | + */ |
|
| 75 | + public function __identify(Update $update): ?string |
|
| 76 | + { |
|
| 77 | + $type = $update->getUpdateType(); |
|
| 78 | + |
|
| 79 | + if ($type === null) { |
|
| 80 | + return null; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + return str_replace('_', '', ucwords($type, '_')); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Execute the plugin. |
|
| 88 | + * |
|
| 89 | + * @param WebhookHandler $receiver |
|
| 90 | + * @param Update $update |
|
| 91 | + * @return void |
|
| 92 | + */ |
|
| 93 | + public function __execute(WebhookHandler $receiver, Update $update): void |
|
| 94 | + { |
|
| 95 | + $this->hook = $receiver; |
|
| 96 | + |
|
| 97 | + if (method_exists($this, 'onReceivedUpdate')) { |
|
| 98 | + $return = $this->onReceivedUpdate($update); |
|
| 99 | + $this->__checkExit($return); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $type = $this->__identify($update); |
|
| 103 | + if (method_exists($this, ($method = 'on' . $type)) && $type !== null) { |
|
| 104 | + $return = $this->$method($update); |
|
| 105 | + $this->__checkExit($return); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Kill the plugin. |
|
| 111 | + * |
|
| 112 | + * @return void |
|
| 113 | + */ |
|
| 114 | + public function kill(): void |
|
| 115 | + { |
|
| 116 | + $this->hook->kill(); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } |
| 120 | 120 | \ No newline at end of file |
@@ -23,18 +23,18 @@ |
||
| 23 | 23 | class ChatMemberUpdated extends Entity |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * {@inheritdoc} |
|
| 28 | - */ |
|
| 29 | - protected function subEntities(): array |
|
| 30 | - { |
|
| 31 | - return [ |
|
| 32 | - 'chat' => Chat::class, |
|
| 33 | - 'from' => User::class, |
|
| 34 | - 'old_chat_member' => ChatMemberFactory::class, |
|
| 35 | - 'new_chat_member' => ChatMemberFactory::class, |
|
| 36 | - 'invite_link' => ChatInviteLink::class, |
|
| 37 | - ]; |
|
| 38 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritdoc} |
|
| 28 | + */ |
|
| 29 | + protected function subEntities(): array |
|
| 30 | + { |
|
| 31 | + return [ |
|
| 32 | + 'chat' => Chat::class, |
|
| 33 | + 'from' => User::class, |
|
| 34 | + 'old_chat_member' => ChatMemberFactory::class, |
|
| 35 | + 'new_chat_member' => ChatMemberFactory::class, |
|
| 36 | + 'invite_link' => ChatInviteLink::class, |
|
| 37 | + ]; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | } |
@@ -15,36 +15,36 @@ |
||
| 15 | 15 | class UserProfilePhotos extends Entity |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * {@inheritdoc} |
|
| 20 | - */ |
|
| 21 | - protected function subEntities(): array |
|
| 22 | - { |
|
| 23 | - return [ |
|
| 24 | - 'photos' => PhotoSize::class, |
|
| 25 | - ]; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Requested profile pictures (in up to 4 sizes each) |
|
| 30 | - * |
|
| 31 | - * This method overrides the default getPhotos method and returns a nice array |
|
| 32 | - * |
|
| 33 | - * @return PhotoSize[][] |
|
| 34 | - */ |
|
| 35 | - public function getPhotos(): array |
|
| 36 | - { |
|
| 37 | - $all_photos = []; |
|
| 38 | - |
|
| 39 | - if ($these_photos = $this->getProperty('photos')) { |
|
| 40 | - foreach ($these_photos as $photos) { |
|
| 41 | - $all_photos[] = array_map(function ($photo) { |
|
| 42 | - return new PhotoSize($photo); |
|
| 43 | - }, $photos); |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - return $all_photos; |
|
| 48 | - } |
|
| 18 | + /** |
|
| 19 | + * {@inheritdoc} |
|
| 20 | + */ |
|
| 21 | + protected function subEntities(): array |
|
| 22 | + { |
|
| 23 | + return [ |
|
| 24 | + 'photos' => PhotoSize::class, |
|
| 25 | + ]; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Requested profile pictures (in up to 4 sizes each) |
|
| 30 | + * |
|
| 31 | + * This method overrides the default getPhotos method and returns a nice array |
|
| 32 | + * |
|
| 33 | + * @return PhotoSize[][] |
|
| 34 | + */ |
|
| 35 | + public function getPhotos(): array |
|
| 36 | + { |
|
| 37 | + $all_photos = []; |
|
| 38 | + |
|
| 39 | + if ($these_photos = $this->getProperty('photos')) { |
|
| 40 | + foreach ($these_photos as $photos) { |
|
| 41 | + $all_photos[] = array_map(function ($photo) { |
|
| 42 | + return new PhotoSize($photo); |
|
| 43 | + }, $photos); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + return $all_photos; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | } |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | |
| 39 | 39 | if ($these_photos = $this->getProperty('photos')) { |
| 40 | 40 | foreach ($these_photos as $photos) { |
| 41 | - $all_photos[] = array_map(function ($photo) { |
|
| 41 | + $all_photos[] = array_map(function($photo) { |
|
| 42 | 42 | return new PhotoSize($photo); |
| 43 | 43 | }, $photos); |
| 44 | 44 | } |
@@ -14,14 +14,14 @@ |
||
| 14 | 14 | class VideoChatParticipantsInvited extends Entity |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * {@inheritdoc} |
|
| 19 | - */ |
|
| 20 | - protected function subEntities(): array |
|
| 21 | - { |
|
| 22 | - return [ |
|
| 23 | - 'users' => [User::class], |
|
| 24 | - ]; |
|
| 25 | - } |
|
| 17 | + /** |
|
| 18 | + * {@inheritdoc} |
|
| 19 | + */ |
|
| 20 | + protected function subEntities(): array |
|
| 21 | + { |
|
| 22 | + return [ |
|
| 23 | + 'users' => [User::class], |
|
| 24 | + ]; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | } |
@@ -20,14 +20,14 @@ |
||
| 20 | 20 | class VideoNote extends Entity |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * {@inheritdoc} |
|
| 25 | - */ |
|
| 26 | - protected function subEntities(): array |
|
| 27 | - { |
|
| 28 | - return [ |
|
| 29 | - 'thumb' => PhotoSize::class, |
|
| 30 | - ]; |
|
| 31 | - } |
|
| 23 | + /** |
|
| 24 | + * {@inheritdoc} |
|
| 25 | + */ |
|
| 26 | + protected function subEntities(): array |
|
| 27 | + { |
|
| 28 | + return [ |
|
| 29 | + 'thumb' => PhotoSize::class, |
|
| 30 | + ]; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | } |
@@ -21,14 +21,14 @@ |
||
| 21 | 21 | class Venue extends Entity |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * {@inheritdoc} |
|
| 26 | - */ |
|
| 27 | - protected function subEntities(): array |
|
| 28 | - { |
|
| 29 | - return [ |
|
| 30 | - 'location' => Location::class, |
|
| 31 | - ]; |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * {@inheritdoc} |
|
| 26 | + */ |
|
| 27 | + protected function subEntities(): array |
|
| 28 | + { |
|
| 29 | + return [ |
|
| 30 | + 'location' => Location::class, |
|
| 31 | + ]; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | } |
@@ -20,9 +20,9 @@ |
||
| 20 | 20 | class ChatJoinRequest extends Entity |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * {@inheritdoc} |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * {@inheritdoc} |
|
| 25 | + */ |
|
| 26 | 26 | protected function subEntities(): array |
| 27 | 27 | { |
| 28 | 28 | return [ |
@@ -23,14 +23,14 @@ |
||
| 23 | 23 | class Video extends Entity |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * {@inheritdoc} |
|
| 28 | - */ |
|
| 29 | - protected function subEntities(): array |
|
| 30 | - { |
|
| 31 | - return [ |
|
| 32 | - 'thumb' => PhotoSize::class, |
|
| 33 | - ]; |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritdoc} |
|
| 28 | + */ |
|
| 29 | + protected function subEntities(): array |
|
| 30 | + { |
|
| 31 | + return [ |
|
| 32 | + 'thumb' => PhotoSize::class, |
|
| 33 | + ]; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | } |
@@ -17,14 +17,14 @@ |
||
| 17 | 17 | class ChatLocation extends Entity |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * {@inheritdoc} |
|
| 22 | - */ |
|
| 23 | - protected function subEntities(): array |
|
| 24 | - { |
|
| 25 | - return [ |
|
| 26 | - 'location' => Location::class, |
|
| 27 | - ]; |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * {@inheritdoc} |
|
| 22 | + */ |
|
| 23 | + protected function subEntities(): array |
|
| 24 | + { |
|
| 25 | + return [ |
|
| 26 | + 'location' => Location::class, |
|
| 27 | + ]; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | } |