68 lines
1.5 KiB
PHP
68 lines
1.5 KiB
PHP
|
<?PHP
|
||
|
/**
|
||
|
* Represents a time indicator (CE / BCE).
|
||
|
*
|
||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||
|
*/
|
||
|
declare(strict_types = 1);
|
||
|
|
||
|
/**
|
||
|
* Represents a time indicator (CE / BCE).
|
||
|
*/
|
||
|
enum NodaTimeBeforeAfterIndicator implements JsonSerializable {
|
||
|
|
||
|
case none;
|
||
|
case after;
|
||
|
case before;
|
||
|
case since;
|
||
|
case until;
|
||
|
|
||
|
/**
|
||
|
* Returns a value of this type based on a string.
|
||
|
*
|
||
|
* @param string $input Input to get a value from.
|
||
|
*
|
||
|
* @return NodaTimeBeforeAfterIndicator
|
||
|
*/
|
||
|
public static function fromString(string $input):NodaTimeBeforeAfterIndicator {
|
||
|
|
||
|
return match($input) {
|
||
|
'' => self::none,
|
||
|
'Nach' => self::after,
|
||
|
'Vor' => self::before,
|
||
|
'Seit' => self::since,
|
||
|
'Bis' => self::until,
|
||
|
default => throw new MDpageParameterNotFromListException("Unknown before / after indicator"),
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns a canonical string representation.
|
||
|
*
|
||
|
* @return string
|
||
|
*/
|
||
|
public function toString():string {
|
||
|
|
||
|
return match($this) {
|
||
|
self::none => '',
|
||
|
self::after => 'Nach',
|
||
|
self::before => 'Vor',
|
||
|
self::since => 'Seit',
|
||
|
self::until => 'Bis',
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Provides the option to serialize as a string during json_encode().
|
||
|
*
|
||
|
* @return string
|
||
|
*/
|
||
|
public function jsonSerialize():string {
|
||
|
|
||
|
return $this->name;
|
||
|
|
||
|
}
|
||
|
}
|