This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop' into develop
- Loading branch information
78 parents
c91b8cb
+
442a604
+
ce86130
+
6a17c00
+
3be35a1
+
b101693
+
38a8855
+
2503264
+
1330305
+
c63994b
+
0cebe75
+
88437dd
+
335a7e0
+
49f818c
+
94c6248
+
babc2b3
+
c5537ad
+
a278174
+
ee91e56
+
f730475
+
e954d31
+
aa83987
+
4272527
+
760e014
+
8f9644f
+
89ddc85
+
ef5a070
+
af19258
+
363ebe6
+
774ea64
+
db99c7e
+
fb3727c
+
d8ea42f
+
a5c0289
+
9730940
+
ebc1a56
+
1d8cf16
+
09b3859
+
efe96d1
+
acf177c
+
7a7f261
+
df4c86b
+
4d14dd3
+
d0b7057
+
c858228
+
8855a3f
+
956acc6
+
085a083
+
99b3987
+
59e9d17
+
edd16d1
+
17ad876
+
401ed50
+
f43d222
+
73ebfdd
+
da15c07
+
4652c73
+
6a7b288
+
93b11b3
+
d67242e
+
be0deed
+
c16475f
+
68c3d64
+
537f455
+
e79de85
+
0cbbdec
+
3e0855f
+
a7a27db
+
779ae47
+
5ef112f
+
7ea9722
+
e951b83
+
37c7404
+
e730f97
+
43752c5
+
ba32611
+
7c15be9
+
e3a9518
commit cc9ba24
Showing
10 changed files
with
812 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_InputFilter | ||
*/ | ||
|
||
namespace Zend\InputFilter; | ||
|
||
use Zend\Validator\File\Upload as UploadValidator; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_InputFilter | ||
*/ | ||
class FileInput extends Input | ||
{ | ||
/** | ||
* @var boolean | ||
*/ | ||
protected $isValid = false; | ||
|
||
/** | ||
* @var boolean | ||
*/ | ||
protected $autoPrependUploadValidator = true; | ||
|
||
/** | ||
* @param boolean $value Enable/Disable automatically prepending an Upload validator | ||
* @return FileInput | ||
*/ | ||
public function setAutoPrependUploadValidator($value) | ||
{ | ||
$this->autoPrependUploadValidator = $value; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function getAutoPrependUploadValidator() | ||
{ | ||
return $this->autoPrependUploadValidator; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getValue() | ||
{ | ||
$filter = $this->getFilterChain(); | ||
$value = (is_array($this->value) && isset($this->value['tmp_name'])) | ||
? $this->value['tmp_name'] : $this->value; | ||
if (is_scalar($value) && $this->isValid) { | ||
// Single file input | ||
$value = $filter->filter($value); | ||
} elseif (is_array($value)) { | ||
// Multi file input (multiple attribute set) | ||
$newValue = array(); | ||
foreach ($value as $multiFileData) { | ||
$fileName = (is_array($multiFileData) && isset($multiFileData['tmp_name'])) | ||
? $multiFileData['tmp_name'] : $multiFileData; | ||
$newValue[] = ($this->isValid) ? $filter->filter($fileName) : $fileName; | ||
} | ||
$value = $newValue; | ||
} | ||
return $value; | ||
} | ||
|
||
/** | ||
* @param mixed $context Extra "context" to provide the validator | ||
* @return boolean | ||
*/ | ||
public function isValid($context = null) | ||
{ | ||
$this->injectUploadValidator(); | ||
$validator = $this->getValidatorChain(); | ||
//$value = $this->getValue(); // Do not run the filters yet for File uploads | ||
|
||
$rawValue = $this->getRawValue(); | ||
if (!is_array($rawValue)) { | ||
// This can happen in an AJAX POST, where the input comes across as a string | ||
$rawValue = array( | ||
'tmp_name' => $rawValue, | ||
'name' => $rawValue, | ||
'size' => 0, | ||
'type' => '', | ||
'error' => UPLOAD_ERR_NO_FILE, | ||
); | ||
} | ||
if (is_array($rawValue) && isset($rawValue['tmp_name'])) { | ||
// Single file input | ||
$this->isValid = $validator->isValid($rawValue, $context); | ||
} elseif (is_array($rawValue) && !empty($rawValue) && isset($rawValue[0]['tmp_name'])) { | ||
// Multi file input (multiple attribute set) | ||
$this->isValid = true; | ||
foreach ($rawValue as $value) { | ||
if (!$validator->isValid($value, $context)) { | ||
$this->isValid = false; | ||
break; // Do not continue processing files if validation fails | ||
} | ||
} | ||
} | ||
|
||
return $this->isValid; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function injectUploadValidator() | ||
{ | ||
if (!$this->autoPrependUploadValidator) { | ||
return; | ||
} | ||
$chain = $this->getValidatorChain(); | ||
|
||
// Check if Upload validator is already first in chain | ||
$validators = $chain->getValidators(); | ||
if (isset($validators[0]['instance']) | ||
&& $validators[0]['instance'] instanceof UploadValidator | ||
) { | ||
$this->autoPrependUploadValidator = false; | ||
return; | ||
} | ||
|
||
$chain->prependByName('fileupload', array(), true); | ||
$this->autoPrependUploadValidator = false; | ||
} | ||
|
||
/** | ||
* No-op, NotEmpty validator does not apply for FileInputs. | ||
* See also: BaseInputFilter::isValid() | ||
* | ||
* @return void | ||
*/ | ||
protected function injectNotEmptyValidator() | ||
{ | ||
$this->notEmptyValidator = true; | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @return FileInput | ||
*/ | ||
public function merge(InputInterface $input) | ||
{ | ||
parent::merge($input); | ||
if ($input instanceof FileInput) { | ||
$this->setAutoPrependUploadValidator($input->getAutoPrependUploadValidator()); | ||
} | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_InputFilter | ||
*/ | ||
|
||
namespace Zend\InputFilter; | ||
|
||
use Zend\InputFilter\InputFilterInterface; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_InputFilter | ||
*/ | ||
trait InputFilterAwareTrait | ||
{ | ||
/** | ||
* @var InputFilterInterface | ||
*/ | ||
protected $inputFilter = null; | ||
|
||
/** | ||
* Set input filter | ||
* | ||
* @param InputFilterInterface $inputFilter | ||
* @return mixed | ||
*/ | ||
public function setInputFilter(InputFilterInterface $inputFilter) | ||
{ | ||
$this->inputFilter = $inputFilter; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Retrieve input filter | ||
* | ||
* @return InputFilterInterface | ||
*/ | ||
public function getInputFilter() | ||
{ | ||
return $this->inputFilter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_InputFilter | ||
*/ | ||
|
||
namespace Zend\InputFilter; | ||
|
||
/** | ||
* Implementors of this interface may report on the existence of unknown input, | ||
* as well as retrieve all unknown values. | ||
* | ||
* @category Zend | ||
* @package Zend_InputFilter | ||
*/ | ||
interface UnknownInputsCapableInterface | ||
{ | ||
public function hasUnknown(); | ||
public function getUnknown(); | ||
} |
Oops, something went wrong.