refactored file validator.

This commit is contained in:
Qiang Xue
2014-02-01 09:15:40 -05:00
parent 05e4fb0b46
commit b64f618545
3 changed files with 13 additions and 9 deletions

View File

@@ -167,7 +167,7 @@ class FileValidator extends Validator
protected function validateValue($file)
{
if (!$file instanceof UploadedFile || $file->error == UPLOAD_ERR_NO_FILE) {
return $this->skipOnEmpty ? null : [$this->uploadRequired, []];
return [$this->uploadRequired, []];
}
switch ($file->error) {
case UPLOAD_ERR_OK:
@@ -224,6 +224,14 @@ class FileValidator extends Validator
return $limit;
}
/**
* @inheritdoc
*/
public function isEmpty($value, $trim = false)
{
return !$value instanceof UploadedFile || $value->error == UPLOAD_ERR_NO_FILE;
}
/**
* Converts php.ini style size to bytes
*

View File

@@ -144,12 +144,8 @@ class ImageValidator extends FileValidator
*/
protected function validateValue($file)
{
if ($this->skipOnEmpty && (!$file instanceof UploadedFile || $file->error == UPLOAD_ERR_NO_FILE)) {
return null;
} else {
$result = parent::validateValue($file);
return empty($result) ? $this->validateImage($file) : $result;
}
$result = parent::validateValue($file);
return empty($result) ? $this->validateImage($file) : $result;
}
/**