0
0
Fork 0
mirror of https://github.com/verdigado/organization_folders.git synced 2024-11-24 21:50:26 +01:00
organization_folders/lib/Enum/FromNameEnum.php

22 lines
585 B
PHP
Raw Normal View History

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