Class \Prado\Web\TAssetManager
TAssetManager provides a scheme to allow web clients visiting private files that are normally web-inaccessible.
TAssetManager will copy the file to be published into a web-accessible directory. The default base directory for storing the file is "assets", which should be under the application directory. This can be changed by setting the \Prado\Web\setBasePath property together with the \Prado\Web\setBaseUrl property that refers to the URL for accessing the base path.
By default, TAssetManager will not publish a file or directory if it already exists in the publishing directory and has an older modification time. If the application mode is set as 'Performance', the modification time check will be skipped. You can explicitly require a modification time check with the function publishFilePath. This is usually very useful during development.
TAssetManager may be configured in application configuration file as follows,
<module id="asset" BasePath="Application.assets" BaseUrl="/assets" />
where \Prado\Web\getBasePath and \Prado\Web\getBaseUrl are configurable properties of TAssetManager. Make sure that BasePath is a namespace pointing to a valid directory writable by the Web server process.
Class hierarchy
- \Prado\Web\TAssetManager
- \Prado\TModule implements IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.0
public
|
copyDirectory(string $src, string $dst) : mixed
Copies a directory recursively as another.
If the destination directory does not exist, it will be created. File modification time is used to ensure the copied files are latest. |
public
|
|
public
|
|
public
|
|
public
|
getPublishedPath(string $path) : string
Returns the published path of a file path.
This method does not perform any publishing. It merely tells you if the file path is published, where it will go. |
public
|
getPublishedUrl(string $path) : string
Returns the URL of a published file path.
This method does not perform any publishing. It merely tells you if the file path is published, what the URL will be to access it. |
public
|
init(TXmlElement $config) : mixed
Initializes the module.
This method is required by IModule and is invoked by application. |
public
|
publishFilePath(string $path[, bool $checkTimestamp = false ]) : string
Publishes a file or a directory (recursively).
This method will copy the content in a directory (recursively) to a web accessible directory and returns the URL for the directory. If the application is not in performance mode, the file modification time will be used to make sure the published file is latest or not. If not, a file copy will be performed. |
public
|
publishTarFile(string $tarfile, string $md5sum[, bool $checkTimestamp = false ]) : string
Publish a tar file by extracting its contents to the assets directory.
Each tar file must be accomplished with its own MD5 check sum file. The MD5 file is published when the tar contents are successfully extracted to the assets directory. The presence of the MD5 file as published asset assumes that the tar file has already been extracted. |
public
|
setBasePath(string $value) : mixed
Sets the root directory storing published asset files.
The directory must be in namespace format. |
public
|
|
protected
|
copyFile(string $src, string $dst) : mixed
Copies a file to a directory.
Copying is done only when the destination file does not exist or has an older file modification time. |
protected
|
deployTarFile(string $path, string $destination) : bool
Extracts the tar file to the destination directory.
N.B Tar file must not be compressed. |
protected
|
hash(string $dir) : string
Generate a CRC32 hash for the directory path. Collisions are higher
than MD5 but generates a much smaller hash string.
|
protected
|
public
mixed
|
DEFAULT_BASEPATH
Default web accessible base path for storing private files
|
'assets'
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |