class UploadedFileValidator

Same name in other branches
  1. 11.x core/modules/file/src/Validation/UploadedFileValidator.php \Drupal\file\Validation\UploadedFileValidator

Validator for uploaded files.

Hierarchy

Expanded class hierarchy of UploadedFileValidator

1 file declares its use of UploadedFileValidator
UploadedFileValidatorTest.php in core/modules/file/tests/src/Kernel/Validation/UploadedFileValidatorTest.php

File

core/modules/file/src/Validation/UploadedFileValidator.php, line 16

Namespace

Drupal\file\Validation
View source
class UploadedFileValidator implements UploadedFileValidatorInterface {
    
    /**
     * The symfony validator.
     *
     * @var \Symfony\Component\Validator\Validator\ValidatorInterface
     */
    protected ValidatorInterface $validator;
    
    /**
     * Creates a new UploadedFileValidator.
     *
     * @param \Drupal\Core\Validation\BasicRecursiveValidatorFactory $validatorFactory
     *   The validator factory.
     */
    public function __construct(BasicRecursiveValidatorFactory $validatorFactory) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function validate(UploadedFile $uploadedFile, array $options = []) : ConstraintViolationListInterface {
        $constraint = new UploadedFileConstraint($options);
        return $this->getValidator()
            ->validate($uploadedFile, $constraint);
    }
    
    /**
     * Get the Symfony validator instance.
     *
     * @return \Symfony\Component\Validator\Validator\ValidatorInterface
     *   The Symfony validator.
     */
    protected function getValidator() : ValidatorInterface {
        if (!isset($this->validator)) {
            $this->validator = $this->validatorFactory
                ->createValidator();
        }
        return $this->validator;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
UploadedFileValidator::$validator protected property The symfony validator.
UploadedFileValidator::getValidator protected function Get the Symfony validator instance.
UploadedFileValidator::validate public function Validates an uploaded file. Overrides UploadedFileValidatorInterface::validate
UploadedFileValidator::__construct public function Creates a new UploadedFileValidator.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.