class PersistentResource implements ResourceMetaDataInterface, CacheAwareInterface (View source)

Model representing a persistable resource

Properties

protected string $collectionName

Name of a collection whose storage is used for storing this resource and whose target is used for publishing.

protected string $filename

Filename which is used when the data of this resource is downloaded as a file or acting as a label

protected int $fileSize

The size of this object's data

protected string $relativePublicationPath

An optional relative path which can be used by a publishing target for structuring resources into directories

protected string $mediaType

The IANA media type of this resource

protected string $sha1

SHA1 hash identifying the content attached to this resource

protected string $md5

MD5 hash identifying the content attached to this resource

protected bool $protected

As soon as the PersistentResource has been published, modifying this object is not allowed

protected bool $lifecycleEventsActive
protected bool $deleted

An internal flag which tells if this PersistentResource object has been deleted during the current request

protected ResourceManager $resourceManager
protected Environment $environment
protected string $temporaryLocalCopyPathAndFilename

Methods

void
initializeObject(int $initializationCause)

Protects this PersistentResource if it has been persisted already.

resource|bool
getStream()

Returns a stream for use with read-only file operations such as reading or copying.

void
setCollectionName(string $collectionName)

Sets the name of the collection this resource should be part of

string
getCollectionName()

Returns the name of the collection this resource is part of

void
setFilename(string $filename)

Sets the filename which is used when this resource is downloaded or saved as a file

string
getFilename()

Gets the filename

string
getFileExtension()

Returns the file extension used for this resource

void
setRelativePublicationPath(string $path)

Sets a relative path which can be used by a publishing target for structuring resources into directories

string
getRelativePublicationPath()

Returns the relative publication path

void
setMediaType(string $mediaType)

Explicitly sets the Media Type for this resource

string
getMediaType()

Returns the Media Type for this resource

void
setFileSize(string $fileSize)

Sets the size of the content of this resource

string
getFileSize()

Returns the size of the content of this resource

string
getSha1()

Returns the SHA1 hash of the content of this resource

void
setSha1(string $sha1)

Sets the SHA1 hash of the content of this resource

string
getMd5() deprecated

Returns the MD5 hash of the content of this resource

void
setMd5(string $md5) deprecated

Sets the MD5 hash of the content of this resource

string
createTemporaryLocalCopy()

Returns the path to a local file representing this resource for use with read-only file operations such as reading or copying.

void
postPersist()

Doctrine lifecycle event callback which is triggered on "postPersist" events.

void
preRemove()

Doctrine lifecycle event callback which is triggered on "preRemove" events.

void
disableLifecycleEvents()

A very internal function which disables the Doctrine lifecycle events for this PersistentResource.

void
setDeleted(bool $flag = true)

An internal method which marks the PersistentResource object as deleted.

bool
isDeleted()

An internal method which tells if this PersistentResource object has been already deleted by the ResourceManager.

string
getCacheEntryIdentifier()

Returns a string which distinctly identifies this object and thus can be used as an identifier for cache entries related to this object. Introduced through the CacheAwareInterface.

void
throwExceptionIfProtected()

Throws an exception if this PersistentResource object is protected against modifications.

void
shutdownObject()

Takes care of removing a possibly existing temporary local copy on destruction of this object.

Details

void initializeObject(int $initializationCause)

Protects this PersistentResource if it has been persisted already.

Parameters

int $initializationCause

Return Value

void

resource|bool getStream()

Returns a stream for use with read-only file operations such as reading or copying.

Note: The caller is responsible to close the returned resource by calling fclose($stream)

Return Value

resource|bool

A stream which points to the data of this resource for read-access or false if the stream could not be obtained

void setCollectionName(string $collectionName)

Sets the name of the collection this resource should be part of

Parameters

string $collectionName

Name of the collection

Return Value

void

string getCollectionName()

Returns the name of the collection this resource is part of

Return Value

string

Name of the collection, for example "persistentResources"

void setFilename(string $filename)

Sets the filename which is used when this resource is downloaded or saved as a file

Parameters

string $filename

Return Value

void

string getFilename()

Gets the filename

Return Value

string

The filename

string getFileExtension()

Returns the file extension used for this resource

Return Value

string

The file extension used for this file

void setRelativePublicationPath(string $path)

Sets a relative path which can be used by a publishing target for structuring resources into directories

Parameters

string $path

Return Value

void

string getRelativePublicationPath()

Returns the relative publication path

Return Value

string

void setMediaType(string $mediaType)

Explicitly sets the Media Type for this resource

Parameters

string $mediaType

The IANA Media Type

Return Value

void

string getMediaType()

Returns the Media Type for this resource

Return Value

string

The IANA Media Type

void setFileSize(string $fileSize)

Sets the size of the content of this resource

Parameters

string $fileSize

The content size

Return Value

void

string getFileSize()

Returns the size of the content of this resource

Return Value

string

The md5 hash

string getSha1()

Returns the SHA1 hash of the content of this resource

Return Value

string

The sha1 hash

void setSha1(string $sha1)

Sets the SHA1 hash of the content of this resource

Parameters

string $sha1

The sha1 hash

Return Value

void

string getMd5() deprecated

deprecated since 6.3, will be removed with 7.0 – use getSha1() instead or md5(stream_get_contents($resource->getStream())) if you need an MD5 hash

Returns the MD5 hash of the content of this resource

Return Value

string

The md5 hash

void setMd5(string $md5) deprecated

deprecated since 6.3, will be removed with 7.0 – @see getMd5()

Sets the MD5 hash of the content of this resource

Parameters

string $md5

The md5 hash

Return Value

void

string createTemporaryLocalCopy()

Returns the path to a local file representing this resource for use with read-only file operations such as reading or copying.

Note that you must not store or publish file paths returned from this method as they will change with every request.

Return Value

string

Absolute path and filename pointing to the temporary local copy of this resource

Exceptions

Exception

void postPersist()

Doctrine lifecycle event callback which is triggered on "postPersist" events.

This method triggers the publication of this resource.

Return Value

void

void preRemove()

Doctrine lifecycle event callback which is triggered on "preRemove" events.

This method triggers the deletion of data related to this resource.

Return Value

void

void disableLifecycleEvents()

A very internal function which disables the Doctrine lifecycle events for this PersistentResource.

This is needed when some low-level operations need to be done, for example deleting a PersistentResource from the ResourceRepository without unpublishing the (probably not existing) data from the storage.

Return Value

void

void setDeleted(bool $flag = true)

An internal method which marks the PersistentResource object as deleted.

This method is called by the ResourceManager in order to prevent other code parts, for example the Doctrine lifecycle events, to delete this resource again.

Parameters

bool $flag

Return Value

void

bool isDeleted()

An internal method which tells if this PersistentResource object has been already deleted by the ResourceManager.

Return Value

bool

string getCacheEntryIdentifier()

Returns a string which distinctly identifies this object and thus can be used as an identifier for cache entries related to this object. Introduced through the CacheAwareInterface.

Return Value

string

protected void throwExceptionIfProtected()

Throws an exception if this PersistentResource object is protected against modifications.

Return Value

void

Exceptions

Exception

void shutdownObject()

Takes care of removing a possibly existing temporary local copy on destruction of this object.

Note: we can't use destruct() here because this would lead Doctrine to create a proxy method destruct() which will run __load(), which in turn will trigger the SQL protection in Flow Security, which will then discover that a possibly previously existing session has been half-destroyed already (see FLOW-121).

Return Value

void