Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Validate_File_MimeType Class Reference

Extends mime-type validator to clear the magic file search paths. More...

List of all members.

Static Public Member Functions

static getTypeOfFile ($file)
 Utility method to determine the mime-type of an arbitrary file.
static groupContainsType ($group, $type)
 Utility method to validate that a mime-type group contains this mime-type.

Protected Attributes

 $_magicFiles = array()

Detailed Description

Extends mime-type validator to clear the magic file search paths.

This allows the finfo() extension to fallback on its internal mime database rather than using a database found in the file-system which may be incompatible.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

static P4Cms_Validate_File_MimeType::getTypeOfFile ( file) [static]

Utility method to determine the mime-type of an arbitrary file.

Parameters:
string$filethe path of the file to get the mime type of.
Returns:
string the mime-type of the file.
    {
        $validator = new static('');
        $validator->isValid($file);

        return $validator->_type;
    }
static P4Cms_Validate_File_MimeType::groupContainsType ( group,
type 
) [static]

Utility method to validate that a mime-type group contains this mime-type.

Parameters:
string$groupthe mime-type group to search
string$typethe mime-type
Returns:
bool whether the group contained the type
    {
        $validator = new static($group);
        $mimetype = $validator->getMimeType(true);
        if (in_array($type, $mimetype)) {
            return true;
        }

        $types = explode('/', $type);
        $types = array_merge($types, explode('-', $type));
        $types = array_merge($types, explode(';', $type));
        foreach ($mimetype as $mime) {
            if (in_array($mime, $types)) {
                return true;
            }
        }
        
        return false;
    }

Member Data Documentation

P4Cms_Validate_File_MimeType::$_magicFiles = array() [protected]

The documentation for this class was generated from the following file: