Added \TgBotLib\Objects > LoginUrl
This commit is contained in:
parent
4023c46d66
commit
6b82724942
1 changed files with 110 additions and 0 deletions
110
src/TgBotLib/Objects/LoginUrl.php
Normal file
110
src/TgBotLib/Objects/LoginUrl.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace TgBotLib\Objects;
|
||||
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
|
||||
class LoginUrl implements ObjectTypeInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $forward_text;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $bot_username;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $request_write_access;
|
||||
|
||||
/**
|
||||
* An HTTPS URL to be opened with user authorization data added to the query string when the button is pressed.
|
||||
* If the user refuses to provide authorization data, the original URL without information about the user will
|
||||
* be opened. The data added is the same as described in Receiving authorization data.
|
||||
*
|
||||
* @see https://core.telegram.org/widgets/login#receiving-authorization-data
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(): string
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. New text of the button in forwarded messages.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getForwardText(): ?string
|
||||
{
|
||||
return $this->forward_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Username of a bot, which will be used for user authorization. See Setting up a bot for more details.
|
||||
* If not specified, the current bot's username will be assumed. The url's domain must be the same as the domain
|
||||
* linked with the bot. See Linking your domain to the bot for more details.
|
||||
*
|
||||
* @see https://core.telegram.org/widgets/login#setting-up-a-bot
|
||||
* @see https://core.telegram.org/widgets/login#linking-your-domain-to-the-bot
|
||||
* @return string|null
|
||||
*/
|
||||
public function getBotUsername(): ?string
|
||||
{
|
||||
return $this->bot_username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Pass True to request the permission for your bot to send messages to the user.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getRequestWriteAccess(): bool
|
||||
{
|
||||
return $this->request_write_access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'url' => $this->url,
|
||||
'forward_text' => $this->forward_text,
|
||||
'bot_username' => $this->bot_username,
|
||||
'request_write_access' => $this->request_write_access
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return ObjectTypeInterface
|
||||
*/
|
||||
public static function fromArray(array $data): ObjectTypeInterface
|
||||
{
|
||||
$object = new self();
|
||||
|
||||
$object->url = $data['url'];
|
||||
$object->forward_text = $data['forward_text'] ?? null;
|
||||
$object->bot_username = $data['bot_username'] ?? null;
|
||||
$object->request_write_access = $data['request_write_access'] ?? false;
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue