Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 117 lines (107 sloc) 3.349 kB
e443b8c [DOCUMENTATION] English:
thomas authored
1 <?php
2 /**
745f9c9 @Maks3w [CS][Library] Set File Header
Maks3w authored
3 * Zend Framework (http://framework.zend.com/)
e443b8c [DOCUMENTATION] English:
thomas authored
4 *
745f9c9 @Maks3w [CS][Library] Set File Header
Maks3w authored
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
67f098a @samsonasik Happy new year 2015
samsonasik authored
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
745f9c9 @Maks3w [CS][Library] Set File Header
Maks3w authored
7 * @license http://framework.zend.com/license/new-bsd New BSD License
e443b8c [DOCUMENTATION] English:
thomas authored
8 */
9
dcab696 Converted Zend_Validate to \Zend\Validator
Ralph Schindler authored
10 namespace Zend\Validator\File;
11
ce0bb6c @Maks3w [Validator] Code clean-up
Maks3w authored
12 use Traversable;
13 use Zend\Stdlib\ArrayUtils;
b948e9d @weierophinney Merge branch 'validator_broken_messages' of https://github.com/dchuso…
weierophinney authored
14
dcab696 Converted Zend_Validate to \Zend\Validator
Ralph Schindler authored
15 /**
3cd753d @Danielss89 Fix class description
Danielss89 authored
16 * Validator which checks if the file is an image
e443b8c [DOCUMENTATION] English:
thomas authored
17 */
dcab696 Converted Zend_Validate to \Zend\Validator
Ralph Schindler authored
18 class IsImage extends MimeType
e443b8c [DOCUMENTATION] English:
thomas authored
19 {
20 /**
21 * @const string Error constants
22 */
23 const FALSE_TYPE = 'fileIsImageFalseType';
24 const NOT_DETECTED = 'fileIsImageNotDetected';
25 const NOT_READABLE = 'fileIsImageNotReadable';
26
27 /**
28 * @var array Error message templates
29 */
ce0bb6c @Maks3w [Validator] Code clean-up
Maks3w authored
30 protected $messageTemplates = array(
3f85f5f @cgmartin File Validators refactored
cgmartin authored
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",
e443b8c [DOCUMENTATION] English:
thomas authored
34 );
35
36 /**
37 * Sets validator options
38 *
ce0bb6c @Maks3w [Validator] Code clean-up
Maks3w authored
39 * @param array|Traversable|string $options
e443b8c [DOCUMENTATION] English:
thomas authored
40 */
6fccea6 @thomasweidner [ZF-11594] Zend\Validator
thomasweidner authored
41 public function __construct($options = array())
e443b8c [DOCUMENTATION] English:
thomas authored
42 {
52cc10d @samsonasik Fixes link media type list for iana and wikipedia
samsonasik authored
43 // http://www.iana.org/assignments/media-types/media-types.xhtml#image
77bcced [ZF-8833, GENERIC] Zend_Validate:
thomas authored
44 $default = array(
d75ca60 [ZF-9004] Zend_Validate:
thomas authored
45 'application/cdf',
46 'application/dicom',
47 'application/fractals',
48 'application/postscript',
49 'application/vnd.hp-hpgl',
50 'application/vnd.oasis.opendocument.graphics',
51 'application/x-cdf',
52 'application/x-cmu-raster',
53 'application/x-ima',
54 'application/x-inventor',
55 'application/x-koan',
56 'application/x-portable-anymap',
57 'application/x-world-x-3dmf',
58 'image/bmp',
59 'image/c',
60 'image/cgm',
61 'image/fif',
62 'image/gif',
63 'image/jpeg',
64 'image/jpm',
65 'image/jpx',
77bcced [ZF-8833, GENERIC] Zend_Validate:
thomas authored
66 'image/jp2',
d75ca60 [ZF-9004] Zend_Validate:
thomas authored
67 'image/naplps',
68 'image/pjpeg',
77bcced [ZF-8833, GENERIC] Zend_Validate:
thomas authored
69 'image/png',
d75ca60 [ZF-9004] Zend_Validate:
thomas authored
70 'image/svg',
71 'image/svg+xml',
72 'image/tiff',
77bcced [ZF-8833, GENERIC] Zend_Validate:
thomas authored
73 'image/vnd.adobe.photoshop',
74 'image/vnd.djvu',
d75ca60 [ZF-9004] Zend_Validate:
thomas authored
75 'image/vnd.fpx',
76 'image/vnd.net-fpx',
77 'image/x-cmu-raster',
78 'image/x-cmx',
79 'image/x-coreldraw',
77bcced [ZF-8833, GENERIC] Zend_Validate:
thomas authored
80 'image/x-cpi',
d75ca60 [ZF-9004] Zend_Validate:
thomas authored
81 'image/x-emf',
77bcced [ZF-8833, GENERIC] Zend_Validate:
thomas authored
82 'image/x-ico',
d75ca60 [ZF-9004] Zend_Validate:
thomas authored
83 'image/x-icon',
84 'image/x-jg',
85 'image/x-ms-bmp',
86 'image/x-niff',
87 'image/x-pict',
88 'image/x-pcx',
0bc48c2 @thomasweidner [hotfix/ZF-11661] Zend_Validator_File_IsImage
thomasweidner authored
89 'image/x-png',
d75ca60 [ZF-9004] Zend_Validate:
thomas authored
90 'image/x-portable-anymap',
91 'image/x-portable-bitmap',
92 'image/x-portable-greymap',
93 'image/x-portable-pixmap',
94 'image/x-quicktime',
95 'image/x-rgb',
96 'image/x-tiff',
97 'image/x-unknown',
98 'image/x-windows-bmp',
99 'image/x-xpmi',
77bcced [ZF-8833, GENERIC] Zend_Validate:
thomas authored
100 );
101
b948e9d @weierophinney Merge branch 'validator_broken_messages' of https://github.com/dchuso…
weierophinney authored
102 if ($options instanceof Traversable) {
747d2c0 @Thinkscape Refactor Zend\Stdlib\ArrayTools to ArrayUtils, add missing headers.
Thinkscape authored
103 $options = ArrayUtils::iteratorToArray($options);
6fccea6 @thomasweidner [ZF-11594] Zend\Validator
thomasweidner authored
104 }
d80871f @mwillbanks Resolved same issue for IsCompressed validator
mwillbanks authored
105
ac6e3da @mwillbanks Resolved IsImage to set the mimetype if there was no mimetype options…
mwillbanks authored
106 if ($options === null) {
107 $options = array();
77bcced [ZF-8833, GENERIC] Zend_Validate:
thomas authored
108 }
109
6fccea6 @thomasweidner [ZF-11594] Zend\Validator
thomasweidner authored
110 parent::__construct($options);
ac6e3da @mwillbanks Resolved IsImage to set the mimetype if there was no mimetype options…
mwillbanks authored
111
112 if (!$this->getMimeType()) {
113 $this->setMimeType($default);
114 }
e443b8c [DOCUMENTATION] English:
thomas authored
115 }
116 }
Something went wrong with that request. Please try again.