在文件\Zend\Mvc\Controller\Plugin\FilePostRedirectGet
要看看兩個函數是getNonEmptyUploadData
(即供給的回調函數)和traverseInputs
(這是一個美化的foreach
來在每一個輸入濾波器然後運行它,並通過上述回調的值) 。
爲了讓這個插件的集合工作,你將需要擴展類,並改變上述功能:
/**
* Traverse the InputFilter and run a callback against each Input and associated value
*
* @param InputFilterInterface $inputFilter
* @param array $values
* @param callable $callback
* @return array|null
*/
protected function traverseInputs(InputFilterInterface $inputFilter, $values, $callback)
{
$returnValues = null;
foreach ($values as $name => $value) {
if (!$inputFilter->has($name)) {
continue;
}
$input = $inputFilter->get($name);
if ($input instanceof InputFilterInterface && is_array($value)) {
if ($input instanceof CollectionInputFilter) {
$retVal = null;
foreach ($value as $k => $val) {
$retVal2 = $this->traverseInputs($input->getInputFilter(), $val, $callback);
if ($retVal2)
$retVal[$k] = $retVal2;
}
} else
$retVal = $this->traverseInputs($input, $value, $callback);
if (null !== $retVal) {
$returnValues[$name] = $retVal;
}
continue;
}
$retVal = $callback($input, $value);
if (null !== $retVal) {
$returnValues[$name] = $retVal;
}
}
return $returnValues;
}
/**
* Traverse the InputFilter and only return the data of FileInputs that have an upload
*
* @param InputFilterInterface $inputFilter
* @param array $data
* @return array
*/
protected function getNonEmptyUploadData(InputFilterInterface $inputFilter, $data)
{
return $this->traverseInputs(
$inputFilter,
$data,
function ($input, $value) {
$messages = $input->getMessages();
if (is_array($value) && $input instanceof FileInput && empty($messages)) {
$rawValue = $value;
if (
(isset($rawValue['error']) && $rawValue['error'] !== UPLOAD_ERR_NO_FILE)
|| (isset($rawValue[0]['error']) && $rawValue[0]['error'] !== UPLOAD_ERR_NO_FILE)
) {
return $value;
}
}
return;
}
);
}
這裏是一個差異,顯示線被改變什麼:https://github.com/rafam31/zf2/commit/c481e7404faf93beb4c67a6a4b7490fec15d279b