55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\ComponentsBundle\Entity;
|
|
|
|
use KupShop\KupShopBundle\Arrayable;
|
|
|
|
enum ToastStatus: string
|
|
{
|
|
case Success = 'success';
|
|
case Error = 'error';
|
|
case Warning = 'warning';
|
|
case Info = 'info';
|
|
case Danger = 'danger';
|
|
}
|
|
|
|
enum ToastType: string
|
|
{
|
|
case Classic = 'classic';
|
|
case Computed = 'computed';
|
|
}
|
|
|
|
class Toast implements Arrayable, \JsonSerializable
|
|
{
|
|
public const EVENT_NAME = 'wpj.js-shop.toast-add';
|
|
|
|
public function __construct(
|
|
public string $content,
|
|
public ToastStatus $status,
|
|
public ToastType $type = ToastType::Classic,
|
|
) {
|
|
}
|
|
|
|
public static function success(string $content, ToastType $type = ToastType::Classic): self
|
|
{
|
|
return new self($content, ToastStatus::Success, $type);
|
|
}
|
|
|
|
public static function error(string $content, ToastType $type = ToastType::Classic): self
|
|
{
|
|
return new self($content, ToastStatus::Error, $type);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return get_object_vars($this);
|
|
}
|
|
|
|
public function jsonSerialize(): array
|
|
{
|
|
return $this->toArray();
|
|
}
|
|
}
|