learning-center/app/SharedKernel/Structs/Enum.php
2024-09-08 13:48:26 +03:00

25 lines
568 B
PHP

<?php
declare(strict_types=1);
namespace App\SharedKernel\Structs;
use App\SharedKernel\StringConverter;
abstract class Enum extends ValueObject
{
/**
* @throws \InvalidArgumentException
*/
public static function fromValue(string $value): self
{
$methodName = StringConverter::snakeCaseToCamelCase($value);
if (!method_exists(static::class, $methodName)) {
throw new \InvalidArgumentException(sprintf('Passed value \'%s\' doesn\'t allowed here', $value));
}
return static::$methodName();
}
}