Add MDCopyrightCollective to represent those
This commit is contained in:
parent
0f64939def
commit
2f765e183e
122
src/enums/MDCopyrightCollective.php
Normal file
122
src/enums/MDCopyrightCollective.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Represents a copyright collective.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a type of check an object may be subject to (completeness, condition, general audit).
|
||||
*/
|
||||
enum MDCopyrightCollective implements JsonSerializable {
|
||||
|
||||
case vg_bildkunst;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDCopyrightCollective
|
||||
*/
|
||||
public static function fromString(string $input):MDCopyrightCollective {
|
||||
|
||||
return match($input) {
|
||||
'vg_bildkunst' => self::vg_bildkunst,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown copyright collective"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDCopyrightCollective
|
||||
*/
|
||||
public static function fromInt(int $input):MDCopyrightCollective {
|
||||
|
||||
return match($input) {
|
||||
1 => self::vg_bildkunst,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown copyright collective"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 the human-readable name of the copyright collective.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string {
|
||||
|
||||
return match($this) {
|
||||
self::vg_bildkunst => "VG Bildkunst",
|
||||
default => throw new MDpageParameterNotFromListException("Unknown copyright collective"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an integer representation of the collective (for storage in DB).
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function toInt():int {
|
||||
|
||||
return match($this) {
|
||||
self::vg_bildkunst => 1,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown copyright collective"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a link to the contact form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContactForm():string {
|
||||
|
||||
return match($this) {
|
||||
self::vg_bildkunst => "https://www.bildkunst.de/service/formulare-fuer-nutzer/anfrage-online-nutzung",
|
||||
default => throw new MDpageParameterNotFromListException("Unknown copyright collective"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user