Plank\Mediable\MediaUploader::inferAggregateType PHP Метод

inferAggregateType() публичный Метод

Determine the aggregate type of the file based on the MIME type and the extension.
public inferAggregateType ( string $mime_type, string $extension ) : string
$mime_type string
$extension string
Результат string
    public function inferAggregateType($mime_type, $extension)
    {
        $allowed_types = $this->config['allowed_aggregate_types'];
        $types_for_mime = $this->possibleAggregateTypesForMimeType($mime_type);
        $types_for_extension = $this->possibleAggregateTypesForExtension($extension);
        if (count($allowed_types)) {
            $intersection = array_intersect($types_for_mime, $types_for_extension, $allowed_types);
        } else {
            $intersection = array_intersect($types_for_mime, $types_for_extension);
        }
        if (count($intersection)) {
            $type = $intersection[0];
        } elseif (empty($types_for_mime) && empty($types_for_extension)) {
            if (!$this->config['allow_unrecognized_types']) {
                throw FileNotSupportedException::unrecognizedFileType($mime_type, $extension);
            }
            $type = Media::TYPE_OTHER;
        } else {
            if ($this->config['strict_type_checking']) {
                throw FileNotSupportedException::strictTypeMismatch($mime_type, $extension);
            }
            $merged = array_merge($types_for_mime, $types_for_extension);
            $type = reset($merged);
        }
        if (count($allowed_types) && !in_array($type, $allowed_types)) {
            throw FileNotSupportedException::aggregateTypeRestricted($type, $allowed_types);
        }
        return $type;
    }