tgbotlib/src/TgBotLib/Objects/WebAppInfo.php

69 lines
1.6 KiB
PHP
Raw Normal View History

2023-02-12 22:40:33 -05:00
<?php
2024-10-02 00:18:12 -04:00
namespace TgBotLib\Objects;
2023-02-12 22:40:33 -05:00
use InvalidArgumentException;
use TgBotLib\Classes\Validate;
2023-02-12 22:40:33 -05:00
use TgBotLib\Interfaces\ObjectTypeInterface;
class WebAppInfo implements ObjectTypeInterface
{
/**
* @var string
*/
2024-10-06 16:07:59 -04:00
private string $url;
2023-02-12 22:40:33 -05:00
/**
* An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps
*
* @see https://core.telegram.org/bots/webapps#initializing-web-apps
* @return string
*/
public function getUrl(): string
{
return $this->url;
}
/**
* An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps
*
* @param string $url
* @return $this
*/
public function setUrl(string $url): self
{
if(!Validate::url($url))
2024-10-06 16:07:59 -04:00
{
throw new InvalidArgumentException('Invalid url format');
2024-10-06 16:07:59 -04:00
}
$this->url = $url;
return $this;
}
2023-02-12 22:40:33 -05:00
/**
2024-10-06 16:07:59 -04:00
* @inheritDoc
2023-02-12 22:40:33 -05:00
*/
public function toArray(): array
{
return [
'url' => $this->url,
];
}
/**
2024-10-06 16:07:59 -04:00
* @inheritDoc
2023-02-12 22:40:33 -05:00
*/
2024-10-06 16:07:59 -04:00
public static function fromArray(?array $data): ?WebAppInfo
2023-02-12 22:40:33 -05:00
{
2024-10-06 16:07:59 -04:00
if($data === null)
{
return null;
}
2023-02-12 22:40:33 -05:00
$object = new self();
$object->url = $data['url'];
2024-10-06 16:07:59 -04:00
2023-02-12 22:40:33 -05:00
return $object;
}
}