99
1010namespace Zend \InputFilter ;
1111
12- use Zend \Validator \File \UploadFile as UploadValidator ;
13-
1412/**
1513 * FileInput is a special Input type for handling uploaded files.
1614 *
2119 * 2. The validators are run **before** the filters (the opposite behavior of Input).
2220 * This is so is_uploaded_file() validation can be run prior to any filters that
2321 * 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.
2722 */
2823class FileInput extends Input
2924{
@@ -32,29 +27,6 @@ class FileInput extends Input
3227 */
3328 protected $ isValid = false ;
3429
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-
5830 /**
5931 * @return mixed
6032 */
@@ -83,29 +55,6 @@ public function getValue()
8355 return $ value ;
8456 }
8557
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-
10958 /**
11059 * @param mixed $context Extra "context" to provide the validator
11160 * @return bool
@@ -114,10 +63,7 @@ public function isValid($context = null)
11463 {
11564 $ rawValue = $ this ->getRawValue ();
11665 $ hasValue = $ this ->hasValue ();
117- $ empty = $ this ->isEmptyFile ($ rawValue );
11866 $ required = $ this ->isRequired ();
119- $ allowEmpty = $ this ->allowEmpty ();
120- $ continueIfEmpty = $ this ->continueIfEmpty ();
12167
12268 if (! $ hasValue && ! $ required ) {
12369 return true ;
@@ -130,15 +76,6 @@ public function isValid($context = null)
13076 return false ;
13177 }
13278
133- if ($ empty && ! $ required && ! $ continueIfEmpty ) {
134- return true ;
135- }
136-
137- if ($ empty && $ allowEmpty && ! $ continueIfEmpty ) {
138- return true ;
139- }
140-
141- $ this ->injectUploadValidator ();
14279 $ validator = $ this ->getValidatorChain ();
14380 //$value = $this->getValue(); // Do not run the filters yet for File uploads (see getValue())
14481
@@ -168,53 +105,4 @@ public function isValid($context = null)
168105
169106 return $ this ->isValid ;
170107 }
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- }
220108}
0 commit comments