3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Validator\File
;
13 use Zend\Stdlib\ArrayUtils
;
16 * Validator which checks if the file is an image
18 class IsImage
extends MimeType
21 * @const string Error constants
23 const FALSE_TYPE
= 'fileIsImageFalseType';
24 const NOT_DETECTED
= 'fileIsImageNotDetected';
25 const NOT_READABLE
= 'fileIsImageNotReadable';
28 * @var array Error message templates
30 protected $messageTemplates = [
31 self
::FALSE_TYPE
=> "File is no image, '%type%' detected",
32 self
::NOT_DETECTED
=> "The mimetype could not be detected from the file",
33 self
::NOT_READABLE
=> "File is not readable or does not exist",
37 * Sets validator options
39 * @param array|Traversable|string $options
41 public function __construct($options = [])
43 // http://www.iana.org/assignments/media-types/media-types.xhtml#image
47 'application/fractals',
48 'application/postscript',
49 'application/vnd.hp-hpgl',
50 'application/vnd.oasis.opendocument.graphics',
52 'application/x-cmu-raster',
54 'application/x-inventor',
56 'application/x-portable-anymap',
57 'application/x-world-x-3dmf',
73 'image/vnd.adobe.photoshop',
90 'image/x-portable-anymap',
91 'image/x-portable-bitmap',
92 'image/x-portable-greymap',
93 'image/x-portable-pixmap',
98 'image/x-windows-bmp',
102 if ($options instanceof Traversable
) {
103 $options = ArrayUtils
::iteratorToArray($options);
106 if ($options === null) {
110 parent
::__construct($options);
112 if (! $this->getMimeType()) {
113 $this->setMimeType($default);