0
0
Fork 0
mirror of https://github.com/verdigado/organization_folders.git synced 2024-11-22 12:40:28 +01:00
organization_folders/lib/Enum/FromNameEnum.php

22 lines
No EOL
585 B
PHP

<?php
namespace OCA\OrganizationFolders\Enum;
trait FromNameEnum {
public static function fromName(string $name) {
foreach(self::cases() as $status) {
if($name === $status->name){
return $status;
}
}
throw new \ValueError("$name is not a valid value for enum " . self::class );
}
public static function fromNameOrValue(int|string $scalar) {
if(gettype($scalar) == "integer") {
return self::tryFrom($scalar);
} else {
return self::fromName($scalar);
}
}
}