Files
MDAllowedValueSets/src/enums/MDDieAxisUnit.php

145 lines
3.3 KiB
PHP

<?PHP
/**
* Represents a measurement type.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a measurement type.
*/
enum MDDieAxisUnit implements MDValueEnumInterface, JsonSerializable, MDMeasurementUnitInterface {
case h;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDDieAxisUnit
*/
public static function fromString(string $input):MDDieAxisUnit {
return match($input) {
'h' => self::h,
default => throw new MDpageParameterNotFromListException("Unknown h counting unit"),
};
}
/**
* Returns a value of this type based on an integer.
*
* @param integer $input Input to get a value from.
*
* @return MDDieAxisUnit
*/
public static function fromInt(int $input):MDDieAxisUnit {
return match($input) {
1 => self::h,
default => throw new MDpageParameterNotFromListException("Unknown h counting unit"),
};
}
/**
*
*/
/**
* 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;
}
/**
* Returns an integer representation of the collective (for storage in DB).
*
* @return integer
*/
public function toInt():int {
return match($this) {
self::h => 1,
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
};
}
/**
* Returns the measurement calculated down to the base unit.
*
* @param float $value Measurement value.
*
* @return float
*/
public function convertToBaseUnit(float $value):float {
return $value;
}
/**
* Gets an unsorted list of the entries in a translated version.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return array<string, string>
*/
public static function getUnsortedList(MDTlLoader $tlLoader):array {
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "units_die_axis_set", "units_die_axis_set");
}
/**
* Gets a sorted list of the entries in a translated version.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return array<string, string>
*/
public static function getSortedList(MDTlLoader $tlLoader):array {
return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "units_die_axis_set", "units_die_axis_set");
}
/**
* Returns the name of the current value in translation.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return string
*/
public function getTledName(MDTlLoader $tlLoader):string {
return $tlLoader->tl("units_die_axis_set", "units_die_axis_set", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}