-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNativeTranslatedEnum.php
More file actions
38 lines (31 loc) · 930 Bytes
/
NativeTranslatedEnum.php
File metadata and controls
38 lines (31 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace Yokai\EnumBundle;
use Symfony\Contracts\Translation\TranslatorInterface;
use UnitEnum;
use Yokai\EnumBundle\Exception\LogicException;
/**
* @author Yann Eugoné <eugone.yann@gmail.com>
*/
class NativeTranslatedEnum extends TranslatedEnum
{
public function __construct(
string $enum,
TranslatorInterface $translator,
string $transPattern,
string $transDomain = 'messages',
string|null $name = null
) {
if (!\is_a($enum, UnitEnum::class, true)) {
throw LogicException::invalidUnitEnum($enum);
}
if ($name === null && static::class === __CLASS__) {
$name = $enum;
}
$values = [];
foreach ($enum::cases() as $case) {
$values[$case->name] = $case;
}
parent::__construct($values, $translator, $transPattern, $transDomain, $name);
}
}