ResourceManager
class ResourceManager (View source)
The ResourceManager
Constants
DEFAULT_STATIC_COLLECTION_NAME |
Names of the default collections for static and persistent resources. |
DEFAULT_PERSISTENT_COLLECTION_NAME |
|
PUBLIC_RESSOURCE_REGEXP |
|
Properties
protected ObjectManagerInterface | $objectManager | ||
protected LoggerInterface | $logger | ||
protected ResourceRepository | $resourceRepository | ||
protected PersistenceManagerInterface | $persistenceManager | ||
protected array | $settings | ||
protected Environment | $environment | ||
protected StorageInterface[] | $storages | ||
protected TargetInterface[] | $targets | ||
protected CollectionInterface[] | $collections | ||
protected bool | $initialized |
Methods
Injects the settings of this package
Injects the (system) logger based on PSR-3.
Initializes the ResourceManager by parsing the related configuration and registering the resource stream wrapper.
Imports a resource (file) from the given location as a persistent resource.
Imports the given content passed as a string as a new persistent resource.
Imports a resource (file) from the given upload info array as a persistent resource.
Returns the resource object identified by the given SHA1 hash over the content, or NULL if no such PersistentResource object is known yet.
Returns a stream handle of the given persistent resource which allows for opening / copying the resource's data. Note that this stream handle may only be used read-only.
Returns an object storage with all resource objects which have been imported by the ResourceManager during this script call. Each resource comes with an array of additional information about its import.
Deletes the given PersistentResource from the ResourceRepository and, if the storage data is no longer used in another PersistentResource object, also deletes the data from the storage.
Returns the web accessible URI for the given resource object
Returns the web accessible URI for the resource object specified by the given SHA1 hash.
Returns the public URI for a static resource provided by the specified package and in the given path below the package's resources directory.
Returns the public URI for a static resource provided by the public package
Return the package key and the relative path and filename from the given resource path
Returns a Storage instance by the given name
Returns a Collection instance by the given name
Returns an array of currently known Collection instances
Returns an array of Collection instances which use the given storage
Checks if recently imported resources really have been persisted - and if not, removes its data from the respective storage.
Initializes the Storage objects according to the current settings
Initializes the Target objects according to the current settings
Initializes the Collection objects according to the current settings
Prepare an uploaded file to be imported as resource object. Will check the validity of the file, move it outside of upload folder if open_basedir is enabled and check the filename.
Details
void
injectSettings(array $settings)
Injects the settings of this package
void
injectLogger(LoggerInterface $logger)
Injects the (system) logger based on PSR-3.
protected void
initialize()
Initializes the ResourceManager by parsing the related configuration and registering the resource stream wrapper.
PersistentResource
importResource(string|resource $source, string $collectionName = ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME, string $forcedPersistenceObjectIdentifier = null)
Imports a resource (file) from the given location as a persistent resource.
On a successful import this method returns a PersistentResource object representing the newly imported persistent resource and automatically publishes it to the configured publication target.
PersistentResource
importResourceFromContent(string $content, string $filename, string $collectionName = ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME, string $forcedPersistenceObjectIdentifier = null)
Imports the given content passed as a string as a new persistent resource.
The given content typically is binary data or a text format. On a successful import this method returns a PersistentResource object representing the imported content and automatically publishes it to the configured publication target.
The specified filename will be used when presenting the resource to a user. Its file extension is important because the resource management will derive the IANA Media Type from it.
PersistentResource
importUploadedResource(array $uploadInfo, string $collectionName = self::DEFAULT_PERSISTENT_COLLECTION_NAME)
Imports a resource (file) from the given upload info array as a persistent resource.
On a successful import this method returns a PersistentResource object representing the newly imported persistent resource.
PersistentResource|null
getResourceBySha1(string $sha1Hash)
Returns the resource object identified by the given SHA1 hash over the content, or NULL if no such PersistentResource object is known yet.
resource|bool
getStreamByResource(PersistentResource $resource)
Returns a stream handle of the given persistent resource which allows for opening / copying the resource's data. Note that this stream handle may only be used read-only.
SplObjectStorage
getImportedResources()
Returns an object storage with all resource objects which have been imported by the ResourceManager during this script call. Each resource comes with an array of additional information about its import.
Example for a returned object storage:
$resource1 => array('originalFilename' => 'Foo.txt'), $resource2 => array('originalFilename' => 'Bar.txt'), ...
bool
deleteResource(PersistentResource $resource, bool $unpublishResource = true)
Deletes the given PersistentResource from the ResourceRepository and, if the storage data is no longer used in another PersistentResource object, also deletes the data from the storage.
This method will also remove the PersistentResource object from the (internal) ResourceRepository.
string|bool
getPublicPersistentResourceUri(PersistentResource $resource)
Returns the web accessible URI for the given resource object
string
getPublicPersistentResourceUriByHash(string $resourceHash, string $collectionName = self::DEFAULT_PERSISTENT_COLLECTION_NAME)
Returns the web accessible URI for the resource object specified by the given SHA1 hash.
string
getPublicPackageResourceUri(string $packageKey, string $relativePathAndFilename)
Returns the public URI for a static resource provided by the specified package and in the given path below the package's resources directory.
string
getPublicPackageResourceUriByPath(string $path)
Returns the public URI for a static resource provided by the public package
array
getPackageAndPathByPublicPath(string $path)
Return the package key and the relative path and filename from the given resource path
StorageInterface
getStorage(string $storageName)
Returns a Storage instance by the given name
CollectionInterface
getCollection(string $collectionName)
Returns a Collection instance by the given name
CollectionInterface[]
getCollections()
Returns an array of currently known Collection instances
CollectionInterface[]
getCollectionsByStorage(StorageInterface $storage)
Returns an array of Collection instances which use the given storage
void
shutdownObject()
Checks if recently imported resources really have been persisted - and if not, removes its data from the respective storage.
protected void
initializeStorages()
Initializes the Storage objects according to the current settings
protected void
initializeTargets()
Initializes the Target objects according to the current settings
protected void
initializeCollections()
Initializes the Collection objects according to the current settings
protected array
prepareUploadedFileForImport(array $uploadInfo)
Prepare an uploaded file to be imported as resource object. Will check the validity of the file, move it outside of upload folder if open_basedir is enabled and check the filename.