tgbotlib/src/TgBotLib/Objects/WebAppData.php

60 lines
1.4 KiB
PHP
Raw Normal View History

2023-02-12 18:33:40 -05:00
<?php
2024-10-02 00:18:12 -04:00
namespace TgBotLib\Objects;
2023-02-12 18:33:40 -05:00
use TgBotLib\Interfaces\ObjectTypeInterface;
class WebAppData implements ObjectTypeInterface
{
2024-10-06 16:07:30 -04:00
private string $data;
private string $button_text;
2023-02-12 18:33:40 -05:00
/**
* The data. Be aware that a bad client can send arbitrary data in this field.
*
* @return string
*/
public function getData(): string
{
return $this->data;
}
/**
* Text of the web_app keyboard button from which the Web App was opened.
* Be aware that a bad client can send arbitrary data in this field.
*
* @return string
*/
public function getButtonText(): string
{
return $this->button_text;
}
/**
2024-10-06 16:07:30 -04:00
* @inheritDoc
2023-02-12 18:33:40 -05:00
*/
public function toArray(): array
{
return [
'data' => $this->data,
'button_text' => $this->button_text,
];
}
/**
2024-10-06 16:07:30 -04:00
* @inheritDoc
2023-02-12 18:33:40 -05:00
*/
2024-10-06 16:07:30 -04:00
public static function fromArray(?array $data): ?WebAppData
2023-02-12 18:33:40 -05:00
{
2024-10-06 16:07:30 -04:00
if($data === null)
{
return null;
}
2023-02-12 18:33:40 -05:00
2024-10-06 16:07:30 -04:00
$object = new self();
2023-02-14 17:35:16 -05:00
$object->data = $data['data'] ?: '';
$object->button_text = $data['button_text'] ?: '';
2023-02-12 18:33:40 -05:00
return $object;
}
}