PHP Classes

File: bin/generate.php

Recommend this page to a friend!
  Classes of Eric Sizemore   mimey PHP MIME Type Conversion   bin/generate.php   Download  
File: bin/generate.php
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: adding psalm to workflow, fixes/updates throughout
Date: 25 days ago
Size: 1,267 bytes
 

Contents

Class file image Download
#!/usr/bin/env php
<?php

declare(strict_types=1);

require_once \
dirname(__DIR__) . '/vendor/autoload.php';

//////////////////////////////////////////////////////////////

use Esi\Mimey\Mapping\Generator;

$mimeTypes = \dirname(__DIR__) . '/data/mime.types';
$mimeTypesCustom = \dirname(__DIR__) . '/data/mime.types.custom';
$jsonDestination = \dirname(__DIR__) . '/dist/mime.types.json';
$minJsonDestination = \dirname(__DIR__) . '/dist/mime.types.min.json';
$enumDestination = \dirname(__DIR__) . '/dist/MimeType.php';

$mimeTypesContent = \file_get_contents($mimeTypes);
$mimeTypesCustomContent = \file_get_contents($mimeTypesCustom);

\
assert($mimeTypesContent !== false);
\
assert($mimeTypesCustomContent !== false);

$generator = new Generator($mimeTypesCustomContent . \PHP_EOL . $mimeTypesContent);
$generator->generateMapping();

file_put_contents($jsonDestination, $generator->generateJson(false));
file_put_contents($minJsonDestination, $generator->generateJson());
file_put_contents($enumDestination, $generator->generatePhpEnum());

echo
'Generated MIME types mapping to:' . \PHP_EOL;
echo
' - ' . $jsonDestination . \PHP_EOL;
echo
' - ' . $minJsonDestination . \PHP_EOL;
echo
' - ' . $enumDestination . \PHP_EOL;
echo \
PHP_EOL;