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

37 lines
775 B
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 DifficultyEnum : int
{
case easy = 1;
2023-03-15 11:25:22 +01:00
case medium = 2;
2023-04-18 10:49:39 +02:00
case hard = 3;
2023-03-15 11:25:22 +01:00
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 static function getLabel(self $value): string
{
2023-03-15 11:25:22 +01:00
return match ($value) {
self::easy => __('Easy'),
self::medium => __('Medium'),
self::hard => __('Hard'),
};
}
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()
]]);
}
return $arrayEnum;
}
}