You are here

class File in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/symfony/validator/Constraints/File.php \Symfony\Component\Validator\Constraints\File
  2. 8.0 vendor/symfony/http-foundation/File/File.php \Symfony\Component\HttpFoundation\File\File
  3. 8.0 core/modules/file/src/Entity/File.php \Drupal\file\Entity\File
  4. 8.0 core/lib/Drupal/Core/Render/Element/File.php \Drupal\Core\Render\Element\File
  5. 8.0 core/modules/file/src/Plugin/views/wizard/File.php \Drupal\file\Plugin\views\wizard\File
  6. 8.0 core/modules/file/src/Plugin/views/field/File.php \Drupal\file\Plugin\views\field\File
  7. 8.0 core/modules/file/src/Plugin/migrate/source/d6/File.php \Drupal\file\Plugin\migrate\source\d6\File
  8. 8.0 core/modules/file/src/Plugin/migrate/source/d7/File.php \Drupal\file\Plugin\migrate\source\d7\File
Same name and namespace in other branches
  1. 8 vendor/symfony/validator/Constraints/File.php \Symfony\Component\Validator\Constraints\File

@Target({"PROPERTY", "METHOD", "ANNOTATION"})

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

  • class \Symfony\Component\Validator\Constraint
    • class \Symfony\Component\Validator\Constraints\File

Expanded class hierarchy of File

Related topics

3 files declare their use of File
FileTest.php in vendor/symfony/validator/Tests/Constraints/FileTest.php
FileValidatorPathTest.php in vendor/symfony/validator/Tests/Constraints/FileValidatorPathTest.php
FileValidatorTest.php in vendor/symfony/validator/Tests/Constraints/FileValidatorTest.php
23 string references to 'File'
DirectoryTest::testFileCheckDirectoryHandling in core/modules/system/src/Tests/File/DirectoryTest.php
Test directory handling functions.
DirectoryTest::testFileCheckLocalDirectoryHandling in core/modules/system/src/Tests/File/DirectoryTest.php
Test local directory handling functions.
DirectoryTest::testFileCreateNewFilepath in core/modules/system/src/Tests/File/DirectoryTest.php
This will take a directory and path, and find a valid filepath that is not taken by another file.
DirectoryTest::testFileDestination in core/modules/system/src/Tests/File/DirectoryTest.php
This will test the filepath for a destination based on passed flags and whether or not the file exists.
file.destination.schema.yml in core/modules/file/config/schema/file.destination.schema.yml
core/modules/file/config/schema/file.destination.schema.yml

... See full list

File

vendor/symfony/validator/Constraints/File.php, line 23

Namespace

Symfony\Component\Validator\Constraints
View source
class File extends Constraint {

  // Check the Image constraint for clashes if adding new constants here
  const NOT_FOUND_ERROR = 1;
  const NOT_READABLE_ERROR = 2;
  const EMPTY_ERROR = 3;
  const TOO_LARGE_ERROR = 4;
  const INVALID_MIME_TYPE_ERROR = 5;
  protected static $errorNames = array(
    self::NOT_FOUND_ERROR => 'NOT_FOUND_ERROR',
    self::NOT_READABLE_ERROR => 'NOT_READABLE_ERROR',
    self::EMPTY_ERROR => 'EMPTY_ERROR',
    self::TOO_LARGE_ERROR => 'TOO_LARGE_ERROR',
    self::INVALID_MIME_TYPE_ERROR => 'INVALID_MIME_TYPE_ERROR',
  );
  public $binaryFormat;
  public $mimeTypes = array();
  public $notFoundMessage = 'The file could not be found.';
  public $notReadableMessage = 'The file is not readable.';
  public $maxSizeMessage = 'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.';
  public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.';
  public $disallowEmptyMessage = 'An empty file is not allowed.';
  public $uploadIniSizeErrorMessage = 'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.';
  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.';
  protected $maxSize;
  public function __construct($options = null) {
    parent::__construct($options);
    if (null !== $this->maxSize) {
      $this
        ->normalizeBinaryFormat($this->maxSize);
    }
  }
  public function __set($option, $value) {
    if ('maxSize' === $option) {
      $this
        ->normalizeBinaryFormat($value);
      return;
    }
    parent::__set($option, $value);
  }
  public function __get($option) {
    if ('maxSize' === $option) {
      return $this->maxSize;
    }
    return parent::__get($option);
  }
  private function normalizeBinaryFormat($maxSize) {
    if (ctype_digit((string) $maxSize)) {
      $this->maxSize = (int) $maxSize;
      $this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
    }
    elseif (preg_match('/^\\d++k$/i', $maxSize)) {
      $this->maxSize = $maxSize * 1000;
      $this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
    }
    elseif (preg_match('/^\\d++M$/i', $maxSize)) {
      $this->maxSize = $maxSize * 1000000;
      $this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
    }
    elseif (preg_match('/^\\d++Ki$/i', $maxSize)) {
      $this->maxSize = $maxSize << 10;
      $this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat;
    }
    elseif (preg_match('/^\\d++Mi$/i', $maxSize)) {
      $this->maxSize = $maxSize << 20;
      $this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat;
    }
    else {
      throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Constraint::$payload public property Domain-specific data attached to a constraint.
Constraint::addImplicitGroupName public function Adds the given group if this constraint is in the Default group. 1
Constraint::CLASS_CONSTRAINT constant Marks a constraint that can be put onto classes.
Constraint::DEFAULT_GROUP constant The name of the group given to all constraints with no explicit group.
Constraint::getDefaultOption public function Returns the name of the default option. 18
Constraint::getErrorName public static function Returns the name of the given error code.
Constraint::getRequiredOptions public function Returns the name of the required options. 11
Constraint::getTargets public function Returns whether the constraint can be put onto classes, properties or both. 11
Constraint::PROPERTY_CONSTRAINT constant Marks a constraint that can be put onto properties.
Constraint::validatedBy public function Returns the name of the class that validates this constraint. 11
Constraint::__sleep public function Optimizes the serialized value to minimize storage space.
File::$binaryFormat public property
File::$disallowEmptyMessage public property
File::$errorNames protected static property Maps error codes to the names of their constants. Overrides Constraint::$errorNames 1
File::$maxSize protected property
File::$maxSizeMessage public property
File::$mimeTypes public property 1
File::$mimeTypesMessage public property 1
File::$notFoundMessage public property
File::$notReadableMessage public property
File::$uploadCantWriteErrorMessage public property
File::$uploadErrorMessage public property
File::$uploadExtensionErrorMessage public property
File::$uploadFormSizeErrorMessage public property
File::$uploadIniSizeErrorMessage public property
File::$uploadNoFileErrorMessage public property
File::$uploadNoTmpDirErrorMessage public property
File::$uploadPartialErrorMessage public property
File::EMPTY_ERROR constant
File::INVALID_MIME_TYPE_ERROR constant
File::normalizeBinaryFormat private function
File::NOT_FOUND_ERROR constant
File::NOT_READABLE_ERROR constant
File::TOO_LARGE_ERROR constant
File::__construct public function Initializes the constraint with options. Overrides Constraint::__construct
File::__get public function Returns the value of a lazily initialized option. Overrides Constraint::__get
File::__set public function Sets the value of a lazily initialized option. Overrides Constraint::__set