Skip to content

Instantly share code, notes, and snippets.

@bbrothers
Created April 13, 2016 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbrothers/db1cb85dd38bfe50dcaee7e001a8f86e to your computer and use it in GitHub Desktop.
Save bbrothers/db1cb85dd38bfe50dcaee7e001a8f86e to your computer and use it in GitHub Desktop.
Should Exceptions handler their own assertion logic?
<?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