class FileUploadResult
Same name in other branches
- 9 core/modules/file/src/Upload/FileUploadResult.php \Drupal\file\Upload\FileUploadResult
- 11.x core/modules/file/src/Upload/FileUploadResult.php \Drupal\file\Upload\FileUploadResult
Value object for a file upload result.
Hierarchy
- class \Drupal\file\Upload\FileUploadResult
Expanded class hierarchy of FileUploadResult
1 file declares its use of FileUploadResult
- FileUpload.php in core/
modules/ jsonapi/ src/ Controller/ FileUpload.php
File
-
core/
modules/ file/ src/ Upload/ FileUploadResult.php, line 13
Namespace
Drupal\file\UploadView source
class FileUploadResult {
/**
* If the filename was renamed for security reasons.
*
* @var bool
*/
protected $securityRename = FALSE;
/**
* The sanitized filename.
*
* @var string
*/
protected $sanitizedFilename;
/**
* The original filename.
*
* @var string
*/
protected $originalFilename;
/**
* The File entity.
*
* @var \Drupal\file\FileInterface
*/
protected $file;
/**
* The constraint violations.
*
* @var \Symfony\Component\Validator\ConstraintViolationListInterface
*/
protected ConstraintViolationListInterface $violations;
/**
* Creates a new FileUploadResult.
*/
public function __construct() {
$this->violations = new ConstraintViolationList();
}
/**
* Flags the result as having had a security rename.
*
* @return $this
*/
public function setSecurityRename() : FileUploadResult {
$this->securityRename = TRUE;
return $this;
}
/**
* Sets the sanitized filename.
*
* @param string $sanitizedFilename
* The sanitized filename.
*
* @return $this
*/
public function setSanitizedFilename(string $sanitizedFilename) : FileUploadResult {
$this->sanitizedFilename = $sanitizedFilename;
return $this;
}
/**
* Gets the original filename.
*
* @return string
*/
public function getOriginalFilename() : string {
return $this->originalFilename;
}
/**
* Sets the original filename.
*
* @param string $originalFilename
* The original filename.
*
* @return $this
*/
public function setOriginalFilename(string $originalFilename) : FileUploadResult {
$this->originalFilename = $originalFilename;
return $this;
}
/**
* Sets the File entity.
*
* @param \Drupal\file\FileInterface $file
* A file entity.
*
* @return $this
*/
public function setFile(FileInterface $file) : FileUploadResult {
$this->file = $file;
return $this;
}
/**
* Returns if there was a security rename.
*
* @return bool
*/
public function isSecurityRename() : bool {
return $this->securityRename;
}
/**
* Returns if there was a file rename.
*
* @return bool
*/
public function isRenamed() : bool {
return $this->originalFilename !== $this->sanitizedFilename;
}
/**
* Gets the sanitized filename.
*
* @return string
*/
public function getSanitizedFilename() : string {
return $this->sanitizedFilename;
}
/**
* Gets the File entity.
*
* @return \Drupal\file\FileInterface
*/
public function getFile() : FileInterface {
return $this->file;
}
/**
* Adds a constraint violation.
*
* @param \Symfony\Component\Validator\ConstraintViolationInterface $violation
* The constraint violation.
*/
public function addViolation(ConstraintViolationInterface $violation) : void {
$this->violations
->add($violation);
}
/**
* Adds constraint violations.
*
* @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations
* The constraint violations.
*/
public function addViolations(ConstraintViolationListInterface $violations) : void {
$this->violations
->addAll($violations);
}
/**
* Gets the constraint violations.
*
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
* The constraint violations.
*/
public function getViolations() : ConstraintViolationListInterface {
return $this->violations;
}
/**
* Returns TRUE if there are constraint violations.
*/
public function hasViolations() : bool {
return $this->violations
->count() > 0;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
FileUploadResult::$file | protected | property | The File entity. |
FileUploadResult::$originalFilename | protected | property | The original filename. |
FileUploadResult::$sanitizedFilename | protected | property | The sanitized filename. |
FileUploadResult::$securityRename | protected | property | If the filename was renamed for security reasons. |
FileUploadResult::$violations | protected | property | The constraint violations. |
FileUploadResult::addViolation | public | function | Adds a constraint violation. |
FileUploadResult::addViolations | public | function | Adds constraint violations. |
FileUploadResult::getFile | public | function | Gets the File entity. |
FileUploadResult::getOriginalFilename | public | function | Gets the original filename. |
FileUploadResult::getSanitizedFilename | public | function | Gets the sanitized filename. |
FileUploadResult::getViolations | public | function | Gets the constraint violations. |
FileUploadResult::hasViolations | public | function | Returns TRUE if there are constraint violations. |
FileUploadResult::isRenamed | public | function | Returns if there was a file rename. |
FileUploadResult::isSecurityRename | public | function | Returns if there was a security rename. |
FileUploadResult::setFile | public | function | Sets the File entity. |
FileUploadResult::setOriginalFilename | public | function | Sets the original filename. |
FileUploadResult::setSanitizedFilename | public | function | Sets the sanitized filename. |
FileUploadResult::setSecurityRename | public | function | Flags the result as having had a security rename. |
FileUploadResult::__construct | public | function | Creates a new FileUploadResult. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.