tgbotlib/src/TgBotLib/Objects/LinkPreviewOptions.php

179 lines
4.4 KiB
PHP
Raw Normal View History

2024-09-30 13:13:07 -04:00
<?php
2024-10-02 00:18:12 -04:00
namespace TgBotLib\Objects;
2024-09-30 13:13:07 -04:00
use TgBotLib\Interfaces\ObjectTypeInterface;
class LinkPreviewOptions implements ObjectTypeInterface
{
private bool $is_disabled;
private ?string $url;
private bool $prefer_small_media;
private bool $prefer_large_media;
private bool $show_above_text;
/**
* LinkPreviewOptions constructor.
*/
public function __construct()
{
$this->is_disabled = false;
$this->url = null;
$this->prefer_small_media = false;
$this->prefer_large_media = false;
$this->show_above_text = false;
}
2024-09-30 13:13:07 -04:00
/**
* Optional. True, if the link preview is disabled
*
* @return bool
*/
2024-10-07 13:03:47 -04:00
public function isDisabled(): bool
2024-09-30 13:13:07 -04:00
{
return $this->is_disabled;
}
2024-10-07 13:03:47 -04:00
/**
* Sets the value of is_disabled
*
* @param bool $is_disabled
* @return LinkPreviewOptions
2024-10-07 13:03:47 -04:00
*/
public function setDisabled(bool $is_disabled): LinkPreviewOptions
2024-10-07 13:03:47 -04:00
{
$this->is_disabled = $is_disabled;
return $this;
2024-10-07 13:03:47 -04:00
}
2024-09-30 13:13:07 -04:00
/**
* Optional. URL to use for the link preview. If empty, then the first URL found in the message text will be used
*
* @return string|null
*/
public function getUrl(): ?string
{
return $this->url;
}
2024-10-07 13:03:47 -04:00
/**
* Sets the value of url
*
* @param string|null $url
* @return LinkPreviewOptions
2024-10-07 13:03:47 -04:00
*/
public function setUrl(?string $url): LinkPreviewOptions
2024-10-07 13:03:47 -04:00
{
$this->url = $url;
return $this;
2024-10-07 13:03:47 -04:00
}
2024-09-30 13:13:07 -04:00
/**
* Optional. True, if the media in the link preview is supposed to be shrunk; ignored if the URL isn't
* explicitly specified or media size change isn't supported for the preview
*
* @return bool
*/
public function getPreferSmallMedia(): bool
{
return $this->prefer_small_media;
}
2024-10-07 13:03:47 -04:00
/**
* Sets the value of prefer_small_media
*
* @param bool $prefer_small_media
* @return LinkPreviewOptions
2024-10-07 13:03:47 -04:00
*/
public function setPreferSmallMedia(bool $prefer_small_media): LinkPreviewOptions
2024-10-07 13:03:47 -04:00
{
$this->prefer_small_media = $prefer_small_media;
return $this;
2024-10-07 13:03:47 -04:00
}
2024-09-30 13:13:07 -04:00
/**
* Optional. True, if the media in the link preview is supposed to be enlarged;
* ignored if the URL isn't explicitly specified or media size change isn't supported for the preview
*
* @return bool
*/
public function getPreferLargeMedia(): bool
{
return $this->prefer_large_media;
}
2024-10-07 13:03:47 -04:00
/**
* Sets the value of prefer_large_media
*
* @param bool $prefer_large_media
* @return LinkPreviewOptions
2024-10-07 13:03:47 -04:00
*/
public function setPreferLargeMedia(bool $prefer_large_media): LinkPreviewOptions
2024-10-07 13:03:47 -04:00
{
$this->prefer_large_media = $prefer_large_media;
return $this;
2024-10-07 13:03:47 -04:00
}
2024-09-30 13:13:07 -04:00
/**
* Optional. True, if the link preview must be shown above the message text; otherwise,
* the link preview will be shown below the message text
*
* @return bool
*/
public function getShowAboveText(): bool
{
return $this->show_above_text;
}
2024-10-07 13:03:47 -04:00
/**
* Sets the value of show_above_text
*
* @param bool $show_above_text
* @return LinkPreviewOptions
2024-10-07 13:03:47 -04:00
*/
public function setShowAboveText(bool $show_above_text): LinkPreviewOptions
2024-10-07 13:03:47 -04:00
{
$this->show_above_text = $show_above_text;
return $this;
2024-10-07 13:03:47 -04:00
}
2024-09-30 13:13:07 -04:00
/**
* @inheritDoc
*/
public function toArray(): array
{
$array = [
2024-09-30 13:13:07 -04:00
'is_disabled' => $this->is_disabled,
'prefer_small_media' => $this->prefer_small_media,
'prefer_large_media' => $this->prefer_large_media,
'show_above_text' => $this->show_above_text,
];
if($this->url !== null)
{
$array['url'] = $this->url;
}
return $array;
2024-09-30 13:13:07 -04:00
}
/**
* @inheritDoc
*/
2024-10-05 00:28:45 -04:00
public static function fromArray(?array $data): ?LinkPreviewOptions
2024-09-30 13:13:07 -04:00
{
2024-10-05 00:28:45 -04:00
if($data === null)
{
return null;
}
2024-09-30 13:13:07 -04:00
2024-10-05 00:28:45 -04:00
$object = new self();
2024-09-30 13:13:07 -04:00
$object->is_disabled = $data['is_disabled'] ?? false;
$object->url = $data['url'] ?? null;
$object->prefer_small_media = $data['prefer_small_media'] ?? false;
$object->prefer_large_media = $data['prefer_large_media'] ?? false;
$object->show_above_text = $data['show_above_text'] ?? false;
return $object;
}
}