ldc-nature-and-respect/app/Enums/Recipes/CookingEnum.php

49 lines
1 KiB
PHP
Raw Normal View History

2023-03-15 11:25:22 +01:00
<?php
namespace App\Enums\Recipes;
2023-04-18 10:49:39 +02:00
enum CookingEnum : int
{
case cook = 1;
2023-03-15 11:25:22 +01:00
case grill = 2;
2023-04-18 10:49:39 +02:00
public function label(): string
{
2023-03-15 11:25:22 +01:00
return static::getLabel($this);
}
2023-04-18 10:49:39 +02:00
public function image(): string
{
2023-03-15 11:25:22 +01:00
return static::getImage($this);
}
2023-04-18 10:49:39 +02:00
public static function getLabel(self $value): string
{
2023-03-15 11:25:22 +01:00
return match ($value) {
self::cook => __('Cook'),
self::grill => __('Grill'),
};
}
2023-04-18 10:49:39 +02:00
public static function getImage(self $value): string
{
2023-03-15 11:25:22 +01:00
return match ($value) {
self::cook => "cook.png",
self::grill => "grill.png",
};
}
2023-04-18 10:49:39 +02:00
public static function getData(): array
{
2023-03-15 11:25:22 +01:00
$arrayEnum = [];
foreach (self::cases() as $key => $value) {
$arrayEnum = array_merge($arrayEnum, [[
"value" => $value->value,
"label" => $value->label(),
"image" => $value->image()
]]);
}
return $arrayEnum;
}
}