Refactor Plausi from musdb to move the logic into this subrepository

See #948
This commit is contained in:
2023-07-18 22:05:00 +02:00
parent f35115e38c
commit 863c3a3c93
6 changed files with 933 additions and 1 deletions

View File

@ -0,0 +1,75 @@
<?PHP
/**
* Represents a higher level category of event types.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a higher level category of event types.
*/
enum MDEventCategory implements JsonSerializable {
case production;
case post_production;
case pre_production;
case no_production;
/**
* Returns an MDEventCategory based on a given event type.
*
* @param integer $event_type Event type.
*
* @return MDEventCategory
*/
public static function fromEventType(int $event_type):MDEventCategory {
if (in_array($event_type, MDEventsSet::EVENTS_PRODUCTION, true)) {
return self::production;
}
if (in_array($event_type, MDEventsSet::EVENTS_POST_PRODUCTION, true)) {
return self::post_production;
}
if (in_array($event_type, MDEventsSet::EVENTS_PRE_PRODUCTION, true)) {
return self::pre_production;
}
if (in_array($event_type, MDEventsSet::EVENTS_NO_PRODUCTION, true)) {
return self::no_production;
}
if ($event_type === 5) {
return self::no_production;
}
throw new Exception("Uncategorized event type: " . $event_type);
}
/**
* Lists all available names.
*
* @return array<string>
*/
public static function caseNames():array {
$output = [];
$cases = self::cases();
foreach ($cases as $case) {
$output[] = $case->name;
}
return $output;
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}