mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-17 08:52:41 +00:00
71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace BushlanovDev\MaxMessengerBot;
|
|
|
|
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
|
|
use BushlanovDev\MaxMessengerBot\Models\Result;
|
|
use BushlanovDev\MaxMessengerBot\Models\Subscription;
|
|
use ReflectionException;
|
|
|
|
/**
|
|
* Creates DTOs from raw associative arrays returned by the API client.
|
|
*/
|
|
class ModelFactory
|
|
{
|
|
/**
|
|
* Simple response to request.
|
|
*
|
|
* @param array<string, mixed> $data
|
|
*
|
|
* @return Result
|
|
* @throws ReflectionException
|
|
*/
|
|
public function createResult(array $data): Result
|
|
{
|
|
return Result::fromArray($data);
|
|
}
|
|
|
|
/**
|
|
* Information about the current bot.
|
|
*
|
|
* @param array<string, mixed> $data
|
|
*
|
|
* @return BotInfo
|
|
* @throws ReflectionException
|
|
*/
|
|
public function createBotInfo(array $data): BotInfo
|
|
{
|
|
return BotInfo::fromArray($data);
|
|
}
|
|
|
|
/**
|
|
* Information about webhook subscription.
|
|
*
|
|
* @param array<string, mixed> $data
|
|
*
|
|
* @return Subscription
|
|
* @throws ReflectionException
|
|
*/
|
|
public function createSubscription(array $data): Subscription
|
|
{
|
|
return Subscription::fromArray($data);
|
|
}
|
|
|
|
/**
|
|
* List of all active webhook subscriptions.
|
|
*
|
|
* @param array<string, mixed> $data
|
|
*
|
|
* @return Subscription[]
|
|
* @throws ReflectionException
|
|
*/
|
|
public function createSubscriptions(array $data): array
|
|
{
|
|
return isset($data['subscriptions']) && is_array($data['subscriptions'])
|
|
? array_map([$this, 'createSubscription'], $data['subscriptions'])
|
|
: [];
|
|
}
|
|
}
|