Created
April 13, 2016 15:12
-
-
Save bbrothers/db1cb85dd38bfe50dcaee7e001a8f86e to your computer and use it in GitHub Desktop.
Should Exceptions handler their own assertion logic?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MimeTypeException extends Exception | |
{ | |
const SUPPORTED_MIME_TYPES = ['image/gif', 'image/jpeg', 'impage/png']; | |
public static function isOfSupportedMimeType($mimeType) | |
{ | |
if (!in_array($mimeType, SUPPORTED_MIME_TYPES)) { | |
throw new static( | |
sprintf( | |
'The provided value "%s" is not a supported mime type. Supported types are: %s.', | |
is_string($mimeType) ? $mimeType : gettype($mimeType), | |
implode(', ', SUPPORTED_MIME_TYPES) | |
) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment