Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ResultFactory and value processors, simplify type and method classes #99

Merged
merged 13 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Telegram Bot API for PHP Change Log

## 0.2.2 under development
## 0.3.0 under development

- New #97: Add `getRaw()` and `hasRaw()` methods to `Update` type class.
- Chg #99: Add `ResultFactory` and value processors, simplify type and method classes.

## 0.2.1 July 2, 2024

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ $request = new TelegramRequest(
httpMethod: HttpMethod::GET,
apiMethod: 'getChat',
data: ['chat_id' => '@sergei_predvoditelev'],
successCallback: fn (mixed $result) => ChatFullInfo::fromTelegramResult($result),
resultType: ChatFullInfo::class,
);

// Result is an object of `Vjik\TelegramBot\Api\Type\ChatFullInfo`
Expand Down
7 changes: 3 additions & 4 deletions src/Method/AnswerCallbackQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -46,9 +46,8 @@ public function getData(): array
);
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/ApproveChatJoinRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -37,9 +37,8 @@ public function getData(): array
];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/BanChatMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Vjik\TelegramBot\Api\Method;

use DateTimeInterface;
use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -45,9 +45,8 @@ public function getData(): array
);
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/BanChatSenderChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -37,9 +37,8 @@ public function getData(): array
];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/Close.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand All @@ -28,9 +28,8 @@ public function getData(): array
return [];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/CloseForumTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -37,9 +37,8 @@ public function getData(): array
];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/CloseGeneralForumTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -35,9 +35,8 @@ public function getData(): array
];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
4 changes: 2 additions & 2 deletions src/Method/CopyMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function getData(): array
);
}

public function prepareResult(mixed $result): MessageId
public function getResultType(): string
{
return MessageId::fromTelegramResult($result);
return MessageId::class;
}
}
13 changes: 3 additions & 10 deletions src/Method/CopyMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\ArrayOfObjectsValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\MessageId;
Expand Down Expand Up @@ -54,15 +54,8 @@ public function getData(): array
);
}

/**
* @return MessageId[]
*/
public function prepareResult(mixed $result): array
public function getResultType(): ArrayOfObjectsValue
{
ValueHelper::assertArrayResult($result);
return array_map(
static fn($item) => MessageId::fromTelegramResult($item),
$result
);
return new ArrayOfObjectsValue(MessageId::class);
}
}
4 changes: 2 additions & 2 deletions src/Method/CreateChatInviteLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function getData(): array
);
}

public function prepareResult(mixed $result): ChatInviteLink
public function getResultType(): string
{
return ChatInviteLink::fromTelegramResult($result);
return ChatInviteLink::class;
}
}
4 changes: 2 additions & 2 deletions src/Method/CreateForumTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function getData(): array
);
}

public function prepareResult(mixed $result): ForumTopic
public function getResultType(): string
{
return ForumTopic::fromTelegramResult($result);
return ForumTopic::class;
}
}
7 changes: 3 additions & 4 deletions src/Method/DeclineChatJoinRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -37,9 +37,8 @@ public function getData(): array
];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/DeleteChatPhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -35,9 +35,8 @@ public function getData(): array
];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/DeleteChatStickerSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -35,9 +35,8 @@ public function getData(): array
];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/DeleteForumTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -37,9 +37,8 @@ public function getData(): array
];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/DeleteMyCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;
use Vjik\TelegramBot\Api\Type\BotCommandScope;
Expand Down Expand Up @@ -41,9 +41,8 @@ public function getData(): array
);
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
4 changes: 2 additions & 2 deletions src/Method/EditChatInviteLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function getData(): array
);
}

public function prepareResult(mixed $result): ChatInviteLink
public function getResultType(): string
{
return ChatInviteLink::fromTelegramResult($result);
return ChatInviteLink::class;
}
}
7 changes: 3 additions & 4 deletions src/Method/EditForumTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -44,9 +44,8 @@ public function getData(): array
);
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
7 changes: 3 additions & 4 deletions src/Method/EditGeneralForumTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Vjik\TelegramBot\Api\Method;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\ParseResult\ValueProcessor\TrueValue;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

Expand Down Expand Up @@ -37,9 +37,8 @@ public function getData(): array
];
}

public function prepareResult(mixed $result): true
public function getResultType(): TrueValue
{
ValueHelper::assertTrueResult($result);
return $result;
return new TrueValue();
}
}
Loading
Loading