So I have a variety of classes that extend one central class. Each of these classes deals with a particular variety of data file: images, audio, video, etc.
So each class is going to have a validateMedia() method which checks the MIME type of the file and returns true ONLY IF that MIME type is in a list. This brings me to the list.
It seems natural to me to try and define a constant which contains all the valid mime types but you can't define array constants in PHP. It occurred to me to try and define a semicolon-delimited list like this but I'd need to be sure that no mimetype ever contained a semicolon and also would have to parse/explode/patternmatch this list every time I want to check a mime type. Something like this:
define('VALID_MIME_TYPES', 'image/jpeg;image/gif;image/png');
function is_valid_mime($mime_type) {
$valid_mimes = explode(';', VALID_MIME_TYPES); // not crazy about this part
if (!in_array($mime_type, $valid_mimes)) {
return false;
}
return true;
}
Also, where might I put this? Seems to me that it would be helpful for a site admin to have it in a master config or INI file somewhere in case they choose to start supporting PNG images when the new browser releases come out.
On the other hand, defining it as a class constant might be better because then we don't have a MASSIVE site-wide config file. Something like this:
class Image {
const VALID_MIME_TYPES = 'image/jpeg;image/gif;image/png';
function isValidMimeType($mimeType) {
$valid_mimes = explode(';', self::VALID_MIME_TYPES); // still not crazy about this part
if (!in_array($mimeType, $valid_mimes)) {
return false;
}
return true;
}
}
Any suggestions?