‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Resource\AbstractFile Class Reference
Inheritance diagram for TYPO3\CMS\Core\Resource\AbstractFile:
TYPO3\CMS\Core\Resource\FileInterface TYPO3\CMS\Core\Resource\ResourceInterface TYPO3\CMS\Core\Resource\File TYPO3\CMS\Core\Resource\ProcessedFile TYPO3\CMS\Core\Tests\Unit\Resource\Fixtures\TestingFile

Public Member Functions

 hasProperty (string $key)
 
 getProperty (string $key)
 
 getIdentifier ()
 
non empty string getHashedIdentifier ()
 
 getName ()
 
 getNameWithoutExtension ()
 
int< 0, getSize():int { if( $this->deleted) { throw new \RuntimeException( 'File has been deleted.', 1329821480);} if(empty( $this->properties[ 'size'])) { $fileInfo=$this-> getStorage () -> getFileInfoByIdentifier($this->getIdentifier(), ['size'])
 
return MathUtility::canBeInterpretedAsInteger($size) ?(int) $size int getUid ()
 
non empty string getSha1 ()
 
 getCreationTime ()
 
 getModificationTime ()
 
 getExtension ()
 
non empty string getMimeType ()
 
int getType ()
 
 isType (FileType $fileType)
 
bool isImage ()
 
bool isMediaFile ()
 
bool isTextFile ()
 
 getContents ()
 
$this setContents (string $contents)
 
 getStorage ()
 
bool exists ()
 
$this setStorage (ResourceStorage $storage)
 
$this setIdentifier ($identifier)
 
string getCombinedIdentifier ()
 
 delete ()
 
 setDeleted ()
 
bool isDeleted ()
 
 rename (string $newName, $conflictMode=DuplicationBehavior::RENAME)
 
File copyTo (Folder $targetFolder, $targetFileName=null, $conflictMode=DuplicationBehavior::RENAME)
 
File moveTo (Folder $targetFolder, $targetFileName=null, $conflictMode=DuplicationBehavior::RENAME)
 
string null getPublicUrl ()
 
non empty string getForLocalProcessing (bool $writable=true)
 
 updateProperties (array $properties)
 
 getParentFolder ()
 

Public Attributes

const FILETYPE_UNKNOWN = 0
 
const FILETYPE_TEXT = 1
 
const FILETYPE_IMAGE = 2
 
const FILETYPE_AUDIO = 3
 
const FILETYPE_VIDEO = 4
 
const FILETYPE_APPLICATION = 5
 
array< non-empty-string, function getProperties() { return $this-> properties
 
 $size = array_pop($fileInfo)
 
 else
 

Protected Attributes

array $properties = []
 
ResourceStorage null $storage
 
string $identifier
 
string $name
 
bool $deleted = false
 

Detailed Description

Abstract file representation in the file abstraction layer.

Definition at line 28 of file AbstractFile.php.

Member Function Documentation

◆ copyTo()

File TYPO3\CMS\Core\Resource\AbstractFile::copyTo ( Folder  $targetFolder,
  $targetFileName = null,
  $conflictMode = DuplicationBehavior::RENAME 
)

Copies this file into a target folder

Parameters
Folder$targetFolderFolder to copy file into.
string$targetFileName‪an optional destination fileName
string | DuplicationBehavior$conflictMode
Exceptions

Definition at line 500 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\Enum\getDefaultDuplicationBehaviour, and TYPO3\CMS\Core\Resource\Folder\getStorage().

◆ delete()

TYPO3\CMS\Core\Resource\AbstractFile::delete ( )

Deletes this file from its storage. This also means that this object becomes useless.

Definition at line 431 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\getStorage(), and TYPO3\CMS\Core\Resource\AbstractFile\properties.

◆ exists()

bool TYPO3\CMS\Core\Resource\AbstractFile::exists ( )

Checks if this file exists. This should normally always return TRUE; it might only return FALSE when this object has been created from an index record without checking for.

Returns
‪bool TRUE if this file physically exists

Reimplemented in TYPO3\CMS\Core\Resource\ProcessedFile.

Definition at line 377 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\getIdentifier().

◆ getCombinedIdentifier()

string TYPO3\CMS\Core\Resource\AbstractFile::getCombinedIdentifier ( )

Returns a combined identifier of this file, i.e. the storage UID and the folder identifier separated by a colon ":".

Returns
‪string Combined storage and file identifier, e.g. StorageUID:path/and/fileName.png

Reimplemented in TYPO3\CMS\Core\Resource\File.

Definition at line 418 of file AbstractFile.php.

References TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger(), TYPO3\CMS\Core\Resource\AbstractFile\getIdentifier(), TYPO3\CMS\Core\Resource\AbstractFile\getStorage(), TYPO3\CMS\Core\Resource\AbstractFile\getUid(), and TYPO3\CMS\Core\Resource\AbstractFile\properties.

◆ getContents()

TYPO3\CMS\Core\Resource\AbstractFile::getContents ( )

Get the contents of this file

Exceptions

Reimplemented in TYPO3\CMS\Core\Resource\File.

Definition at line 332 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\getStorage().

◆ getCreationTime()

TYPO3\CMS\Core\Resource\AbstractFile::getCreationTime ( )

Returns the creation time of the file as Unix timestamp

Exceptions

Definition at line 219 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\getProperty().

Referenced by TYPO3\CMS\Core\Resource\FileReference\getCreationTime(), and TYPO3\CMS\Filelist\FileList\getSortingValueForFile().

◆ getExtension()

◆ getForLocalProcessing()

non empty string TYPO3\CMS\Core\Resource\AbstractFile::getForLocalProcessing ( bool  $writable = true)

Returns a path to a local version of this file to process it locally (e.g. with some system tool). If the file is normally located on a remote storages, this creates a local copy. If the file is already on the local system, this only makes a new copy if $writable is set to TRUE.

Parameters
bool$writable‪Set this to FALSE if you only want to do read operations on the file.
Exceptions

Definition at line 576 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\getStorage().

Referenced by TYPO3\CMS\Core\Resource\Index\Indexer\extractRequiredMetaData(), TYPO3\CMS\Core\Resource\Index\MetaDataRepository\findByFile(), TYPO3\CMS\Core\Resource\Processing\LocalPreviewHelper\generatePreviewFromFile(), and TYPO3\CMS\Core\Resource\FileReference\getForLocalProcessing().

◆ getHashedIdentifier()

non empty string TYPO3\CMS\Core\Resource\AbstractFile::getHashedIdentifier ( )
Returns
‪non-empty-string

Implements TYPO3\CMS\Core\Resource\ResourceInterface.

Definition at line 152 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\properties.

◆ getIdentifier()

◆ getMimeType()

◆ getModificationTime()

TYPO3\CMS\Core\Resource\AbstractFile::getModificationTime ( )

◆ getName()

◆ getNameWithoutExtension()

TYPO3\CMS\Core\Resource\AbstractFile::getNameWithoutExtension ( )

Returns the basename (the name without extension) of this file.

Definition at line 167 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\getName(), and TYPO3\CMS\Core\Utility\PathUtility\pathinfo().

Referenced by TYPO3\CMS\Core\Resource\FileReference\getNameWithoutExtension().

◆ getParentFolder()

◆ getProperty()

◆ getPublicUrl()

string null TYPO3\CMS\Core\Resource\AbstractFile::getPublicUrl ( )

Returns a publicly accessible URL for this file

WARNING: Access to the file may be restricted by further means, e.g. some web-based authentication. You have to take care of this yourself.

Returns
‪string|null NULL if file is deleted, the generated URL otherwise

Reimplemented in TYPO3\CMS\Core\Resource\ProcessedFile, and TYPO3\CMS\Core\Resource\File.

Definition at line 558 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\File\getPublicUrl(), and TYPO3\CMS\Core\Resource\AbstractFile\getStorage().

◆ getSha1()

non empty string TYPO3\CMS\Core\Resource\AbstractFile::getSha1 ( )

Returns the Sha1 of this file

Exceptions

Reimplemented in TYPO3\CMS\Core\Resource\File.

Definition at line 206 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\getStorage().

◆ getStorage() [1/2]

TYPO3\CMS\Core\Resource\AbstractFile::getStorage ( )

◆ getStorage() [2/2]

int<0, getSize(): int { if ($this->deleted) { throw new \RuntimeException('File has been deleted.', 1329821480); } if (empty($this->properties['size'])) { $fileInfo = $this-> TYPO3\CMS\Core\Resource\AbstractFile::getStorage ( ) -> getFileInfoByIdentifier($this->getIdentifier(), ['size'])

◆ getType()

int TYPO3\CMS\Core\Resource\AbstractFile::getType ( )

Returns the fileType of this file basically there are only five main "file types" "audio" "image" "software" "text" "video" "other" see FileType enum

Returns
‪int $fileType
Todo:
‪will return an instance of FileType enum in TYPO3 v14.0

Definition at line 281 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\getMimeType(), TYPO3\CMS\Core\Resource\AbstractFile\properties, and TYPO3\CMS\Core\Resource\tryFromMimeType.

Referenced by TYPO3\CMS\Core\Resource\FileReference\getType(), TYPO3\CMS\Core\Resource\Service\ExtractorService\isFileTypeSupportedByExtractor(), TYPO3\CMS\Core\Resource\Index\Indexer\isFileTypeSupportedByExtractor(), TYPO3\CMS\Core\Resource\AbstractFile\isType(), and TYPO3\CMS\Core\Resource\File\updateProperties().

◆ getUid()

return MathUtility::canBeInterpretedAsInteger ( $size) ?(int) $size int TYPO3\CMS\Core\Resource\AbstractFile::getUid ( )

◆ hasProperty()

TYPO3\CMS\Core\Resource\AbstractFile::hasProperty ( string  $key)

Returns true if the given property key exists for this file.

Parameters
non-empty-string$key

Implements TYPO3\CMS\Core\Resource\FileInterface.

Definition at line 116 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\properties.

Referenced by TYPO3\CMS\Core\Resource\AbstractFile\getProperty().

◆ isDeleted()

bool TYPO3\CMS\Core\Resource\AbstractFile::isDeleted ( )

Returns TRUE if this file has been deleted

Returns
‪bool

Definition at line 459 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\$deleted.

◆ isImage()

bool TYPO3\CMS\Core\Resource\AbstractFile::isImage ( )

Useful to find out if this file can be previewed or resized as image.

Returns
‪bool true if File has an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']

Definition at line 301 of file AbstractFile.php.

References $GLOBALS, TYPO3\CMS\Core\Resource\AbstractFile\getExtension(), and TYPO3\CMS\Core\Utility\GeneralUtility\inList().

Referenced by TYPO3\CMS\Core\Resource\Index\Indexer\extractRequiredMetaData(), TYPO3\CMS\Backend\Controller\File\FileController\flattenFileResultDataValue(), and TYPO3\CMS\Core\Resource\Processing\LocalPreviewHelper\generatePreviewFromFile().

◆ isMediaFile()

bool TYPO3\CMS\Core\Resource\AbstractFile::isMediaFile ( )

Useful to find out if this file has a file extension based on any of the registered media extensions

Returns
‪bool true if File is a media-extension according to $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']

Definition at line 310 of file AbstractFile.php.

References $GLOBALS, TYPO3\CMS\Core\Resource\AbstractFile\getExtension(), and TYPO3\CMS\Core\Utility\GeneralUtility\inList().

◆ isTextFile()

bool TYPO3\CMS\Core\Resource\AbstractFile::isTextFile ( )

Useful to find out if this file can be edited.

Returns
‪bool true if File is a text-based file extension according to $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']

Definition at line 320 of file AbstractFile.php.

References $GLOBALS, TYPO3\CMS\Core\Resource\AbstractFile\getExtension(), and TYPO3\CMS\Core\Utility\GeneralUtility\inList().

◆ isType()

◆ moveTo()

File TYPO3\CMS\Core\Resource\AbstractFile::moveTo ( Folder  $targetFolder,
  $targetFileName = null,
  $conflictMode = DuplicationBehavior::RENAME 
)

Moves the file into the target folder

Parameters
Folder$targetFolderFolder to move file into.
string$targetFileName‪an optional destination fileName
string | DuplicationBehavior$conflictMode
Exceptions

Definition at line 529 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\Enum\getDefaultDuplicationBehaviour, and TYPO3\CMS\Core\Resource\Folder\getStorage().

◆ rename()

TYPO3\CMS\Core\Resource\AbstractFile::rename ( string  $newName,
  $conflictMode = DuplicationBehavior::RENAME 
)

Renames this file.

Parameters
non-empty-string$newName‪The new file name
string | DuplicationBehavior$conflictMode
Todo:
‪change $conflictMode parameter type to DuplicationBehavior in TYPO3 v14.0

Definition at line 471 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\Enum\getDefaultDuplicationBehaviour, and TYPO3\CMS\Core\Resource\AbstractFile\getStorage().

◆ setContents()

$this TYPO3\CMS\Core\Resource\AbstractFile::setContents ( string  $contents)

Replace the current file contents with the given string

Exceptions

Reimplemented in TYPO3\CMS\Core\Resource\ProcessedFile, and TYPO3\CMS\Core\Resource\File.

Definition at line 346 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\getStorage().

◆ setDeleted()

TYPO3\CMS\Core\Resource\AbstractFile::setDeleted ( )

Marks this file as deleted. This should only be used inside the File Abstraction Layer, as it is a low-level API method.

Definition at line 449 of file AbstractFile.php.

◆ setIdentifier()

$this TYPO3\CMS\Core\Resource\AbstractFile::setIdentifier (   $identifier)

Set the identifier of this file

Should only be used by other parts of the File API (e.g. drivers after moving a file)

Parameters
string$identifier
Returns
‪$this

Definition at line 406 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\$identifier.

Referenced by TYPO3\CMS\Core\Resource\ResourceStorage\updateProcessedFile().

◆ setStorage()

$this TYPO3\CMS\Core\Resource\AbstractFile::setStorage ( ResourceStorage  $storage)

Sets the storage this file is located in. This is only meant for \TYPO3\CMS\Core\Resource-internal usage; don't use it to move files.

Should only be used by other parts of the File API (e.g. drivers after moving a file)

Returns
‪$this

Definition at line 392 of file AbstractFile.php.

References TYPO3\CMS\Core\Resource\AbstractFile\$storage, TYPO3\CMS\Core\Resource\ResourceStorage\getUid(), and TYPO3\CMS\Core\Resource\AbstractFile\properties.

◆ updateProperties()

TYPO3\CMS\Core\Resource\AbstractFile::updateProperties ( array  $properties)
abstract

Updates properties of this object. This method is used to reconstitute settings from the database into this object after being instantiated.

Reimplemented in TYPO3\CMS\Core\Resource\ProcessedFile, TYPO3\CMS\Core\Resource\File, and TYPO3\CMS\Core\Tests\Unit\Resource\Fixtures\TestingFile.

Member Data Documentation

◆ $deleted

bool TYPO3\CMS\Core\Resource\AbstractFile::$deleted = false
protected

If set to true, this file is regarded as being deleted.

Definition at line 65 of file AbstractFile.php.

Referenced by TYPO3\CMS\Core\Resource\AbstractFile\isDeleted().

◆ $identifier

string TYPO3\CMS\Core\Resource\AbstractFile::$identifier
protected

The identifier of this file to identify it on the storage. On some drivers, this is the path to the file, but drivers could also just provide any other unique identifier for this file on the specific storage.

Definition at line 53 of file AbstractFile.php.

Referenced by TYPO3\CMS\Core\Resource\AbstractFile\getIdentifier(), and TYPO3\CMS\Core\Resource\AbstractFile\setIdentifier().

◆ $name

◆ $properties

array TYPO3\CMS\Core\Resource\AbstractFile::$properties = []
protected

◆ $size

TYPO3\CMS\Core\Resource\AbstractFile::$size = array_pop($fileInfo)

Definition at line 183 of file AbstractFile.php.

◆ $storage

ResourceStorage null TYPO3\CMS\Core\Resource\AbstractFile::$storage
protected

◆ else

TYPO3\CMS\Core\Resource\AbstractFile::else
Initial value:
{
‪$size = $this->‪properties['size']

Definition at line 184 of file AbstractFile.php.

◆ FILETYPE_APPLICATION

const TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_APPLICATION = 5

Any kind of application

See also
http://www.iana.org/assignments/media-types/application
Deprecated:
‪will be removed in TYPO3 v14, use TYPO3\CMS\Core\Resource\FileType::APPLICATION instead

Definition at line 106 of file AbstractFile.php.

◆ FILETYPE_AUDIO

const TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_AUDIO = 3

Any kind of audio file

See also
http://www.iana.org/assignments/media-types/audio
Deprecated:
‪will be removed in TYPO3 v14, use TYPO3\CMS\Core\Resource\FileType::AUDIO instead

Definition at line 92 of file AbstractFile.php.

◆ FILETYPE_IMAGE

const TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_IMAGE = 2

Any kind of image

See also
http://www.iana.org/assignments/media-types/image
Deprecated:
‪will be removed in TYPO3 v14, use TYPO3\CMS\Core\Resource\FileType::IMAGE instead

Definition at line 85 of file AbstractFile.php.

◆ FILETYPE_TEXT

const TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_TEXT = 1

Any kind of text

See also
http://www.iana.org/assignments/media-types/text
Deprecated:
‪will be removed in TYPO3 v14, use TYPO3\CMS\Core\Resource\FileType::TEXT instead

Definition at line 78 of file AbstractFile.php.

◆ FILETYPE_UNKNOWN

const TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_UNKNOWN = 0

any other file

Deprecated:
‪will be removed in TYPO3 v14, use TYPO3\CMS\Core\Resource\FileType::UNKNOWN instead

Definition at line 71 of file AbstractFile.php.

◆ FILETYPE_VIDEO

const TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_VIDEO = 4

Any kind of video

See also
http://www.iana.org/assignments/media-types/video
Deprecated:
‪will be removed in TYPO3 v14, use TYPO3\CMS\Core\Resource\FileType::VIDEO instead

Definition at line 99 of file AbstractFile.php.

◆ properties

‪TYPO3\CMS\Core\Resource\AbstractFile\$size
‪$size
Definition: AbstractFile.php:183
‪TYPO3\CMS\Core\Resource\AbstractFile\properties
‪array< non-empty-string, function getProperties() { return $this-> properties
Definition: AbstractFile.php:141