class FileUploaded in N1ED - Visual editor as CKEditor plugin with Bootstrap support 8.2
Uploaded but not commited yet file. Data stucture about file is to be converted to commited file when all validations are passed.
Hierarchy
- class \Drupal\n1ed\Flmngr\FileUploaderServer\lib\file\AFile
- class \Drupal\n1ed\Flmngr\FileUploaderServer\lib\file\FileUploaded
Expanded class hierarchy of FileUploaded
3 files declare their use of FileUploaded
- ActionUploadAddFile.php in src/
Flmngr/ FileUploaderServer/ lib/ action/ ActionUploadAddFile.php - ActionUploadCommit.php in src/
Flmngr/ FileUploaderServer/ lib/ action/ ActionUploadCommit.php - ActionUploadRemoveFile.php in src/
Flmngr/ FileUploaderServer/ lib/ action/ ActionUploadRemoveFile.php
File
- src/
Flmngr/ FileUploaderServer/ lib/ file/ FileUploaded.php, line 13
Namespace
Drupal\n1ed\Flmngr\FileUploaderServer\lib\fileView source
class FileUploaded extends AFile {
protected $newName;
protected $confilictsErrors = [];
protected $customErrors = [];
/**
* {@inheritdoc}
*/
public function __construct($config, $dir, $name, $newName) {
parent::__construct($config, $dir, $name);
$this->newName = $newName;
}
/**
* {@inheritdoc}
*/
public function getBaseDir() {
return $this->config
->getTmpDir();
}
/**
* {@inheritdoc}
*/
public function getNewName() {
return $this->newName;
}
/**
* {@inheritdoc}
*/
public function checkForErrors($checkForExist) {
if (!parent::checkForErrors($checkForExist)) {
return FALSE;
}
if ($this->newName !== $this
->getName() && !Utils::isFileNameSyntaxOk($this->newName)) {
$this->commonErrors[] = Message::createMessage(Message::FILE_ERROR_SYNTAX, $this->newName);
}
if (Utils::isImage($this
->getName())) {
$ext = $this
->getExt();
$newExt = Utils::getExt($this->newName);
if ($ext !== $newExt) {
if (!($ext === "jpg" && $newExt === "jpeg") && !($ext === "jpeg" && $newExt === "jpg")) {
$this->commonErrors[] = Message::createMessage(Message::FILE_ERROR_INCORRECT_IMAGE_EXT_CHANGE, $ext, $newExt);
}
}
}
return TRUE;
}
/**
* Adds custom error.
*/
public function addCustomError($message) {
$this->customErrors[] = $message;
}
/**
* {@inheritdoc}
*/
public function getErrors() {
$errors = (array) parent::getErrors();
for ($i = 0; $i < count($this->confilictsErrors); $i++) {
$errors[] = $this->confilictsErrors[$i];
}
for ($i = 0; $i < count($this->customErrors); $i++) {
$errors[] = $this->customErrors[$i];
}
return $errors;
}
/**
* Gets commited file.
*/
public function getCommitedFile($dir) {
return new FileCommited($this->config, $dir, $this->newName);
}
/**
* Checks for conflicts.
*/
public function checkForConflicts($dir) {
$this->confilictsErrors = [];
$file = $this
->getCommitedFile($dir);
if ($file
->exists()) {
$this->confilictsErrors[] = Message::createMessage(Message::FILE_ALREADY_EXISTS, $file
->getName());
}
if ($file
->isImage()) {
$fileOriginal = $file
->getFileOriginal();
if ($fileOriginal
->exists()) {
$this->confilictsErrors[] = Message::createMessage(Message::FILE_ALREADY_EXISTS, $fileOriginal
->getName());
}
$filePreview = $file
->getFilePreview();
if ($filePreview
->exists()) {
$this->confilictsErrors[] = Message::createMessage(Message::FILE_ALREADY_EXISTS, $filePreview
->getName());
}
}
}
/**
* Uploads and commits file.
*/
public function uploadAndCommit($file) {
$initName = $this
->getName();
$this
->setFreeFileName();
if (!move_uploaded_file($file['tmp_name'], $this
->getFullPath())) {
throw new MessageException(Message::createMessage(Message::WRITING_FILE_ERROR, $initName));
}
}
/**
* Rehosts a file (downloads from some URL).
*/
public function rehost($url) {
$dUrl = URLDownloader::download($url, $this
->getBaseDir() . DIRECTORY_SEPARATOR . $this
->getDir());
$this
->setName($dUrl->fileName);
}
/**
* Commits a file.
*/
public function commit($dir, $autoRename) {
$file = $this
->getCommitedFile($dir);
if ($autoRename) {
$file
->setFreeFileName();
}
$this
->copyTo($file);
return $file;
}
/**
* Is file commited.
*/
public function isCommited() {
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AFile:: |
protected | property | ||
AFile:: |
protected | property | ||
AFile:: |
private | property | 1 | |
AFile:: |
private | property | 1 | |
AFile:: |
public | function | Copies file to another place. | |
AFile:: |
public | function | Deletes file from storage. | |
AFile:: |
public | function | Does file exist. | |
AFile:: |
public | function | Gets a data for response format file representation. | 1 |
AFile:: |
public | function | Gets directory. | |
AFile:: |
public | function | Gets extension of file. | |
AFile:: |
public | function | Gets full path. | 1 |
AFile:: |
public | function | Gets as image object. | |
AFile:: |
public | function | Gets height of image. | |
AFile:: |
public | function | Gets width of image. | |
AFile:: |
public | function | Gets modification name. | 1 |
AFile:: |
public | function | Gets all file modifications (original, preview, etc.). | 1 |
AFile:: |
public | function | Gets name. | |
AFile:: |
public | function | Gets a name without extension. | |
AFile:: |
public | function | Gets path. | |
AFile:: |
public | function | Gets a size of file. | |
AFile:: |
public | function | Checks file is image or not. | |
AFile:: |
public | function | Sets a directory of file. | |
AFile:: |
protected | function | Generates and sets free file name for this file. | |
AFile:: |
public | function | Sets a name of file. | |
FileUploaded:: |
protected | property | ||
FileUploaded:: |
protected | property | ||
FileUploaded:: |
protected | property | ||
FileUploaded:: |
public | function | Adds custom error. | |
FileUploaded:: |
public | function | Checks for conflicts. | |
FileUploaded:: |
public | function |
Returns do we need to continue check or not. Overrides AFile:: |
|
FileUploaded:: |
public | function | Commits a file. | |
FileUploaded:: |
public | function |
Gets base directory. Overrides AFile:: |
|
FileUploaded:: |
public | function | Gets commited file. | |
FileUploaded:: |
public | function |
Gets errors accumulated for file. Overrides AFile:: |
|
FileUploaded:: |
public | function | ||
FileUploaded:: |
public | function |
Is file commited. Overrides AFile:: |
|
FileUploaded:: |
public | function | Rehosts a file (downloads from some URL). | |
FileUploaded:: |
public | function | Uploads and commits file. | |
FileUploaded:: |
public | function |
Creates a File instance. Overrides AFile:: |