Get the extension that matches given mimetype.

@param  string $mimetype
@return mixed  null when not found, extension (string) when found.
379
public function getExtension($mimetype)
    {
        if (!($extension = array_search($mimetype, $this->mainMimeTypes))) {
            $extension = array_search($mimetype, $this->mimeTypes);
        }

        return !$extension ? null : $extension;
    }
692648
public function getParam(string $paramType)
    {
        if (isset($this->definitions[$paramType])) {
            return $this->definitions[$paramType];
        }

        return null;
    }
127901
public function getIconByMimeType($mimeType)
    {
        return array_key_exists($mimeType, $this->icons) ? $this->icons[$mimeType] : null;
    }
1128
public static function getMimetype($name)
    {
        $parts = explode('.', $name);
        if (count($parts) > 1) {
            $ext = strtolower(end($parts));
            if (isset(self::$mime_types[$ext])) {
                return self::$mime_types[$ext];
            }
        }

        return null;
    }
1147479
public static function getMimeByExtension($extension, $default = 'application/octet-stream')
    {
        $extension = strtolower($extension);

        // look for some standard types
        switch ($extension) {
            case null:
                return $default;
            case 'json':
                return 'application/json';
            case 'html':
                return 'text/html';
            case 'atom':
                return 'application/atom+xml';
            case 'rss':
                return 'application/rss+xml';
            case 'xml':
                return 'application/xml';
        }

        $media_types = Grav::instance()['config']->get('media.types');

        if (isset($media_types[$extension])) {
            if (isset($media_types[$extension]['mime'])) {
                return $media_types[$extension]['mime'];
            }
        }

        return $default;
    }
1319980
protected function checkMimeType($mimeType)
    {
        $allow = $this->getWhitelistedMimeTypes();
        $block = $this->getBlacklistedMimeTypes();

        if (false !== $allow) {
            foreach ($allow as $pattern) {
                if ($this->wildCardMatch($mimeType, $pattern)) {
                    return true;
                }
            }

            return false;
        }

        if (false !== $block) {
            foreach ($block as $pattern) {
                if ($this->wildCardMatch($mimeType, $pattern)) {
                    return false;
                }
            }
        }

        return true;
    }
555497
public function readPath($path, $mimeType = null)
    {
        return $this->read($this->uriFactory()->fromPath($path), $mimeType);
    }
245515
private static final String getExtension(String MIMETYPE) throws Exception {
        if (m_extensionMappings == null) {
            m_extensionMappings = readExtensionMappings(Server.FEDORA_HOME + "/server/" + Server.CONFIG_DIR + "/" + DATASTREAM_MAPPING_SOURCE_FILE);
        }

        String extension = m_extensionMappings.get(MIMETYPE);
        if (extension != null) {
            return extension;
        } else {
            return "";
        }
    }
126976
public function getMimeType(): string
    {
        $mimes = new MimeTypes();

        $type = $mimes->getMimeType($this->getAttribute('extension'));

        return $type ?? 'unknown';
    }
966254
public static function isImage($mimeType)
    {
        if (in_array($mimeType, self::$mimeTypes, true)) {
            return (bool)preg_match('|^image/.+$|', $mimeType);
        }

        return false;
    }
356164
public function isAcceptMimetype($mimetype)
    {
        if ($this->hasHeader('Accept')) {
            return $this->isAccept($this->getHeader('Accept'), $mimetype);
        }
        return false;
    }
311303
protected function _getMimeIcon( $mimetype )
	{
		$config = $this->_getContext()->getConfig();

		/** controller/extjs/media/default/mimeicon/directory
		 * Directory that contains the icons for the different mime types
		 *
		 * If no preview image can be generated from an uploaded file, an icon
		 * for its mime type is displayed instead. The directory for the mime
		 * icons is structured by the general mime type (e.g. "image") as
		 * sub-directory and the specific name of the mime type (e.g. "jpeg")
		 * as file name.
		 *
		 * The mime icon directory must be relative to the "basedir" configuration
		 * option. If
		 *
		 *  /var/www/test
		 *
		 * is the configured base directory and the upload directory should be
		 * located in
		 *
		 *  /var/www/test/media/mime
		 *
		 * then the configuration for the uploads directory must be
		 *
		 *  media/mime
		 *
		 * Avoid leading and trailing slashes for the upload directory string!
		 *
		 * @param string Path relative to the base directory
		 * @since 2014.03
		 * @category Developer
		 * @see controller/extjs/media/default/basedir
		 */
		if( ( $mimedir = $config->get( 'controller/extjs/media/default/mimeicon/directory', null ) ) === null )
		{
			$this->_getContext()->getLogger()->log( 'No directory for mime type images configured' );
			return '';
		}

		/** controller/extjs/media/default/mimeicon/extension
		 * File extension of the mime icon images
		 *
		 * If you would like to use different mime icons that are available in
		 * another file format, you have to change the file extension for the
		 * mime icons to the actual ones.
		 *
		 * Note: The configured file extension needs a leading dot!
		 *
		 * @param string File extension including a leading dot, e.g ".jpg"
		 * @since 2014.03
		 * @category Developer
		 */
		$ext = $config->get( 'controller/extjs/media/default/mimeicon/extension', '.png' );
		$abspath = $this->_getAbsoluteDirectory( $mimedir ) . DIRECTORY_SEPARATOR . $mimetype . $ext;
		$mimeicon = $mimedir . DIRECTORY_SEPARATOR . $mimetype . $ext;

		if( is_file( $abspath ) === false ) {
			$mimeicon = $mimedir . DIRECTORY_SEPARATOR . 'unknown' . $ext;
		}

		return $mimeicon;
	}
360719
protected function _getCommonJsData($mimeType)
    {
        $commonJsData = parent::_getCommonJsData($mimeType);
        if ($commonJsData) {
            $deps = array_merge(
                $this->_loadedPackage->_getFilteredUniqueDependencies('text/javascript'),
                $this->_loadedPackage->_getFilteredUniqueDependencies('text/javascript; defer')
            );
            foreach ($deps as $i) {
                $data = array();
                $commonJsDeps = $this->_getCommonJsDeps($i, $data);
                foreach (array_keys($data) as $key) {
                    if (isset($commonJsData[$key])) {
                        unset($commonJsData[$key]);
                    }
                }
            }
        }
        return $commonJsData;
    }
277602
def extension_by_source(source, mime_type):
    ""

    # TODO: should get this information from the plugin
    extension = source.plugin_name
    if extension:
        return extension

    if mime_type:
        return mime_type.split("/")[-1]
123721
public function findMimeType($ext = null) {
		if (empty($ext)) {
			return null;
		}
		return $this->find('all', ['conditions' => [$this->getAlias() . '.ext' => $ext]])->first();
	}
30639
public function toExtension($mime_type)
    {
        $mime_type = strtolower($mime_type);

        return array_search($mime_type, $this->dict) ?: null;
    }
1074636
public function getTypeByExtension($extension)
    {
        if ($this->isValidExtension($extension)) {

            // We get back flipped copy
            $list = $this->getList(true);
            return $list[$extension];

        } else {

            // For all unknown extensions, the default Mime-Type is used
            return 'application/octet-stream';
        }
    }