TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ProcessedFile Class Reference
Inheritance diagram for ProcessedFile:
AbstractFile FileInterface ResourceInterface

Public Member Functions

 __construct (File $originalFile, $taskType, array $processingConfiguration, array $databaseRow=null)
 
 calculateChecksum ()
 
 setContents ($contents)
 
 updateWithLocalFile ($filePath)
 
 isIndexed ()
 
 isPersisted ()
 
 isNew ()
 
 isUpdated ()
 
 setName ($name)
 
 isProcessed ()
 
 getOriginalFile ()
 
 getIdentifier ()
 
 getName ()
 
 updateProperties (array $properties)
 
 toArray ()
 
 setUsesOriginalFile ()
 
 usesOriginalFile ()
 
 isOutdated ()
 
 delete ($force=false)
 
 getProperty ($key)
 
 getUid ()
 
 needsReprocessing ()
 
 getProcessingConfiguration ()
 
 getTaskIdentifier ()
 
 getTask ()
 
 generateProcessedFileNameWithoutExtension ()
 
 getPublicUrl ($relativeToCurrentScript=false)
 
- Public Member Functions inherited from AbstractFile
 hasProperty ($key)
 
 getProperty ($key)
 
 getProperties ()
 
 getIdentifier ()
 
 getHashedIdentifier ()
 
 getName ()
 
 getNameWithoutExtension ()
 
 getSize ()
 
 getUid ()
 
 getSha1 ()
 
 getCreationTime ()
 
 getModificationTime ()
 
 getExtension ()
 
 getMimeType ()
 
 getType ()
 
 getContents ()
 
 setContents ($contents)
 
 getStorage ()
 
 exists ()
 
 setStorage (ResourceStorage $storage)
 
 setIdentifier ($identifier)
 
 getCombinedIdentifier ()
 
 delete ()
 
 setDeleted ()
 
 isDeleted ()
 
 rename ($newName)
 
 copyTo (Folder $targetFolder, $targetFileName=null, $conflictMode=DuplicationBehavior::RENAME)
 
 moveTo (Folder $targetFolder, $targetFileName=null, $conflictMode=DuplicationBehavior::RENAME)
 
 getPublicUrl ($relativeToCurrentScript=false)
 
 getForLocalProcessing ($writable=true)
 
 updateProperties (array $properties)
 
 getParentFolder ()
 

Public Attributes

const CONTEXT_IMAGEPREVIEW = 'Image.Preview'
 
const CONTEXT_IMAGECROPSCALEMASK = 'Image.CropScaleMask'
 
- Public Attributes inherited from AbstractFile
const FILETYPE_UNKNOWN = 0
 
const FILETYPE_TEXT = 1
 
const FILETYPE_IMAGE = 2
 
const FILETYPE_AUDIO = 3
 
const FILETYPE_VIDEO = 4
 
const FILETYPE_APPLICATION = 5
 

Protected Member Functions

 reconstituteFromDatabaseRecord (array $databaseRow)
 
 isUnchanged ()
 

Protected Attributes

 $taskType
 
 $task
 
 $taskTypeRegistry
 
 $processingConfiguration
 
 $originalFile
 
 $originalFileSha1
 
 $updated = false
 
- Protected Attributes inherited from AbstractFile
 $properties
 
 $storage = null
 
 $identifier
 
 $name
 
 $deleted = false
 

Detailed Description

Representation of a specific processed version of a file. These are created by the FileProcessingService, which in turn uses helper classes for doing the actual file processing. See there for a detailed description.

Objects of this class may be freshly created during runtime or being fetched from the database. The latter indicates that the file has been processed earlier and was then cached.

Each processed file—besides belonging to one file—has been created for a certain task (context) and configuration. All these won't change during the lifetime of a processed file; the only thing that can change is the original file, or rather it's contents. In that case, the processed file has to be processed again. Detecting this is done via comparing the current SHA1 hash of the original file against the one it had at the time the file was processed. The configuration of a processed file indicates what should be done to the original file to create the processed version. This may include things like cropping, scaling, rotating, flipping or using some special magic. A file may also meet the expectations set in the configuration without any processing. In that case, the ProcessedFile object still exists, but there is no physical file directly linked to it. Instead, it then redirects most method calls to the original file object. The data of these objects are also stored in the database, to indicate that no processing is required. With such files, the identifier and name fields in the database are empty to show this.

Definition at line 41 of file ProcessedFile.php.

Constructor & Destructor Documentation

__construct ( File  $originalFile,
  $taskType,
array  $processingConfiguration,
array  $databaseRow = null 
)

Constructor for a processed file object. Should normally not be used directly, use the corresponding factory methods instead.

Parameters
File$originalFile
string$taskType
array$processingConfiguration
array$databaseRow

Definition at line 115 of file ProcessedFile.php.

References ProcessedFile\$originalFile, ProcessedFile\$processingConfiguration, ProcessedFile\$taskType, AbstractFile\getStorage(), GeneralUtility\makeInstance(), and ProcessedFile\reconstituteFromDatabaseRecord().

Member Function Documentation

calculateChecksum ( )

Returns a unique checksum for this file's processing configuration and original file.

Returns
string

Definition at line 155 of file ProcessedFile.php.

References ProcessedFile\getTask().

Referenced by ProcessedFile\generateProcessedFileNameWithoutExtension(), ImageService\getCompatibilityImageResourceValues(), ProcessedFile\needsReprocessing(), and ProcessedFile\toArray().

delete (   $force = false)

Delete processed file

Parameters
bool$force
Returns
bool

Definition at line 425 of file ProcessedFile.php.

References ProcessedFile\isUnchanged(), and ProcessedFile\usesOriginalFile().

generateProcessedFileNameWithoutExtension ( )

Generate the name of of the new File

Returns
string

Definition at line 545 of file ProcessedFile.php.

References AbstractFile\$name, and ProcessedFile\calculateChecksum().

getIdentifier ( )

Get the identifier of the file

If there is no processed file in the file system (as the original file did not have to be modified e.g. when the original image is in the boundaries of the maxW/maxH stuff), then just return the identifier of the original file

Returns
string

Implements ResourceInterface.

Definition at line 297 of file ProcessedFile.php.

References ProcessedFile\getOriginalFile(), and ProcessedFile\usesOriginalFile().

Referenced by ProcessedFile\toArray().

getName ( )

Get the name of the file

If there is no processed file in the file system (as the original file did not have to be modified e.g. when the original image is in the boundaries of the maxW/maxH stuff) then just return the name of the original file

Returns
string

Implements ResourceInterface.

Definition at line 311 of file ProcessedFile.php.

References AbstractFile\$name, and ProcessedFile\usesOriginalFile().

Referenced by ProcessedFile\toArray(), and ResourceStorage\updateProcessedFile().

getProcessingConfiguration ( )

Returns the processing information

Returns
array

Definition at line 510 of file ProcessedFile.php.

References ProcessedFile\$processingConfiguration.

getProperty (   $key)

Getter for file-properties

Parameters
string$key
Returns
mixed

Implements FileInterface.

Definition at line 445 of file ProcessedFile.php.

References ProcessedFile\isUnchanged().

Referenced by ImageService\getCompatibilityImageResourceValues().

getPublicUrl (   $relativeToCurrentScript = false)

Returns a publicly accessible URL for this file

Parameters
bool$relativeToCurrentScriptDetermines whether the URL returned should be relative to the current script, in case it is relative at all
Returns
NULL|string NULL if file is deleted, the generated URL otherwise

Implements FileInterface.

Definition at line 560 of file ProcessedFile.php.

References ProcessedFile\getOriginalFile(), AbstractFile\getStorage(), and ProcessedFile\usesOriginalFile().

Referenced by ImageService\getCompatibilityImageResourceValues().

getTask ( )

Returns the task object associated with this processed file.

Returns
Processing
Exceptions
RuntimeException

Definition at line 531 of file ProcessedFile.php.

References ProcessedFile\$task.

Referenced by ProcessedFile\calculateChecksum(), and PreviewProcessing\getTargetFileName().

getTaskIdentifier ( )

Getter for the task identifier.

Returns
string

Definition at line 520 of file ProcessedFile.php.

References ProcessedFile\$taskType.

getUid ( )

Returns the uid of this file

Returns
int

Definition at line 460 of file ProcessedFile.php.

Referenced by ProcessedFile\toArray().

isIndexed ( )

Returns TRUE if this file is indexed

Returns
bool

Implements FileInterface.

Definition at line 208 of file ProcessedFile.php.

isNew ( )

Checks whether the ProcessedFile Object is newly created

Returns
bool

Definition at line 229 of file ProcessedFile.php.

References ProcessedFile\isPersisted().

isOutdated ( )

Returns TRUE if the original file of this file changed and the file should be processed again.

Returns
bool

Definition at line 414 of file ProcessedFile.php.

References ProcessedFile\needsReprocessing().

isPersisted ( )

Checks whether the ProcessedFile already has an entry in sys_file_processedfile table

Returns
bool

Definition at line 219 of file ProcessedFile.php.

Referenced by ProcessedFile\isNew(), and ProcessedFile\isProcessed().

isProcessed ( )

Returns TRUE if this file is already processed.

Returns
bool

Definition at line 273 of file ProcessedFile.php.

References ProcessedFile\isPersisted(), and ProcessedFile\needsReprocessing().

isUnchanged ( )
protected

Returns TRUE if this file has not been changed during processing (i.e., we just deliver the original file)

Returns
bool

Definition at line 385 of file ProcessedFile.php.

References ProcessedFile\usesOriginalFile().

Referenced by ProcessedFile\delete(), ProcessedFile\getProperty(), and ProcessedFile\updateProperties().

isUpdated ( )

Checks whether the object since last reconstitution, and therefore needs persistence again

Returns
bool

Definition at line 240 of file ProcessedFile.php.

References ProcessedFile\$updated.

needsReprocessing ( )
reconstituteFromDatabaseRecord ( array  $databaseRow)
protected

Creates a ProcessedFile object from a database record.

Parameters
array$databaseRow
Returns
ProcessedFile

Definition at line 134 of file ProcessedFile.php.

Referenced by ProcessedFile\__construct().

setContents (   $contents)

Replace the current file contents with the given string

Parameters
string$contentsThe contents to write to the file.
Returns
File The file object (allows chaining).
Exceptions
BadMethodCallException

Implements FileInterface.

Definition at line 170 of file ProcessedFile.php.

setName (   $name)

Sets a new file name

Parameters
string$name

Definition at line 250 of file ProcessedFile.php.

References AbstractFile\$name, and AbstractFile\exists().

setUsesOriginalFile ( )
Returns
void

Definition at line 393 of file ProcessedFile.php.

updateProperties ( array  $properties)

Updates properties of this object. Do not use this to reconstitute an object from the database; use reconstituteFromDatabaseRecord() instead!

Parameters
array$properties

Definition at line 326 of file ProcessedFile.php.

References MathUtility\canBeInterpretedAsInteger(), AbstractFile\exists(), and ProcessedFile\isUnchanged().

Referenced by ProcessedFile\updateWithLocalFile().

updateWithLocalFile (   $filePath)

Injects a local file, which is a processing result into the object.

Parameters
string$filePath
Returns
void
Exceptions
RuntimeException

Definition at line 182 of file ProcessedFile.php.

References ProcessedFile\updateProperties().

Member Data Documentation

$originalFile
protected

Definition at line 87 of file ProcessedFile.php.

Referenced by ProcessedFile\__construct(), and ProcessedFile\getOriginalFile().

$originalFileSha1
protected

Definition at line 96 of file ProcessedFile.php.

Referenced by ProcessedFile\needsReprocessing(), and ProcessedFile\toArray().

$processingConfiguration
protected
$task
protected

Definition at line 68 of file ProcessedFile.php.

Referenced by ProcessedFile\getTask().

$taskType
protected

Definition at line 63 of file ProcessedFile.php.

Referenced by ProcessedFile\__construct(), and ProcessedFile\getTaskIdentifier().

$taskTypeRegistry
protected

Definition at line 73 of file ProcessedFile.php.

$updated = false
protected

Definition at line 104 of file ProcessedFile.php.

Referenced by ProcessedFile\isUpdated().

const CONTEXT_IMAGECROPSCALEMASK = 'Image.CropScaleMask'

Standard processing context for the frontend, that was previously in ::getImgResource which only takes cropping, masking and scaling into account

Definition at line 56 of file ProcessedFile.php.

Referenced by ImageService\applyProcessingInstructions(), MagicImageService\createMagicImage(), DefaultAvatarProvider\getImage(), and ImageManipulationElement\getPreview().

const CONTEXT_IMAGEPREVIEW = 'Image.Preview'

Basic processing context to get a processed image with smaller width/height to render a preview

Definition at line 50 of file ProcessedFile.php.

Referenced by FileList\formatFileList(), FileBrowser\renderFilesInFolder(), AddImageHandler\renderFilesInFolder(), and InlineRecordContainer\renderForeignRecordHeader().