99
1010namespace Longman \TelegramBot \Entities ;
1111
12+ use Longman \TelegramBot \Entities \ChatMember \ChatMember ;
13+ use Longman \TelegramBot \Entities \ChatMember \Factory as ChatMemberFactory ;
1214use Longman \TelegramBot \Entities \Games \GameHighScore ;
1315use Longman \TelegramBot \Request ;
1416
@@ -104,7 +106,7 @@ public function printError($return = false)
104106 * @param array $result
105107 * @param string $bot_username
106108 *
107- * @return Chat|ChatMember|File|Message|User|UserProfilePhotos|WebhookInfo
109+ * @return Chat|ChatMember|File|Message|User|UserProfilePhotos|WebhookInfo|Entity
108110 */
109111 private function createResultObject (array $ result , string $ bot_username )
110112 {
@@ -115,7 +117,7 @@ private function createResultObject(array $result, string $bot_username)
115117
116118 $ result_object_types = [
117119 'getChat ' => Chat::class,
118- 'getChatMember ' => ChatMember ::class,
120+ 'getChatMember ' => ChatMemberFactory ::class,
119121 'getFile ' => File::class,
120122 'getMe ' => User::class,
121123 'getStickerSet ' => StickerSet::class,
@@ -125,7 +127,7 @@ private function createResultObject(array $result, string $bot_username)
125127
126128 $ object_class = array_key_exists ($ action , $ result_object_types ) ? $ result_object_types [$ action ] : Message::class;
127129
128- return new $ object_class( $ result , $ bot_username );
130+ return Factory:: resolveEntityClass ( $ object_class, $ result , $ bot_username );
129131 }
130132
131133 /**
@@ -143,7 +145,7 @@ private function createResultObjects(array $result, string $bot_username): array
143145
144146 $ result_object_types = [
145147 'getMyCommands ' => BotCommand::class,
146- 'getChatAdministrators ' => ChatMember ::class,
148+ 'getChatAdministrators ' => ChatMemberFactory ::class,
147149 'getGameHighScores ' => GameHighScore::class,
148150 'sendMediaGroup ' => Message::class,
149151 ];
@@ -154,7 +156,7 @@ private function createResultObjects(array $result, string $bot_username): array
154156 // We don't need to save the raw_data of the response object!
155157 $ data ['raw_data ' ] = null ;
156158
157- $ results [] = new $ object_class( $ data , $ bot_username );
159+ $ results [] = Factory:: resolveEntityClass ( $ object_class, $ data , $ bot_username );
158160 }
159161
160162 return $ results ;
0 commit comments