Updated Story

This commit is contained in:
netkas 2024-10-05 00:55:14 -04:00
parent e246741b5a
commit af7a33b1c1

View file

@ -1,149 +1,153 @@
<?php <?php
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
class Story implements ObjectTypeInterface class Story implements ObjectTypeInterface
{
private string $file_id;
private string $file_unique_id;
private int $width;
private int $height;
private int $duration;
private ?PhotoSize $thumbnail;
private ?string $file_name;
private ?string $mime_type;
private ?int $file_size;
/**
* Identifier for this file, which can be used to download or reuse the file
*
* @return string
*/
public function getFileId(): string
{ {
return $this->file_id; private string $file_id;
} private string $file_unique_id;
private int $width;
private int $height;
private int $duration;
private ?PhotoSize $thumbnail;
private ?string $file_name;
private ?string $mime_type;
private ?int $file_size;
/** /**
* Unique identifier for this file, which is supposed to be the same over time * Identifier for this file, which can be used to download or reuse the file
* and for different bots. Can't be used to download or reuse the file. *
* * @return string
* @return string */
*/ public function getFileId(): string
public function getFileUniqueId(): string {
{ return $this->file_id;
return $this->file_unique_id; }
}
/** /**
* Video width as defined by the sender * Unique identifier for this file, which is supposed to be the same over time
* * and for different bots. Can't be used to download or reuse the file.
* @return int *
*/ * @return string
public function getWidth(): int */
{ public function getFileUniqueId(): string
return $this->width; {
} return $this->file_unique_id;
}
/** /**
* Video height as defined by the sender * Video width as defined by the sender
* *
* @return int * @return int
*/ */
public function getHeight(): int public function getWidth(): int
{ {
return $this->height; return $this->width;
} }
/** /**
* Duration of the video in seconds as defined by the sender * Video height as defined by the sender
* *
* @return int * @return int
*/ */
public function getDuration(): int public function getHeight(): int
{ {
return $this->duration; return $this->height;
} }
/** /**
* Optional. Video thumbnail * Duration of the video in seconds as defined by the sender
* *
* @return PhotoSize|null * @return int
*/ */
public function getThumbnail(): ?PhotoSize public function getDuration(): int
{ {
return $this->thumbnail; return $this->duration;
} }
/** /**
* Optional. Original filename as defined by the sender * Optional. Video thumbnail
* *
* @return string|null * @return PhotoSize|null
*/ */
public function getFileName(): ?string public function getThumbnail(): ?PhotoSize
{ {
return $this->file_name; return $this->thumbnail;
} }
/** /**
* Optional. MIME type of the file as defined by the sender * Optional. Original filename as defined by the sender
* *
* @return string|null * @return string|null
*/ */
public function getMimeType(): ?string public function getFileName(): ?string
{ {
return $this->mime_type; return $this->file_name;
} }
/** /**
* Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have * Optional. MIME type of the file as defined by the sender
* difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit *
* integer or double-precision float type are safe for storing this value. * @return string|null
* */
* @return int|null public function getMimeType(): ?string
*/ {
public function getFileSize(): ?int return $this->mime_type;
{ }
return $this->file_size;
}
/** /**
* @inheritDoc * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have
*/ * difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit
public function toArray(): array * integer or double-precision float type are safe for storing this value.
{ *
return [ * @return int|null
'file_id' => $this->file_id, */
'file_unique_id' => $this->file_unique_id, public function getFileSize(): ?int
'width' => $this->width, {
'height' => $this->height, return $this->file_size;
'duration' => $this->duration, }
'thumbnail' => $this->thumbnail ? $this->thumbnail->toArray() : null,
'file_name' => $this->file_name,
'mime_type' => $this->mime_type,
'file_size' => $this->file_size,
];
}
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function fromArray(array $data): ObjectTypeInterface public function toArray(): array
{ {
$object = new self(); return [
'file_id' => $this->file_id,
'file_unique_id' => $this->file_unique_id,
'width' => $this->width,
'height' => $this->height,
'duration' => $this->duration,
'thumbnail' => $this->thumbnail?->toArray(),
'file_name' => $this->file_name,
'mime_type' => $this->mime_type,
'file_size' => $this->file_size,
];
}
$object->file_id = $data['file_id']; /**
$object->file_unique_id = $data['file_unique_id']; * @inheritDoc
$object->width = $data['width']; */
$object->height = $data['height']; public static function fromArray(?array $data): ?Story
$object->duration = $data['duration']; {
$object->thumbnail = isset($data['thumbnail']) ? PhotoSize::fromArray($data['thumbnail']) : null; if($data === null)
$object->file_name = $data['file_name'] ?? null; {
$object->mime_type = $data['mime_type'] ?? null; return null;
$object->file_size = $data['file_size'] ?? null; }
return $object; $object = new self();
} $object->file_id = $data['file_id'];
} $object->file_unique_id = $data['file_unique_id'];
$object->width = $data['width'];
$object->height = $data['height'];
$object->duration = $data['duration'];
$object->thumbnail = isset($data['thumbnail']) ? PhotoSize::fromArray($data['thumbnail']) : null;
$object->file_name = $data['file_name'] ?? null;
$object->mime_type = $data['mime_type'] ?? null;
$object->file_size = $data['file_size'] ?? null;
return $object;
}
}