X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fsymfony%2Fvalidator%2FConstraints%2FFileValidator.php;h=e752f2a1e6502951295ce54481a17a219094c986;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=34eb0d25bf124f2c8aa0c616bf2cd745028ade17;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/symfony/validator/Constraints/FileValidator.php b/vendor/symfony/validator/Constraints/FileValidator.php index 34eb0d25b..e752f2a1e 100644 --- a/vendor/symfony/validator/Constraints/FileValidator.php +++ b/vendor/symfony/validator/Constraints/FileValidator.php @@ -13,7 +13,6 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\HttpFoundation\File\File as FileObject; use Symfony\Component\HttpFoundation\File\UploadedFile; -use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; @@ -62,103 +61,53 @@ class FileValidator extends ConstraintValidator } list($sizeAsString, $limitAsString, $suffix) = $this->factorizeSizes(0, $limitInBytes, $binaryFormat); - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->uploadIniSizeErrorMessage) - ->setParameter('{{ limit }}', $limitAsString) - ->setParameter('{{ suffix }}', $suffix) - ->setCode(UPLOAD_ERR_INI_SIZE) - ->addViolation(); - } else { - $this->buildViolation($constraint->uploadIniSizeErrorMessage) - ->setParameter('{{ limit }}', $limitAsString) - ->setParameter('{{ suffix }}', $suffix) - ->setCode(UPLOAD_ERR_INI_SIZE) - ->addViolation(); - } + $this->context->buildViolation($constraint->uploadIniSizeErrorMessage) + ->setParameter('{{ limit }}', $limitAsString) + ->setParameter('{{ suffix }}', $suffix) + ->setCode(UPLOAD_ERR_INI_SIZE) + ->addViolation(); return; case UPLOAD_ERR_FORM_SIZE: - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->uploadFormSizeErrorMessage) - ->setCode(UPLOAD_ERR_FORM_SIZE) - ->addViolation(); - } else { - $this->buildViolation($constraint->uploadFormSizeErrorMessage) - ->setCode(UPLOAD_ERR_FORM_SIZE) - ->addViolation(); - } + $this->context->buildViolation($constraint->uploadFormSizeErrorMessage) + ->setCode(UPLOAD_ERR_FORM_SIZE) + ->addViolation(); return; case UPLOAD_ERR_PARTIAL: - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->uploadPartialErrorMessage) - ->setCode(UPLOAD_ERR_PARTIAL) - ->addViolation(); - } else { - $this->buildViolation($constraint->uploadPartialErrorMessage) - ->setCode(UPLOAD_ERR_PARTIAL) - ->addViolation(); - } + $this->context->buildViolation($constraint->uploadPartialErrorMessage) + ->setCode(UPLOAD_ERR_PARTIAL) + ->addViolation(); return; case UPLOAD_ERR_NO_FILE: - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->uploadNoFileErrorMessage) - ->setCode(UPLOAD_ERR_NO_FILE) - ->addViolation(); - } else { - $this->buildViolation($constraint->uploadNoFileErrorMessage) - ->setCode(UPLOAD_ERR_NO_FILE) - ->addViolation(); - } + $this->context->buildViolation($constraint->uploadNoFileErrorMessage) + ->setCode(UPLOAD_ERR_NO_FILE) + ->addViolation(); return; case UPLOAD_ERR_NO_TMP_DIR: - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->uploadNoTmpDirErrorMessage) - ->setCode(UPLOAD_ERR_NO_TMP_DIR) - ->addViolation(); - } else { - $this->buildViolation($constraint->uploadNoTmpDirErrorMessage) - ->setCode(UPLOAD_ERR_NO_TMP_DIR) - ->addViolation(); - } + $this->context->buildViolation($constraint->uploadNoTmpDirErrorMessage) + ->setCode(UPLOAD_ERR_NO_TMP_DIR) + ->addViolation(); return; case UPLOAD_ERR_CANT_WRITE: - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->uploadCantWriteErrorMessage) - ->setCode(UPLOAD_ERR_CANT_WRITE) - ->addViolation(); - } else { - $this->buildViolation($constraint->uploadCantWriteErrorMessage) - ->setCode(UPLOAD_ERR_CANT_WRITE) - ->addViolation(); - } + $this->context->buildViolation($constraint->uploadCantWriteErrorMessage) + ->setCode(UPLOAD_ERR_CANT_WRITE) + ->addViolation(); return; case UPLOAD_ERR_EXTENSION: - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->uploadExtensionErrorMessage) - ->setCode(UPLOAD_ERR_EXTENSION) - ->addViolation(); - } else { - $this->buildViolation($constraint->uploadExtensionErrorMessage) - ->setCode(UPLOAD_ERR_EXTENSION) - ->addViolation(); - } + $this->context->buildViolation($constraint->uploadExtensionErrorMessage) + ->setCode(UPLOAD_ERR_EXTENSION) + ->addViolation(); return; default: - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->uploadErrorMessage) - ->setCode($value->getError()) - ->addViolation(); - } else { - $this->buildViolation($constraint->uploadErrorMessage) - ->setCode($value->getError()) - ->addViolation(); - } + $this->context->buildViolation($constraint->uploadErrorMessage) + ->setCode($value->getError()) + ->addViolation(); return; } @@ -171,33 +120,19 @@ class FileValidator extends ConstraintValidator $path = $value instanceof FileObject ? $value->getPathname() : (string) $value; if (!is_file($path)) { - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->notFoundMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setCode(File::NOT_FOUND_ERROR) - ->addViolation(); - } else { - $this->buildViolation($constraint->notFoundMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setCode(File::NOT_FOUND_ERROR) - ->addViolation(); - } + $this->context->buildViolation($constraint->notFoundMessage) + ->setParameter('{{ file }}', $this->formatValue($path)) + ->setCode(File::NOT_FOUND_ERROR) + ->addViolation(); return; } if (!is_readable($path)) { - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->notReadableMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setCode(File::NOT_READABLE_ERROR) - ->addViolation(); - } else { - $this->buildViolation($constraint->notReadableMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setCode(File::NOT_READABLE_ERROR) - ->addViolation(); - } + $this->context->buildViolation($constraint->notReadableMessage) + ->setParameter('{{ file }}', $this->formatValue($path)) + ->setCode(File::NOT_READABLE_ERROR) + ->addViolation(); return; } @@ -205,17 +140,10 @@ class FileValidator extends ConstraintValidator $sizeInBytes = filesize($path); if (0 === $sizeInBytes) { - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->disallowEmptyMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setCode(File::EMPTY_ERROR) - ->addViolation(); - } else { - $this->buildViolation($constraint->disallowEmptyMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setCode(File::EMPTY_ERROR) - ->addViolation(); - } + $this->context->buildViolation($constraint->disallowEmptyMessage) + ->setParameter('{{ file }}', $this->formatValue($path)) + ->setCode(File::EMPTY_ERROR) + ->addViolation(); return; } @@ -225,23 +153,13 @@ class FileValidator extends ConstraintValidator if ($sizeInBytes > $limitInBytes) { list($sizeAsString, $limitAsString, $suffix) = $this->factorizeSizes($sizeInBytes, $limitInBytes, $constraint->binaryFormat); - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->maxSizeMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setParameter('{{ size }}', $sizeAsString) - ->setParameter('{{ limit }}', $limitAsString) - ->setParameter('{{ suffix }}', $suffix) - ->setCode(File::TOO_LARGE_ERROR) - ->addViolation(); - } else { - $this->buildViolation($constraint->maxSizeMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setParameter('{{ size }}', $sizeAsString) - ->setParameter('{{ limit }}', $limitAsString) - ->setParameter('{{ suffix }}', $suffix) - ->setCode(File::TOO_LARGE_ERROR) - ->addViolation(); - } + $this->context->buildViolation($constraint->maxSizeMessage) + ->setParameter('{{ file }}', $this->formatValue($path)) + ->setParameter('{{ size }}', $sizeAsString) + ->setParameter('{{ limit }}', $limitAsString) + ->setParameter('{{ suffix }}', $suffix) + ->setCode(File::TOO_LARGE_ERROR) + ->addViolation(); return; } @@ -267,21 +185,12 @@ class FileValidator extends ConstraintValidator } } - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->mimeTypesMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setParameter('{{ type }}', $this->formatValue($mime)) - ->setParameter('{{ types }}', $this->formatValues($mimeTypes)) - ->setCode(File::INVALID_MIME_TYPE_ERROR) - ->addViolation(); - } else { - $this->buildViolation($constraint->mimeTypesMessage) - ->setParameter('{{ file }}', $this->formatValue($path)) - ->setParameter('{{ type }}', $this->formatValue($mime)) - ->setParameter('{{ types }}', $this->formatValues($mimeTypes)) - ->setCode(File::INVALID_MIME_TYPE_ERROR) - ->addViolation(); - } + $this->context->buildViolation($constraint->mimeTypesMessage) + ->setParameter('{{ file }}', $this->formatValue($path)) + ->setParameter('{{ type }}', $this->formatValue($mime)) + ->setParameter('{{ types }}', $this->formatValues($mimeTypes)) + ->setCode(File::INVALID_MIME_TYPE_ERROR) + ->addViolation(); } }