From 883b139726a11c92ef20aa45639a6b6c283e50b8 Mon Sep 17 00:00:00 2001 From: Netkas Date: Tue, 14 Feb 2023 15:07:28 -0500 Subject: [PATCH] Added \TgBotLib\Objects > ShippingOption --- src/TgBotLib/Objects/ShippingOption.php | 89 +++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/TgBotLib/Objects/ShippingOption.php diff --git a/src/TgBotLib/Objects/ShippingOption.php b/src/TgBotLib/Objects/ShippingOption.php new file mode 100644 index 0000000..78d5700 --- /dev/null +++ b/src/TgBotLib/Objects/ShippingOption.php @@ -0,0 +1,89 @@ +id; + } + + /** + * Option title + * + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * List of price portions + * + * @return LabeledPrice[] + */ + public function getPrices(): array + { + return $this->prices; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'title' => $this->title, + 'prices' => array_map(function (LabeledPrice $price) { + return $price->toArray(); + }, $this->prices) + ]; + } + + /** + * Constructs object from an array representation + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new self(); + $object->id = $data['id']; + $object->title = $data['title']; + $object->prices = array_map(function (array $price) { + return LabeledPrice::fromArray($price); + }, $data['prices']); + + return $object; + } + } \ No newline at end of file