diff --git a/src/Symfony/Component/Validator/Constraints/File.php b/src/Symfony/Component/Validator/Constraints/File.php index 7b00523b49..3abd7e2b71 100644 --- a/src/Symfony/Component/Validator/Constraints/File.php +++ b/src/Symfony/Component/Validator/Constraints/File.php @@ -27,7 +27,12 @@ class File extends Constraint public $maxSizeMessage = 'The file is too large ({{ size }}). Allowed maximum size is {{ limit }}'; public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}'; - public $uploadIniSizeErrorMessage = 'The file is too large. Allowed maximum size is {{ limit }}'; - public $uploadFormSizeErrorMessage = 'The file is too large'; - public $uploadErrorMessage = 'The file could not be uploaded'; + public $uploadIniSizeErrorMessage = 'The file is too large. Allowed maximum size is {{ limit }}'; + public $uploadFormSizeErrorMessage = 'The file is too large'; + public $uploadPartialErrorMessage = 'The file was only partially uploaded'; + public $uploadNoFileErrorMessage = 'No file was uploaded'; + public $uploadNoTmpDirErrorMessage = 'No temporary folder was configured in php.ini'; + public $uploadCantWriteErrorMessage = 'Cannot write temporary file to disk'; + public $uploadExtensionErrorMessage = 'A PHP extension caused the upload to fail'; + public $uploadErrorMessage = 'The file could not be uploaded'; } diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index 39d93ed493..05d3e3e983 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -50,6 +50,26 @@ class FileValidator extends ConstraintValidator case UPLOAD_ERR_FORM_SIZE: $this->context->addViolation($constraint->uploadFormSizeErrorMessage); + return false; + case UPLOAD_ERR_PARTIAL: + $this->context->addViolation($constraint->uploadPartialErrorMessage); + + return false; + case UPLOAD_ERR_NO_FILE: + $this->context->addViolation($constraint->uploadNoFileErrorMessage); + + return false; + case UPLOAD_ERR_NO_TMP_DIR: + $this->context->addViolation($constraint->uploadNoTmpDirErrorMessage); + + return false; + case UPLOAD_ERR_CANT_WRITE: + $this->context->addViolation($constraint->uploadCantWriteErrorMessage); + + return false; + case UPLOAD_ERR_EXTENSION: + $this->context->addViolation($constraint->uploadExtensionErrorMessage); + return false; default: $this->context->addViolation($constraint->uploadErrorMessage); diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/FileValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/FileValidatorTest.php index fb09e23cfa..344302c440 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/FileValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/FileValidatorTest.php @@ -303,9 +303,11 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase return array( array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', array('{{ limit }}' => UploadedFile::getMaxFilesize() . ' bytes')), array(UPLOAD_ERR_FORM_SIZE, 'uploadFormSizeErrorMessage'), - array(UPLOAD_ERR_PARTIAL, 'uploadErrorMessage'), - array(UPLOAD_ERR_NO_TMP_DIR, 'uploadErrorMessage'), - array(UPLOAD_ERR_EXTENSION, 'uploadErrorMessage'), + array(UPLOAD_ERR_PARTIAL, 'uploadPartialErrorMessage'), + array(UPLOAD_ERR_NO_FILE, 'uploadNoFileErrorMessage'), + array(UPLOAD_ERR_NO_TMP_DIR, 'uploadNoTmpDirErrorMessage'), + array(UPLOAD_ERR_CANT_WRITE, 'uploadCantWriteErrorMessage'), + array(UPLOAD_ERR_EXTENSION, 'uploadExtensionErrorMessage'), ); }