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
|
|
|
}
|