Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

File Validators refactored

  • Loading branch information...
commit 3f85f5fd7074e372208b23ac3d18ef24812a8c73 1 parent 02f8f7a
Christopher Martin authored October 02, 2012
4  library/Zend/InputFilter/FileInput.php
@@ -52,9 +52,11 @@ public function isValid($context = null)
52 52
         return $this->isValid;
53 53
     }
54 54
 
  55
+    /**
  56
+     * @return void
  57
+     */
55 58
     protected function injectNotEmptyValidator()
56 59
     {
57 60
         $this->notEmptyValidator = true;
58  
-        // TODO: Could do something like automatically add the Upload validator here
59 61
     }
60 62
 }
3  library/Zend/InputFilter/Input.php
@@ -309,6 +309,9 @@ public function getMessages()
309 309
         return $validator->getMessages();
310 310
     }
311 311
 
  312
+    /**
  313
+     * @return void
  314
+     */
312 315
     protected function injectNotEmptyValidator()
313 316
     {
314 317
         if ((!$this->isRequired() && $this->allowEmpty()) || $this->notEmptyValidator) {
252  library/Zend/Validator/File/Count.php
... ...
@@ -1,252 +0,0 @@
1  
-<?php
2  
-/**
3  
- * Zend Framework (http://framework.zend.com/)
4  
- *
5  
- * @link      http://github.com/zendframework/zf2 for the canonical source repository
6  
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
7  
- * @license   http://framework.zend.com/license/new-bsd New BSD License
8  
- * @package   Zend_Validator
9  
- */
10  
-
11  
-namespace Zend\Validator\File;
12  
-
13  
-use Zend\Validator\AbstractValidator;
14  
-use Zend\Validator\Exception;
15  
-
16  
-/**
17  
- * Validator for counting all given files
18  
- *
19  
- * @category  Zend
20  
- * @package   Zend_Validator
21  
- */
22  
-class Count extends AbstractValidator
23  
-{
24  
-    /**#@+
25  
-     * @const string Error constants
26  
-     */
27  
-    const TOO_MANY = 'fileCountTooMany';
28  
-    const TOO_FEW  = 'fileCountTooFew';
29  
-    /**#@-*/
30  
-
31  
-    /**
32  
-     * @var array Error message templates
33  
-     */
34  
-    protected $messageTemplates = array(
35  
-        self::TOO_MANY => "Too many files, maximum '%max%' are allowed but '%count%' are given",
36  
-        self::TOO_FEW  => "Too few files, minimum '%min%' are expected but '%count%' are given",
37  
-    );
38  
-
39  
-    /**
40  
-     * @var array Error message template variables
41  
-     */
42  
-    protected $messageVariables = array(
43  
-        'min'   => array('options' => 'min'),
44  
-        'max'   => array('options' => 'max'),
45  
-        'count' => 'count'
46  
-    );
47  
-
48  
-    /**
49  
-     * Actual filecount
50  
-     *
51  
-     * @var integer
52  
-     */
53  
-    protected $count;
54  
-
55  
-    /**
56  
-     * Internal file array
57  
-     * @var array
58  
-     */
59  
-    protected $files;
60  
-
61  
-    /**
62  
-     * Options for this validator
63  
-     *
64  
-     * @var array
65  
-     */
66  
-    protected $options = array(
67  
-        'min' => null,  // Minimum file count, if null there is no minimum file count
68  
-        'max' => null,  // Maximum file count, if null there is no maximum file count
69  
-    );
70  
-
71  
-    /**
72  
-     * Sets validator options
73  
-     *
74  
-     * Min limits the file count, when used with max=null it is the maximum file count
75  
-     * It also accepts an array with the keys 'min' and 'max'
76  
-     *
77  
-     * If $options is a integer, it will be used as maximum file count
78  
-     * As Array is accepts the following keys:
79  
-     * 'min': Minimum filecount
80  
-     * 'max': Maximum filecount
81  
-     *
82  
-     * @param  integer|array|\Traversable $options Options for the adapter
83  
-     */
84  
-    public function __construct($options = null)
85  
-    {
86  
-        if (is_string($options) || is_numeric($options)) {
87  
-            $options = array('max' => $options);
88  
-        }
89  
-
90  
-        if (1 < func_num_args()) {
91  
-            $options['min'] = func_get_arg(0);
92  
-            $options['max'] = func_get_arg(1);
93  
-        }
94  
-
95  
-        parent::__construct($options);
96  
-    }
97  
-
98  
-    /**
99  
-     * Returns the minimum file count
100  
-     *
101  
-     * @return integer
102  
-     */
103  
-    public function getMin()
104  
-    {
105  
-        return $this->options['min'];
106  
-    }
107  
-
108  
-    /**
109  
-     * Sets the minimum file count
110  
-     *
111  
-     * @param  integer|array $min The minimum file count
112  
-     * @return Count Provides a fluent interface
113  
-     * @throws Exception\InvalidArgumentException When min is greater than max
114  
-     */
115  
-    public function setMin($min)
116  
-    {
117  
-        if (is_array($min) and isset($min['min'])) {
118  
-            $min = $min['min'];
119  
-        }
120  
-
121  
-        if (!is_string($min) and !is_numeric($min)) {
122  
-            throw new Exception\InvalidArgumentException('Invalid options to validator provided');
123  
-        }
124  
-
125  
-        $min = (integer) $min;
126  
-        if (($this->getMax() !== null) && ($min > $this->getMax())) {
127  
-            throw new Exception\InvalidArgumentException("The minimum must be less than or equal to the maximum file count, but $min >"
128  
-                                            . " {$this->getMax()}");
129  
-        }
130  
-
131  
-        $this->options['min'] = $min;
132  
-        return $this;
133  
-    }
134  
-
135  
-    /**
136  
-     * Returns the maximum file count
137  
-     *
138  
-     * @return integer
139  
-     */
140  
-    public function getMax()
141  
-    {
142  
-        return $this->options['max'];
143  
-    }
144  
-
145  
-    /**
146  
-     * Sets the maximum file count
147  
-     *
148  
-     * @param  integer|array $max The maximum file count
149  
-     * @return Count Provides a fluent interface
150  
-     * @throws Exception\InvalidArgumentException When max is smaller than min
151  
-     */
152  
-    public function setMax($max)
153  
-    {
154  
-        if (is_array($max) and isset($max['max'])) {
155  
-            $max = $max['max'];
156  
-        }
157  
-
158  
-        if (!is_string($max) and !is_numeric($max)) {
159  
-            throw new Exception\InvalidArgumentException('Invalid options to validator provided');
160  
-        }
161  
-
162  
-        $max = (integer) $max;
163  
-        if (($this->getMin() !== null) && ($max < $this->getMin())) {
164  
-            throw new Exception\InvalidArgumentException("The maximum must be greater than or equal to the minimum file count, but "
165  
-                                            . "$max < {$this->getMin()}");
166  
-        }
167  
-
168  
-        $this->options['max'] = $max;
169  
-        return $this;
170  
-    }
171  
-
172  
-    /**
173  
-     * Adds a file for validation
174  
-     *
175  
-     * @param string|array $file
176  
-     * @return Count
177  
-     */
178  
-    public function addFile($file)
179  
-    {
180  
-        if (is_string($file)) {
181  
-            $file = array($file);
182  
-        }
183  
-
184  
-        if (is_array($file)) {
185  
-            foreach ($file as $name) {
186  
-                if (!isset($this->files[$name]) && !empty($name)) {
187  
-                    $this->files[$name] = $name;
188  
-                }
189  
-            }
190  
-        }
191  
-
192  
-        return $this;
193  
-    }
194  
-
195  
-    /**
196  
-     * Returns true if and only if the file count of all checked files is at least min and
197  
-     * not bigger than max (when max is not null). Attention: When checking with set min you
198  
-     * must give all files with the first call, otherwise you will get an false.
199  
-     *
200  
-     * @param  string|array $value Filenames to check for count
201  
-     * @param  array        $file  File data from \Zend\File\Transfer\Transfer
202  
-     * @return boolean
203  
-     */
204  
-    public function isValid($value, $file = null)
205  
-    {
206  
-        if (($file !== null) && !array_key_exists('destination', $file)) {
207  
-            $file['destination'] = dirname($value);
208  
-        }
209  
-
210  
-        if (($file !== null) && array_key_exists('tmp_name', $file)) {
211  
-            $value = $file['destination'] . DIRECTORY_SEPARATOR . $file['name'];
212  
-        }
213  
-
214  
-        if (($file === null) || !empty($file['tmp_name'])) {
215  
-            $this->addFile($value);
216  
-        }
217  
-
218  
-        $this->count = count($this->files);
219  
-        if (($this->getMax() !== null) && ($this->count > $this->getMax())) {
220  
-            return $this->throwError($file, self::TOO_MANY);
221  
-        }
222  
-
223  
-        if (($this->getMin() !== null) && ($this->count < $this->getMin())) {
224  
-            return $this->throwError($file, self::TOO_FEW);
225  
-        }
226  
-
227  
-        return true;
228  
-    }
229  
-
230  
-    /**
231  
-     * Throws an error of the given type
232  
-     *
233  
-     * @param  string $file
234  
-     * @param  string $errorType
235  
-     * @return false
236  
-     */
237  
-    protected function throwError($file, $errorType)
238  
-    {
239  
-        if ($file !== null) {
240  
-            if (is_array($file)) {
241  
-                if (array_key_exists('name', $file)) {
242  
-                    $this->value = $file['name'];
243  
-                }
244  
-            } elseif (is_string($file)) {
245  
-                $this->value = $file;
246  
-            }
247  
-        }
248  
-
249  
-        $this->error($errorType);
250  
-        return false;
251  
-    }
252  
-}
28  library/Zend/Validator/File/Crc32.php
@@ -29,9 +29,9 @@ class Crc32 extends Hash
29 29
      * @var array Error message templates
30 30
      */
31 31
     protected $messageTemplates = array(
32  
-        self::DOES_NOT_MATCH => "File '%value%' does not match the given crc32 hashes",
  32
+        self::DOES_NOT_MATCH => "File does not match the given crc32 hashes",
33 33
         self::NOT_DETECTED   => "A crc32 hash could not be evaluated for the given file",
34  
-        self::NOT_FOUND      => "File '%value%' is not readable or does not exist",
  34
+        self::NOT_FOUND      => "File is not readable or does not exist",
35 35
     );
36 36
 
37 37
     /**
@@ -81,25 +81,26 @@ public function addCrc32($options)
81 81
     /**
82 82
      * Returns true if and only if the given file confirms the set hash
83 83
      *
84  
-     * @param  string $value Filename to check for hash
85  
-     * @param  array  $file  File data from \Zend\File\Transfer\Transfer
  84
+     * @param  string|array $value Filename to check for hash
86 85
      * @return boolean
87 86
      */
88  
-    public function isValid($value, $file = null)
  87
+    public function isValid($value)
89 88
     {
90  
-        if ($file === null) {
91  
-            $file = array('name' => basename($value));
92  
-        }
  89
+        $file     = (isset($value['tmp_name'])) ? $value['tmp_name'] : $value;
  90
+        $filename = (isset($value['name']))     ? $value['name']     : basename($file);
  91
+        $this->setValue($filename);
93 92
 
94 93
         // Is file readable ?
95  
-        if (false === stream_resolve_include_path($value)) {
96  
-            return $this->throwError($file, self::NOT_FOUND);
  94
+        if (false === stream_resolve_include_path($file)) {
  95
+            $this->error(self::NOT_FOUND);
  96
+            return false;
97 97
         }
98 98
 
99 99
         $hashes = array_unique(array_keys($this->getHash()));
100  
-        $filehash = hash_file('crc32', $value);
  100
+        $filehash = hash_file('crc32', $file);
101 101
         if ($filehash === false) {
102  
-            return $this->throwError($file, self::NOT_DETECTED);
  102
+            $this->error(self::NOT_DETECTED);
  103
+            return false;
103 104
         }
104 105
 
105 106
         foreach ($hashes as $hash) {
@@ -108,6 +109,7 @@ public function isValid($value, $file = null)
108 109
             }
109 110
         }
110 111
 
111  
-        return $this->throwError($file, self::DOES_NOT_MATCH);
  112
+        $this->error(self::DOES_NOT_MATCH);
  113
+        return false;
112 114
     }
113 115
 }
44  library/Zend/Validator/File/ExcludeExtension.php
@@ -28,52 +28,46 @@ class ExcludeExtension extends Extension
28 28
      * @var array Error message templates
29 29
      */
30 30
     protected $messageTemplates = array(
31  
-        self::FALSE_EXTENSION => "File '%value%' has a false extension",
32  
-        self::NOT_FOUND       => "File '%value%' is not readable or does not exist",
  31
+        self::FALSE_EXTENSION => "File has an incorrect extension",
  32
+        self::NOT_FOUND       => "File is not readable or does not exist",
33 33
     );
34 34
 
35 35
     /**
36 36
      * Returns true if and only if the file extension of $value is not included in the
37 37
      * set extension list
38 38
      *
39  
-     * @param  string  $value Real file to check for extension
40  
-     * @param  array   $file  File data from \Zend\File\Transfer\Transfer
  39
+     * @param  string|array $value Real file to check for extension
41 40
      * @return boolean
42 41
      */
43  
-    public function isValid($value, $file = null)
  42
+    public function isValid($value)
44 43
     {
45  
-        if ($file === null) {
46  
-            $file = array('name' => basename($value));
47  
-        }
  44
+        $file     = (isset($value['tmp_name'])) ? $value['tmp_name'] : $value;
  45
+        $filename = (isset($value['name']))     ? $value['name']     : basename($file);
  46
+        $this->setValue($filename);
48 47
 
49 48
         // Is file readable ?
50  
-        if (false === stream_resolve_include_path($value)) {
51  
-            return $this->throwError($file, self::NOT_FOUND);
52  
-        }
53  
-
54  
-        if ($file !== null) {
55  
-            $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
56  
-        } else {
57  
-            $info = pathinfo($value);
  49
+        if (false === stream_resolve_include_path($file)) {
  50
+            $this->error(self::NOT_FOUND);
  51
+            return false;
58 52
         }
59 53
 
  54
+        $extension  = substr($filename, strrpos($filename, '.') + 1);
60 55
         $extensions = $this->getExtension();
61 56
 
62  
-        if ($this->getCase() and (!in_array($info['extension'], $extensions))) {
  57
+        if ($this->getCase() and (!in_array($extension, $extensions))) {
63 58
             return true;
64 59
         } elseif (!$this->getCase()) {
65  
-            $found = false;
66  
-            foreach ($extensions as $extension) {
67  
-                if (strtolower($extension) == strtolower($info['extension'])) {
68  
-                    $found = true;
  60
+            foreach ($extensions as $ext) {
  61
+                if (strtolower($ext) == strtolower($extension)) {
  62
+                    $this->error(self::FALSE_EXTENSION);
  63
+                    return false;
69 64
                 }
70 65
             }
71 66
 
72  
-            if (!$found) {
73  
-                return true;
74  
-            }
  67
+            return true;
75 68
         }
76 69
 
77  
-        return $this->throwError($file, self::FALSE_EXTENSION);
  70
+        $this->error(self::FALSE_EXTENSION);
  71
+        return false;
78 72
     }
79 73
 }
35  library/Zend/Validator/File/ExcludeMimeType.php
@@ -29,22 +29,20 @@ class ExcludeMimeType extends MimeType
29 29
      * of mimetypes can be checked. If you give for example "image" all image
30 30
      * mime types will not be accepted like "image/gif", "image/jpeg" and so on.
31 31
      *
32  
-     * @param  string $value Real file to check for mimetype
33  
-     * @param  array  $file  File data from \Zend\File\Transfer\Transfer
  32
+     * @param  string|array $value Real file to check for mimetype
34 33
      * @return boolean
35 34
      */
36  
-    public function isValid($value, $file = null)
  35
+    public function isValid($value)
37 36
     {
38  
-        if ($file === null) {
39  
-            $file = array(
40  
-                'type' => null,
41  
-                'name' => $value,
42  
-            );
43  
-        }
  37
+        $file     = (isset($value['tmp_name'])) ? $value['tmp_name'] : $value;
  38
+        $filename = (isset($value['name']))     ? $value['name']     : basename($file);
  39
+        $filetype = (isset($value['type']))     ? $value['type']     : null;
  40
+        $this->setValue($filename);
44 41
 
45 42
         // Is file readable ?
46  
-        if (false === stream_resolve_include_path($value)) {
47  
-            return $this->createError($file, self::NOT_READABLE);
  43
+        if (false === stream_resolve_include_path($file)) {
  44
+            $this->error(self::NOT_READABLE);
  45
+            return false;
48 46
         }
49 47
 
50 48
         $mimefile = $this->getMagicFile();
@@ -60,27 +58,29 @@ public function isValid($value, $file = null)
60 58
 
61 59
             $this->type = null;
62 60
             if (!empty($this->finfo)) {
63  
-                $this->type = finfo_file($this->finfo, $value);
  61
+                $this->type = finfo_file($this->finfo, $file);
64 62
             }
65 63
         }
66 64
 
67 65
         if (empty($this->type) &&
68 66
             (function_exists('mime_content_type') && ini_get('mime_magic.magicfile'))
69 67
         ) {
70  
-            $this->type = mime_content_type($value);
  68
+            $this->type = mime_content_type($file);
71 69
         }
72 70
 
73 71
         if (empty($this->type) && $this->getHeaderCheck()) {
74  
-            $this->type = $file['type'];
  72
+            $this->type = $filetype;
75 73
         }
76 74
 
77 75
         if (empty($this->type)) {
78  
-            return $this->createError($file, self::NOT_DETECTED);
  76
+            $this->error(self::NOT_DETECTED);
  77
+            false;
79 78
         }
80 79
 
81 80
         $mimetype = $this->getMimeType(true);
82 81
         if (in_array($this->type, $mimetype)) {
83  
-            return $this->createError($file, self::FALSE_TYPE);
  82
+            $this->error(self::FALSE_TYPE);
  83
+            return false;
84 84
         }
85 85
 
86 86
         $types = explode('/', $this->type);
@@ -88,7 +88,8 @@ public function isValid($value, $file = null)
88 88
         $types = array_merge($types, explode(';', $this->type));
89 89
         foreach ($mimetype as $mime) {
90 90
             if (in_array($mime, $types)) {
91  
-                return $this->createError($file, self::FALSE_TYPE);
  91
+                $this->error(self::FALSE_TYPE);
  92
+                return false;
92 93
             }
93 94
         }
94 95
 
50  library/Zend/Validator/File/Exists.php
@@ -30,7 +30,7 @@ class Exists extends AbstractValidator
30 30
      * @var array Error message templates
31 31
      */
32 32
     protected $messageTemplates = array(
33  
-        self::DOES_NOT_EXIST => "File '%value%' does not exist",
  33
+        self::DOES_NOT_EXIST => "File does not exist",
34 34
     );
35 35
 
36 36
     /**
@@ -138,58 +138,34 @@ public function addDirectory($directory)
138 138
     /**
139 139
      * Returns true if and only if the file already exists in the set directories
140 140
      *
141  
-     * @param  string  $value Real file to check for existence
142  
-     * @param  array   $file  File data from \Zend\File\Transfer\Transfer
  141
+     * @param  string|array $value Real file to check for existence
143 142
      * @return boolean
144 143
      */
145  
-    public function isValid($value, $file = null)
  144
+    public function isValid($value)
146 145
     {
147  
-        $directories = $this->getDirectory(true);
148  
-        if (($file !== null) and (!empty($file['destination']))) {
149  
-            $directories[] = $file['destination'];
150  
-        } elseif (!isset($file['name'])) {
151  
-            $file['name'] = $value;
152  
-        }
  146
+        $file     = (isset($value['tmp_name'])) ? $value['tmp_name'] : $value;
  147
+        $filename = (isset($value['name']))     ? $value['name']     : basename($file);
  148
+        $this->setValue($filename);
153 149
 
154 150
         $check = false;
  151
+        $directories = $this->getDirectory(true);
155 152
         foreach ($directories as $directory) {
156  
-            if (empty($directory)) {
  153
+            if (!isset($directory) || '' === $directory) {
157 154
                 continue;
158 155
             }
159 156
 
160 157
             $check = true;
161  
-            if (!file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) {
162  
-                return $this->throwError($file, self::DOES_NOT_EXIST);
  158
+            if (!file_exists($directory . DIRECTORY_SEPARATOR . $filename)) {
  159
+                $this->error(self::DOES_NOT_EXIST);
  160
+                return false;
163 161
             }
164 162
         }
165 163
 
166 164
         if (!$check) {
167  
-            return $this->throwError($file, self::DOES_NOT_EXIST);
  165
+            $this->error(self::DOES_NOT_EXIST);
  166
+            return false;
168 167
         }
169 168
 
170 169
         return true;
171 170
     }
172  
-
173  
-    /**
174  
-     * Throws an error of the given type
175  
-     *
176  
-     * @param  string $file
177  
-     * @param  string $errorType
178  
-     * @return false
179  
-     */
180  
-    protected function throwError($file, $errorType)
181  
-    {
182  
-        if ($file !== null) {
183  
-            if (is_array($file)) {
184  
-                if (array_key_exists('name', $file)) {
185  
-                    $this->value = basename($file['name']);
186  
-                }
187  
-            } elseif (is_string($file)) {
188  
-                $this->value = basename($file);
189  
-            }
190  
-        }
191  
-
192  
-        $this->error($errorType);
193  
-        return false;
194  
-    }
195 171
 }
61  library/Zend/Validator/File/Extension.php
@@ -32,8 +32,8 @@ class Extension extends AbstractValidator
32 32
      * @var array Error message templates
33 33
      */
34 34
     protected $messageTemplates = array(
35  
-        self::FALSE_EXTENSION => "File '%value%' has a false extension",
36  
-        self::NOT_FOUND       => "File '%value%' is not readable or does not exist",
  35
+        self::FALSE_EXTENSION => "File has an incorrect extension",
  36
+        self::NOT_FOUND       => "File is not readable or does not exist",
37 37
     );
38 38
 
39 39
     /**
@@ -42,8 +42,8 @@ class Extension extends AbstractValidator
42 42
      * @var array
43 43
      */
44 44
     protected $options = array(
45  
-        'case' => false,   // Validate case sensitive
46  
-        'extension' => '', // List of extensions
  45
+        'case'      => false,   // Validate case sensitive
  46
+        'extension' => '',      // List of extensions
47 47
     );
48 48
 
49 49
     /**
@@ -174,62 +174,35 @@ public function addExtension($extension)
174 174
      * Returns true if and only if the file extension of $value is included in the
175 175
      * set extension list
176 176
      *
177  
-     * @param  string  $value Real file to check for extension
178  
-     * @param  array   $file  File data from \Zend\File\Transfer\Transfer
  177
+     * @param  string|array $value Real file to check for extension
179 178
      * @return boolean
180 179
      */
181  
-    public function isValid($value, $file = null)
  180
+    public function isValid($value)
182 181
     {
183  
-        if ($file === null) {
184  
-            $file = array('name' => basename($value));
185  
-        }
  182
+        $file     = (isset($value['tmp_name'])) ? $value['tmp_name'] : $value;
  183
+        $filename = (isset($value['name']))     ? $value['name']     : basename($file);
  184
+         $this->setValue($filename);
186 185
 
187 186
         // Is file readable ?
188  
-        if (false === stream_resolve_include_path($value)) {
189  
-            return $this->throwError($file, self::NOT_FOUND);
190  
-        }
191  
-
192  
-        if ($file !== null) {
193  
-            $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
194  
-        } else {
195  
-            $info = pathinfo($value);
  187
+        if (false === stream_resolve_include_path($file)) {
  188
+            $this->error(self::NOT_FOUND);
  189
+            return false;
196 190
         }
197 191
 
  192
+        $extension  = substr($filename, strrpos($filename, '.') + 1);
198 193
         $extensions = $this->getExtension();
199 194
 
200  
-        if ($this->getCase() && (in_array($info['extension'], $extensions))) {
  195
+        if ($this->getCase() && (in_array($extension, $extensions))) {
201 196
             return true;
202 197
         } elseif (!$this->getCase()) {
203  
-            foreach ($extensions as $extension) {
204  
-                if (strtolower($extension) == strtolower($info['extension'])) {
  198
+            foreach ($extensions as $ext) {
  199
+                if (strtolower($ext) == strtolower($extension)) {
205 200
                     return true;
206 201
                 }
207 202
             }
208 203
         }
209 204
 
210  
-        return $this->throwError($file, self::FALSE_EXTENSION);
211  
-    }
212  
-
213  
-    /**
214  
-     * Throws an error of the given type
215  
-     *
216  
-     * @param  string $file
217  
-     * @param  string $errorType
218  
-     * @return false
219  
-     */
220  
-    protected function throwError($file, $errorType)
221  
-    {
222  
-        if ($file !== null) {
223  
-            if (is_array($file)) {
224  
-                if (array_key_exists('name', $file)) {
225  
-                    $this->value = $file['name'];
226  
-                }
227  
-            } elseif (is_string($file)) {
228  
-                $this->value = $file;
229  
-            }
230  
-        }
231  
-
232  
-        $this->error($errorType);
  205
+        $this->error(self::FALSE_EXTENSION);
233 206
         return false;
234 207
     }
235 208
 }
151  library/Zend/Validator/File/FilesSize.php
... ...
@@ -1,151 +0,0 @@
1  
-<?php
2  
-/**
3  
- * Zend Framework (http://framework.zend.com/)
4  
- *
5  
- * @link      http://github.com/zendframework/zf2 for the canonical source repository
6  
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
7  
- * @license   http://framework.zend.com/license/new-bsd New BSD License
8  
- * @package   Zend_Validator
9  
- */
10  
-
11  
-namespace Zend\Validator\File;
12  
-
13  
-use Traversable;
14  
-use Zend\Stdlib\ArrayUtils;
15  
-use Zend\Stdlib\ErrorHandler;
16  
-use Zend\Validator\Exception;
17  
-
18  
-/**
19  
- * Validator for the size of all files which will be validated in sum
20  
- *
21  
- * @category  Zend
22  
- * @package   Zend_Validator
23  
- */
24  
-class FilesSize extends Size
25  
-{
26  
-    /**
27  
-     * @const string Error constants
28  
-     */
29  
-    const TOO_BIG      = 'fileFilesSizeTooBig';
30  
-    const TOO_SMALL    = 'fileFilesSizeTooSmall';
31  
-    const NOT_READABLE = 'fileFilesSizeNotReadable';
32  
-
33  
-    /**
34  
-     * @var array Error message templates
35  
-     */
36  
-    protected $messageTemplates = array(
37  
-        self::TOO_BIG      => "All files in sum should have a maximum size of '%max%' but '%size%' were detected",
38  
-        self::TOO_SMALL    => "All files in sum should have a minimum size of '%min%' but '%size%' were detected",
39  
-        self::NOT_READABLE => "One or more files can not be read",
40  
-    );
41  
-
42  
-    /**
43  
-     * Internal file array
44  
-     *
45  
-     * @var array
46  
-     */
47  
-    protected $files;
48  
-
49  
-    /**
50  
-     * Sets validator options
51  
-     *
52  
-     * Min limits the used disk space for all files, when used with max=null it is the maximum file size
53  
-     * It also accepts an array with the keys 'min' and 'max'
54  
-     *
55  
-     * @param  integer|array|Traversable $options Options for this validator
56  
-     * @throws \Zend\Validator\Exception\InvalidArgumentException
57  
-     */
58  
-    public function __construct($options = null)
59  
-    {
60  
-        $this->files = array();
61  
-        $this->setSize(0);
62  
-
63  
-        if ($options instanceof Traversable) {
64  
-            $options = ArrayUtils::iteratorToArray($options);
65  
-        } elseif (is_scalar($options)) {
66  
-            $options = array('max' => $options);
67  
-        } elseif (!is_array($options)) {
68  
-            throw new Exception\InvalidArgumentException('Invalid options to validator provided');
69  
-        }
70  
-
71  
-        if (1 < func_num_args()) {
72  
-            $argv = func_get_args();
73  
-            array_shift($argv);
74  
-            $options['max'] = array_shift($argv);
75  
-            if (!empty($argv)) {
76  
-                $options['useByteString'] = array_shift($argv);
77  
-            }
78  
-        }
79  
-
80  
-        parent::__construct($options);
81  
-    }
82  
-
83  
-    /**
84  
-     * Returns true if and only if the disk usage of all files is at least min and
85  
-     * not bigger than max (when max is not null).
86  
-     *
87  
-     * @param  string|array $value Real file to check for size
88  
-     * @param  array        $file  File data from \Zend\File\Transfer\Transfer
89  
-     * @return boolean
90  
-     */
91  
-    public function isValid($value, $file = null)
92  
-    {
93  
-        if (is_string($value)) {
94  
-            $value = array($value);
95  
-        }
96  
-
97  
-        $min  = $this->getMin(true);
98  
-        $max  = $this->getMax(true);
99  
-        $size = $this->getSize();
100  
-        foreach ($value as $files) {
101  
-            // Is file readable ?
102  
-            if (false === stream_resolve_include_path($files)) {
103  
-                $this->throwError($file, self::NOT_READABLE);
104  
-                continue;
105  
-            }
106  
-
107  
-            if (!isset($this->files[$files])) {
108  
-                $this->files[$files] = $files;
109  
-            } else {
110  
-                // file already counted... do not count twice
111  
-                continue;
112  
-            }
113  
-
114  
-            // limited to 2GB files
115  
-            ErrorHandler::start();
116  
-            $size += filesize($files);
117  
-            ErrorHandler::stop();
118  
-            $this->size = $size;
119  
-            if (($max !== null) && ($max < $size)) {
120  
-                if ($this->getByteString()) {
121  
-                    $this->options['max'] = $this->toByteString($max);
122  
-                    $this->size          = $this->toByteString($size);
123  
-                    $this->throwError($file, self::TOO_BIG);
124  
-                    $this->options['max'] = $max;
125  
-                    $this->size          = $size;
126  
-                } else {
127  
-                    $this->throwError($file, self::TOO_BIG);
128  
-                }
129  
-            }
130  
-        }
131  
-
132  
-        // Check that aggregate files are >= minimum size
133  
-        if (($min !== null) && ($size < $min)) {
134  
-            if ($this->getByteString()) {
135  
-                $this->options['min'] = $this->toByteString($min);
136  
-                $this->size          = $this->toByteString($size);
137  
-                $this->throwError($file, self::TOO_SMALL);
138  
-                $this->options['min'] = $min;
139  
-                $this->size          = $size;
140  
-            } else {
141  
-                $this->throwError($file, self::TOO_SMALL);
142  
-            }
143  
-        }
144  
-
145  
-        if (count($this->getMessages()) > 0) {
146  
-            return false;
147  
-        }
148  
-
149  
-        return true;
150  
-    }
151  
-}
49  library/Zend/Validator/File/Hash.php
@@ -32,9 +32,9 @@ class Hash extends AbstractValidator
32 32
      * @var array Error message templates
33 33
      */
34 34
     protected $messageTemplates = array(
35  
-        self::DOES_NOT_MATCH => "File '%value%' does not match the given hashes",
  35
+        self::DOES_NOT_MATCH => "File does not match the given hashes",
36 36
         self::NOT_DETECTED   => "A hash could not be evaluated for the given file",
37  
-        self::NOT_FOUND      => "File '%value%' is not readable or does not exist"
  37
+        self::NOT_FOUND      => "File is not readable or does not exist"
38 38
     );
39 39
 
40 40
     /**
@@ -127,27 +127,28 @@ public function addHash($options)
127 127
     /**
128 128
      * Returns true if and only if the given file confirms the set hash
129 129
      *
130  
-     * @param  string $value Filename to check for hash
131  
-     * @param  array  $file  File data from \Zend\File\Transfer\Transfer
  130
+     * @param  string|array $value File to check for hash
132 131
      * @return boolean
133 132
      */
134  
-    public function isValid($value, $file = null)
  133
+    public function isValid($value)
135 134
     {
136  
-        if ($file === null) {
137  
-            $file = array('name' => basename($value));
138  
-        }
  135
+        $file     = (isset($value['tmp_name'])) ? $value['tmp_name'] : $value;
  136
+        $filename = (isset($value['name']))     ? $value['name']     : basename($file);
  137
+        $this->setValue($filename);
139 138
 
140 139
         // Is file readable ?
141  
-        if (false === stream_resolve_include_path($value)) {
142  
-            return $this->throwError($file, self::NOT_FOUND);
  140
+        if (false === stream_resolve_include_path($file)) {
  141
+            $this->error(self::NOT_FOUND);
  142
+            return false;
143 143
         }
144 144
 
145 145
         $algos  = array_unique(array_values($this->getHash()));
146 146
         $hashes = array_unique(array_keys($this->getHash()));
147 147
         foreach ($algos as $algorithm) {
148  
-            $filehash = hash_file($algorithm, $value);
  148
+            $filehash = hash_file($algorithm, $file);
149 149
             if ($filehash === false) {
150  
-                return $this->throwError($file, self::NOT_DETECTED);
  150
+                $this->error(self::NOT_DETECTED);
  151
+                return false;
151 152
             }
152 153
 
153 154
             foreach ($hashes as $hash) {
@@ -157,29 +158,7 @@ public function isValid($value, $file = null)
157 158
             }
158 159
         }
159 160
 
160  
-        return $this->throwError($file, self::DOES_NOT_MATCH);
161  
-    }
162  
-
163  
-    /**
164  
-     * Throws an error of the given type
165  
-     *
166  
-     * @param  string $file
167  
-     * @param  string $errorType
168  
-     * @return false
169  
-     */
170  
-    protected function throwError($file, $errorType)
171  
-    {
172  
-        if ($file !== null) {
173  
-            if (is_array($file)) {
174  
-                if (array_key_exists('name', $file)) {
175  
-                    $this->value = $file['name'];
176  
-                }
177  
-            } elseif (is_string($file)) {
178  
-                $this->value = $file;
179  
-            }
180  
-        }
181  
-
182  
-        $this->error($errorType);
  161
+        $this->error(self::DOES_NOT_MATCH);
183 162
         return false;
184 163
     }
185 164
 }
65  library/Zend/Validator/File/ImageSize.php
@@ -36,12 +36,12 @@ class ImageSize extends AbstractValidator
36 36
      * @var array Error message template
37 37
      */
38 38
     protected $messageTemplates = array(
39  
-        self::WIDTH_TOO_BIG    => "Maximum allowed width for image '%value%' should be '%maxwidth%' but '%width%' detected",
40  
-        self::WIDTH_TOO_SMALL  => "Minimum expected width for image '%value%' should be '%minwidth%' but '%width%' detected",
41  
-        self::HEIGHT_TOO_BIG   => "Maximum allowed height for image '%value%' should be '%maxheight%' but '%height%' detected",
42  
-        self::HEIGHT_TOO_SMALL => "Minimum expected height for image '%value%' should be '%minheight%' but '%height%' detected",
43  
-        self::NOT_DETECTED     => "The size of image '%value%' could not be detected",
44  
-        self::NOT_READABLE     => "File '%value%' is not readable or does not exist",
  39
+        self::WIDTH_TOO_BIG    => "Maximum allowed width for image should be '%maxwidth%' but '%width%' detected",
  40
+        self::WIDTH_TOO_SMALL  => "Minimum expected width for image should be '%minwidth%' but '%width%' detected",
  41
+        self::HEIGHT_TOO_BIG   => "Maximum allowed height for image should be '%maxheight%' but '%height%' detected",
  42
+        self::HEIGHT_TOO_SMALL => "Minimum expected height for image should be '%minheight%' but '%height%' detected",
  43
+        self::NOT_DETECTED     => "The size of image could not be detected",
  44
+        self::NOT_READABLE     => "File is not readable or does not exist",
45 45
     );
46 46
 
47 47
     /**
@@ -322,46 +322,46 @@ public function setImageHeight($options)
322 322
      * Returns true if and only if the image size of $value is at least min and
323 323
      * not bigger than max
324 324
      *
325  
-     * @param  string $value Real file to check for image size
326  
-     * @param  array  $file  File data from \Zend\File\Transfer\Transfer
  325
+     * @param  string|array $value Real file to check for image size
327 326
      * @return boolean
328 327
      */
329  
-    public function isValid($value, $file = null)
  328
+    public function isValid($value)
330 329
     {
331  
-        if ($file === null) {
332  
-            $file = array('name' => basename($value));
333  
-        }
  330
+        $file     = (isset($value['tmp_name'])) ? $value['tmp_name'] : $value;
  331
+        $filename = (isset($value['name']))     ? $value['name']     : basename($file);
  332
+        $this->setValue($filename);
334 333
 
335 334
         // Is file readable ?
336  
-        if (false === stream_resolve_include_path($value)) {
337  
-            return $this->throwError($file, self::NOT_READABLE);
  335
+        if (false === stream_resolve_include_path($file)) {
  336
+            $this->error(self::NOT_READABLE);
  337
+            return false;
338 338
         }
339 339
 
340 340
         ErrorHandler::start();
341  
-        $size = getimagesize($value);
  341
+        $size = getimagesize($file);
342 342
         ErrorHandler::stop();
343  
-        $this->setValue($file);
344 343
 
345 344
         if (empty($size) or ($size[0] === 0) or ($size[1] === 0)) {
346  
-            return $this->throwError($file, self::NOT_DETECTED);
  345
+            $this->error(self::NOT_DETECTED);
  346
+            return false;
347 347
         }
348 348
 
349 349
         $this->width  = $size[0];
350 350
         $this->height = $size[1];
351 351
         if ($this->width < $this->getMinWidth()) {
352  
-            $this->throwError($file, self::WIDTH_TOO_SMALL);
  352
+            $this->error(self::WIDTH_TOO_SMALL);
353 353
         }
354 354
 
355 355
         if (($this->getMaxWidth() !== null) and ($this->getMaxWidth() < $this->width)) {
356  
-            $this->throwError($file, self::WIDTH_TOO_BIG);
  356
+            $this->error(self::WIDTH_TOO_BIG);
357 357
         }
358 358
 
359 359
         if ($this->height < $this->getMinHeight()) {
360  
-            $this->throwError($file, self::HEIGHT_TOO_SMALL);
  360
+            $this->error(self::HEIGHT_TOO_SMALL);
361 361
         }
362 362
 
363 363
         if (($this->getMaxHeight() !== null) and ($this->getMaxHeight() < $this->height)) {
364  
-            $this->throwError($file, self::HEIGHT_TOO_BIG);
  364
+            $this->error(self::HEIGHT_TOO_BIG);
365 365
         }
366 366
 
367 367
         if (count($this->getMessages()) > 0) {
@@ -370,27 +370,4 @@ public function isValid($value, $file = null)
370 370
 
371 371
         return true;
372 372
     }
373  
-
374  
-    /**
375  
-     * Throws an error of the given type
376  
-     *
377  
-     * @param  string $file
378  
-     * @param  string $errorType
379  
-     * @return false
380  
-     */
381  
-    protected function throwError($file, $errorType)
382  
-    {
383  
-        if ($file !== null) {
384  
-            if (is_array($file)) {
385  
-                if (array_key_exists('name', $file)) {
386  
-                    $this->value = $file['name'];
387  
-                }
388  
-            } elseif (is_string($file)) {
389  
-                $this->value = $file;
390  
-            }
391  
-        }
392  
-
393  
-        $this->error($errorType);
394  
-        return false;
395  
-    }
396 373
 }
44  library/Zend/Validator/File/IsCompressed.php
@@ -32,9 +32,9 @@ class IsCompressed extends MimeType
32 32
      * @var array Error message templates
33 33
      */
34 34
     protected $messageTemplates = array(
35  
-        self::FALSE_TYPE   => "File '%value%' is not compressed, '%type%' detected",
36  
-        self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected",
37  
-        self::NOT_READABLE => "File '%value%' is not readable or does not exist",
  35
+        self::FALSE_TYPE   => "File is not compressed, '%type%' detected",
  36
+        self::NOT_DETECTED => "The mimetype could not be detected from the file",
  37
+        self::NOT_READABLE => "File is not readable or does not exist",
38 38
     );
39 39
 
40 40
     /**
@@ -89,42 +89,4 @@ public function __construct($options = array())
89 89
 
90 90
         parent::__construct($options);
91 91
     }
92  
-
93  
-    /**
94  
-     * Throws an error of the given type
95  
-     * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2
96  
-     *
97  
-     * @param  string $file
98  
-     * @param  string $errorType
99  
-     * @return false
100  
-     */
101  
-    protected function createError($file, $errorType)
102  
-    {
103  
-        if ($file !== null) {
104  
-            if (is_array($file)) {
105  
-                if (array_key_exists('name', $file)) {
106  
-                    $file = $file['name'];
107  
-                }
108  
-            }
109  
-
110  
-            if (is_string($file)) {
111  
-                $this->value = basename($file);
112  
-            }
113  
-        }
114  
-
115  
-        switch ($errorType) {
116  
-            case MimeType::FALSE_TYPE :
117  
-                $errorType = self::FALSE_TYPE;
118  
-                break;
119  
-            case MimeType::NOT_DETECTED :
120  
-                $errorType = self::NOT_DETECTED;
121  
-                break;
122  
-            case MimeType::NOT_READABLE :
123  
-                $errorType = self::NOT_READABLE;
124  
-                break;
125  
-        }
126  
-
127  
-        $this->error($errorType);
128  
-        return false;
129  
-    }
130 92
 }
44  library/Zend/Validator/File/IsImage.php
@@ -32,9 +32,9 @@ class IsImage extends MimeType
32 32
      * @var array Error message templates
33 33
      */
34 34
     protected $messageTemplates = array(
35  
-        self::FALSE_TYPE   => "File '%value%' is no image, '%type%' detected",
36  
-        self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected",
37  
-        self::NOT_READABLE => "File '%value%' is not readable or does not exist",
  35
+        self::FALSE_TYPE   => "File is no image, '%type%' detected",
  36
+        self::NOT_DETECTED => "The mimetype could not be detected from the file",
  37
+        self::NOT_READABLE => "File is not readable or does not exist",
38 38
     );
39 39
 
40 40
     /**
@@ -114,42 +114,4 @@ public function __construct($options = array())
114 114
 
115 115
         parent::__construct($options);
116 116
     }
117  
-
118  
-    /**
119  
-     * Throws an error of the given type
120  
-     * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2
121  
-     *