1<?php
2/**
3 * RRDGraph Plugin: Static class for mapping file extensions to content type
4*
5* @author Daniel Goß <developer@flashsystems.de>
6* @license MIT
7*/
8class ContentType
9{
10    /**
11     * Contains an associative array mapping file extensions (key) to content type strings (value).
12     * @var Array
13     */
14    const contentTypes = array(
15      "png" => "image/png",
16      "svg" => "image/svg+xml"
17    );
18
19    /**
20     * Returns the content type to use for transmitting the given file name. The content type is
21     * solely detected by the file extension.
22     * @param String $fileName The file name to detect the content type for.
23     * @return String The content type to use or null if the given file extension is not in the list of known file extensions.
24     */
25    public static function get_content_type($fileName) {
26        $extension = strtolower(ltrim(strrchr($fileName, '.'), '.'));
27
28        if (array_key_exists($extension, self::contentTypes)) {
29            return self::contentTypes[$extension];
30        } else {
31            return null;
32        }
33    }
34}