[Validator] fixed the problem with conflict "File" name in namespace at Symfony\Components\Validator\Constraints\FileValidator when Symfony\Components\Validator\Comstraints\File was loaded before loading FileValidator

This commit is contained in:
fivestar 2010-07-15 19:47:10 +09:00 committed by Fabien Potencier
parent 6142700881
commit 2de5efdd1a

View File

@ -6,7 +6,7 @@ use Symfony\Components\Validator\Constraint;
use Symfony\Components\Validator\ConstraintValidator;
use Symfony\Components\Validator\Exception\ConstraintDefinitionException;
use Symfony\Components\Validator\Exception\UnexpectedTypeException;
use Symfony\Components\File\File;
use Symfony\Components\File\File as FileObject;
class FileValidator extends ConstraintValidator
{
@ -16,11 +16,11 @@ class FileValidator extends ConstraintValidator
return true;
}
if (!is_scalar($value) && !$value instanceof File && !(is_object($value) && method_exists($value, '__toString()'))) {
if (!is_scalar($value) && !$value instanceof FileObject && !(is_object($value) && method_exists($value, '__toString()'))) {
throw new UnexpectedTypeException($value, 'string');
}
$path = $value instanceof File ? $value->getPath() : (string)$value;
$path = $value instanceof FileObject ? $value->getPath() : (string)$value;
if (!file_exists($path)) {
$this->setMessage($constraint->notFoundMessage, array('file' => $path));
@ -63,7 +63,7 @@ class FileValidator extends ConstraintValidator
}
if ($constraint->mimeTypes) {
if (!$value instanceof File) {
if (!$value instanceof FileObject) {
throw new ConstraintValidationException();
}
@ -80,4 +80,4 @@ class FileValidator extends ConstraintValidator
return true;
}
}
}