*/ declare(strict_types = 1); /** * Represents a format in which custom reports can be generated. */ enum MDCustomReportFormat implements JsonSerializable { case csv; case html; /** * Returns a value of this type based on a string. * * @param string $input Input to get a value from. * * @return MDCustomReportFormat */ public static function fromString(string $input):MDCustomReportFormat { return match($input) { 'csv' => self::csv, 'html' => self::html, default => throw new MDpageParameterNotFromListException("Unknown custom report format"), }; } /** * Lists all available names. * * @return array */ 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; } /** * Sanitizes a string for input into a file of the current format. * * @param string $input Input string to sanitize. * * @return string */ public function sanitize(string $input):string { return match($this) { self::csv => '"' . strtr($input, ['"' => '\'']) . '"', self::html => htmlspecialchars($input), }; } }