- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

Packages: default System System.Caching System.Collections System.Data System.Data.ActiveRecord System.Data.ActiveRecord.Relations System.Data.ActiveRecord.Scaffold System.Data.ActiveReecord.Scaffold.InputBuilder System.Data.Commom.Sqlite System.Data.Common System.Data.Common.Mssql System.Data.Common.Mysql System.Data.Common.Oracle System.Data.Common.Pgsql System.Data.Common.Sqlite System.Data.DataGateway System.Data.SqlMap System.Data.SqlMap.Configuration System.Data.SqlMap.Statements System.Exceptions System.I18N System.IO System.Security System.Util System.Web System.Web.Services System.Web.UI System.Web.UI.ActiveControls System.Web.UI.WebControls System.Web.UI.WebControls.assets System.Xml Classes: TAssetManager TCacheHttpSession THttpCookie THttpCookieCollection THttpRequest THttpRequestUrlFormat THttpResponse THttpResponseAdapter THttpSession THttpSessionCookieMode THttpUtility TSessionIterator TUri TUrlManager TUrlMapping TUrlMappingPattern |
Keyword
# Class TAssetManager
    TComponent
       |
       --TApplicationComponent
          |
          --TModule
             |
             --TAssetManager
TAssetManager class 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 BasePath property together with the BaseUrl 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 BasePath and BaseUrl are configurable properties of TAssetManager. Make sure that BasePath is a namespace pointing to a valid directory writable by the Web server process. Since: 3.0 Author: Qiang Xue <qiang.xue@gmail.com>
Method Summary
void | copyDirectory ( string $src, string $dst) Copies a directory recursively as another.
protected void | copyFile ( string $src, string $dst) Copies a file to a directory.
protected boolean | deployTarFile ( string $path, string $destination) Extracts the tar file to the destination directory.
string | getBasePath ()
string | getBaseUrl ()
protected array | getPublished ()
string | getPublishedPath ( string $path) Returns the published path of a file path.
string | getPublishedUrl ( string $path) Returns the URL of a published file path.
protected string | hash ( string $dir) Generate a CRC32 hash for the directory path. Collisions are higher than MD5 but generates a much smaller hash string.
void | init ( TXmlElement $config) Initializes the module.
string | publishFilePath ( string $path, boolean $checkTimestamp) Publishes a file or a directory (recursively).
string | publishTarFile ( string $tarfile, string $md5sum, boolean $checkTimestamp) Publish a tar file by extracting its contents to the assets directory.
void | setBasePath ( string $value) Sets the root directory storing published asset files.
void | setBaseUrl ( string $value)
protected void | setPublished ( $values $values)
Methods Inherited From TModule
TModule::getID(), TModule::init(), TModule::setID()
Methods Inherited From TApplicationComponent
TApplicationComponent::getApplication(), TApplicationComponent::getRequest(), TApplicationComponent::getResponse(), TApplicationComponent::getService(), TApplicationComponent::getSession(), TApplicationComponent::getUser(), TApplicationComponent::publishAsset(), TApplicationComponent::publishFilePath()
Methods Inherited From TComponent
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
Constant Summary
string | DEFAULT_BASEPATH | Default web accessible base path for storing private files
Method Details
## copyDirectory
public void copyDirectory | (string $src , string $dst )
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.
Input
string | $src | the source directory
string | $dst | the destination directory
Output
Exception
## copyFile
protected void copyFile | (string $src , string $dst )
Copies a file to a directory. Copying is done only when the destination file does not exist or has an older file modification time.
Input
string | $src | source file path
string | $dst | destination directory (if not exists, it will be created)
Output
Exception
## deployTarFile
protected boolean deployTarFile | (string $path , string $destination )
Extracts the tar file to the destination directory. N.B Tar file must not be compressed.
Input
string | $path | tar file
string | $destination | path where the contents of tar file are to be extracted
Output
boolean | true if extract successful, false otherwise.
Exception
## getBasePath
public string getBasePath | ()
Output
string | the root directory storing published asset files
Exception
## getBaseUrl
public string getBaseUrl | ()
Output
string | the base url that the published asset files can be accessed
Exception
## getPublished
protected array getPublished | ()
Output
array | List of published assets
Exception
## getPublishedPath
public string getPublishedPath | (string $path )
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.
Input
string | $path | directory or file path being published
Output
string | the published file path
Exception
## getPublishedUrl
public string getPublishedUrl | (string $path )
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.
Input
string | $path | directory or file path being published
Output
string | the published URL for the file path
Exception
## hash
protected string hash | (string $dir )
Generate a CRC32 hash for the directory path. Collisions are higher than MD5 but generates a much smaller hash string.
Input
string | $dir | string to be hashed.
Output
string | hashed string.
Exception
## init
public void init | (TXmlElement $config )
Initializes the module. This method is required by IModule and is invoked by application.
Input
TXmlElement | $config | module configuration
Output
Exception
## publishFilePath
public string publishFilePath | (string $path , boolean $checkTimestamp )
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.
Input
string | $path | the path to be published
boolean | $checkTimestamp | If true, file modification time will be checked even if the application is in performance mode.
Output
string | an absolute URL to the published directory
Exception
throws | TInvalidDataValueException if the file path to be published is invalid
## publishTarFile
public string publishTarFile | (string $tarfile , string $md5sum , boolean $checkTimestamp )
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.
Input
string | $tarfile | tar filename
string | $md5sum | MD5 checksum for the corresponding tar file.
boolean | $checkTimestamp | Wether or not to check the time stamp of the file for publishing. Defaults to false.
Output
string | URL path to the directory where the tar file was extracted.
Exception
## setBasePath
public void setBasePath | (string $value )
Sets the root directory storing published asset files. The directory must be in namespace format.
Input
string | $value | the root directory storing published asset files
Output
Exception
throws | TInvalidOperationException if the module is initialized already
## setBaseUrl
public void setBaseUrl | (string $value )
Input
string | $value | the base url that the published asset files can be accessed
Output
Exception
throws | TInvalidOperationException if the module is initialized already
## setPublished
protected void setPublished | ($values $values )
Input
$values | $values | List of published assets
Output
Exception
Constant Details
### DEFAULT_BASEPATH Default web accessible base path for storing private files #### Type: string #### Value: 'assets'