tgbotlib/src/TgBotLib/Objects/Telegram/WebAppInfo.php

66 lines
1.6 KiB
PHP
Raw Normal View History

2023-02-12 22:40:33 -05:00
<?php
2023-02-14 17:41:38 -05:00
namespace TgBotLib\Objects\Telegram;
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
*/
private $url;
/**
* 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))
throw new InvalidArgumentException('Invalid url format');
$this->url = $url;
return $this;
}
2023-02-12 22:40:33 -05:00
/**
* Returns an array representation of the object.
*
* @return array
*/
public function toArray(): array
{
return [
'url' => $this->url,
];
}
/**
* Constructs the object from an array representation.
*
* @param array $data
2023-02-16 15:27:57 -05:00
* @return WebAppInfo
2023-02-12 22:40:33 -05:00
*/
2023-02-16 15:27:57 -05:00
public static function fromArray(array $data): self
2023-02-12 22:40:33 -05:00
{
$object = new self();
$object->url = $data['url'];
return $object;
}
}