- if (!in_array(strtolower($subtypes[1]), array('application', 'audio', 'image',
- 'message', 'model', 'multipart', 'text', 'video'))) {
- return false;
+
+ /**
+ * Validate Media type
+ *
+ * Basic Media type validation. Checks for valid maintype and correct
+ * format.
+ *
+ * @param string $mediatype The Media type which is to be validated.
+ *
+ * @return bool Whether media type is valid.
+ *
+ * @access public
+ */
+ public static function validateMediaType($mediatype)
+ {
+ return preg_match('/^(\w+)\/([\w\d-+.]+)$/', $mediatype, $subtypes) > 0
+ &&
+ in_array(strtolower($subtypes[1]), array('application', 'audio',
+ 'image', 'message', 'model', 'multipart', 'text', 'video'));