9
9
10
10
namespace Zend \InputFilter ;
11
11
12
- use Zend \Validator \File \UploadFile as UploadValidator ;
13
-
14
12
/**
15
13
* FileInput is a special Input type for handling uploaded files.
16
14
*
21
19
* 2. The validators are run **before** the filters (the opposite behavior of Input).
22
20
* This is so is_uploaded_file() validation can be run prior to any filters that
23
21
* may rename/move/modify the file.
24
- *
25
- * 3. Instead of adding a NotEmpty validator, it will (by default) automatically add
26
- * a Zend\Validator\File\Upload validator.
27
22
*/
28
23
class FileInput extends Input
29
24
{
@@ -32,29 +27,6 @@ class FileInput extends Input
32
27
*/
33
28
protected $ isValid = false ;
34
29
35
- /**
36
- * @var bool
37
- */
38
- protected $ autoPrependUploadValidator = true ;
39
-
40
- /**
41
- * @param bool $value Enable/Disable automatically prepending an Upload validator
42
- * @return FileInput
43
- */
44
- public function setAutoPrependUploadValidator ($ value )
45
- {
46
- $ this ->autoPrependUploadValidator = $ value ;
47
- return $ this ;
48
- }
49
-
50
- /**
51
- * @return bool
52
- */
53
- public function getAutoPrependUploadValidator ()
54
- {
55
- return $ this ->autoPrependUploadValidator ;
56
- }
57
-
58
30
/**
59
31
* @return mixed
60
32
*/
@@ -83,29 +55,6 @@ public function getValue()
83
55
return $ value ;
84
56
}
85
57
86
- /**
87
- * Checks if the raw input value is an empty file input eg: no file was uploaded
88
- *
89
- * @param $rawValue
90
- * @return bool
91
- */
92
- public function isEmptyFile ($ rawValue )
93
- {
94
- if (!is_array ($ rawValue )) {
95
- return true ;
96
- }
97
-
98
- if (isset ($ rawValue ['error ' ]) && $ rawValue ['error ' ] === UPLOAD_ERR_NO_FILE ) {
99
- return true ;
100
- }
101
-
102
- if (count ($ rawValue ) === 1 && isset ($ rawValue [0 ])) {
103
- return $ this ->isEmptyFile ($ rawValue [0 ]);
104
- }
105
-
106
- return false ;
107
- }
108
-
109
58
/**
110
59
* @param mixed $context Extra "context" to provide the validator
111
60
* @return bool
@@ -114,10 +63,7 @@ public function isValid($context = null)
114
63
{
115
64
$ rawValue = $ this ->getRawValue ();
116
65
$ hasValue = $ this ->hasValue ();
117
- $ empty = $ this ->isEmptyFile ($ rawValue );
118
66
$ required = $ this ->isRequired ();
119
- $ allowEmpty = $ this ->allowEmpty ();
120
- $ continueIfEmpty = $ this ->continueIfEmpty ();
121
67
122
68
if (! $ hasValue && ! $ required ) {
123
69
return true ;
@@ -130,15 +76,6 @@ public function isValid($context = null)
130
76
return false ;
131
77
}
132
78
133
- if ($ empty && ! $ required && ! $ continueIfEmpty ) {
134
- return true ;
135
- }
136
-
137
- if ($ empty && $ allowEmpty && ! $ continueIfEmpty ) {
138
- return true ;
139
- }
140
-
141
- $ this ->injectUploadValidator ();
142
79
$ validator = $ this ->getValidatorChain ();
143
80
//$value = $this->getValue(); // Do not run the filters yet for File uploads (see getValue())
144
81
@@ -168,53 +105,4 @@ public function isValid($context = null)
168
105
169
106
return $ this ->isValid ;
170
107
}
171
-
172
- /**
173
- * @return void
174
- */
175
- protected function injectUploadValidator ()
176
- {
177
- if (!$ this ->autoPrependUploadValidator ) {
178
- return ;
179
- }
180
- $ chain = $ this ->getValidatorChain ();
181
-
182
- // Check if Upload validator is already first in chain
183
- $ validators = $ chain ->getValidators ();
184
- if (isset ($ validators [0 ]['instance ' ])
185
- && $ validators [0 ]['instance ' ] instanceof UploadValidator
186
- ) {
187
- $ this ->autoPrependUploadValidator = false ;
188
- return ;
189
- }
190
-
191
- $ chain ->prependByName ('fileuploadfile ' , [], true );
192
- $ this ->autoPrependUploadValidator = false ;
193
- }
194
-
195
- /**
196
- * @deprecated 2.4.8 See note on parent class. Removal does not affect this class.
197
- *
198
- * No-op, NotEmpty validator does not apply for FileInputs.
199
- * See also: BaseInputFilter::isValid()
200
- *
201
- * @return void
202
- */
203
- protected function injectNotEmptyValidator ()
204
- {
205
- $ this ->notEmptyValidator = true ;
206
- }
207
-
208
- /**
209
- * @param InputInterface $input
210
- * @return FileInput
211
- */
212
- public function merge (InputInterface $ input )
213
- {
214
- parent ::merge ($ input );
215
- if ($ input instanceof FileInput) {
216
- $ this ->setAutoPrependUploadValidator ($ input ->getAutoPrependUploadValidator ());
217
- }
218
- return $ this ;
219
- }
220
108
}
0 commit comments