Moved Objects

This commit is contained in:
netkas 2024-10-02 00:18:12 -04:00
parent 848a2a78e3
commit 6c67e97a4b
167 changed files with 368 additions and 373 deletions

View file

@ -0,0 +1,49 @@
<?php
namespace TgBotLib\Objects;
use InvalidArgumentException;
use TgBotLib\Enums\Types\BackgroundFillType;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BackgroundFill\BackgroundFillFreeformGradient;
use TgBotLib\Objects\BackgroundFill\BackgroundFillGradient;
use TgBotLib\Objects\BackgroundFill\BackgroundFillSolid;
abstract class BackgroundFill implements ObjectTypeInterface
{
protected BackgroundFillType $type;
/**
* Type of the background fill
*
* @return BackgroundFillType
*/
public function getType(): BackgroundFillType
{
return $this->type;
}
/**
* @inheritDoc
*/
public abstract function toArray(): array;
/**
* @inheritDoc
*/
public static function fromArray(array $data): BackgroundFill
{
if(!isset($data['type']))
{
throw new InvalidArgumentException('BackgroundFill expected type');
}
return match(BackgroundFillType::tryFrom($data['type']))
{
BackgroundFillType::SOLID => BackgroundFillSolid::fromArray($data),
BackgroundFillType::GRADIENT => BackgroundFillGradient::fromArray($data),
BackgroundFillType::FREEFORM_GRADIENT => BackgroundFillFreeformGradient::fromArray($data),
default => throw new InvalidArgumentException("Invalid BackgroundFill Type")
};
}
}