PHP Classes

File: stubs/mimeType.php.stub

Recommend this page to a friend!
  Classes of Eric Sizemore   mimey PHP MIME Type Conversion   stubs/mimeType.php.stub   Download  
File: stubs/mimeType.php.stub
Role: Example script
Content type: text/plain
Description: Example script
Class: mimey PHP MIME Type Conversion
Convert between file extensions and MIME types
Author: By
Last change: more work towards 2.0.0
Beginning stages of 2.0
Date: 1 month ago
Size: 955 bytes
 

Contents

Class file image Download
<?php

/**
 * @generated enum generated using bin/generate.php, please DO NOT EDIT!
 *
 * @codeCoverageIgnore
 */
declare(strict_types=1);

namespace %namespace%;

use
InvalidArgumentException;
%
interface_usage%
enum %classname%: string implements MimeTypeInterface
{
%
cases%
   
#[\Override]
   
public function getExtension(): string
   
{
        return
match($this) {
%
type2ext%
        };
    }

   
#[\Override]
   
public function getValue(): string
   
{
        return
$this->value;
    }

    public static function
fromExtension(string $extension): MimeType
   
{
       
$type = self::tryFromExtension($extension);

        if (
$type === null) {
            throw new
InvalidArgumentException('Unknown extension: ' . $extension);
        }
        return
$type;
    }

    public static function
tryFromExtension(string $extension): ?MimeType
   
{
        return
match($extension) {
%
ext2type%
            default =>
null,
        };
    }
}