Class TAssetManager

Description

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,

  1. <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
  • version: $Id: TAssetManager.php 2112 2007-08-06 18:58:55Z xue $
  • author: Qiang Xue <qiang.xue@gmail.com>

Located in /Web/TAssetManager.php (line 45)

TComponent
   |
   --TApplicationComponent
      |
      --TModule
         |
         --TAssetManager
Class Constant Summary
 DEFAULT_BASEPATH = 'assets'
Method Summary
void copyDirectory (string $src, string $dst)
void copyFile (string $src, string $dst)
boolean deployTarFile (string $path, string $destination)
string getBasePath ()
string getBaseUrl ()
string getPublishedPath (string $path)
string getPublishedUrl (string $path)
string hash (string $dir)
void init (TXmlElement $config)
string publishFilePath (string $path, [boolean $checkTimestamp = false])
string publishTarFile (string $tarfile, string $md5sum, [boolean $checkTimestamp = false])
void setBasePath (string $value)
void setBaseUrl (string $value)
Methods
copyDirectory (line 254)

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.

  • access: public
  • todo: a generic solution to ignore certain directories and files
void copyDirectory (string $src, string $dst)
  • string $src: the source directory
  • string $dst: the destination directory
copyFile (line 231)

Copies a file to a directory.

Copying is done only when the destination file does not exist or has an older file modification time.

  • access: protected
void copyFile (string $src, string $dst)
  • string $src: source file path
  • string $dst: destination directory (if not exists, it will be created)
deployTarFile (line 322)

Extracts the tar file to the destination directory.

N.B Tar file must not be compressed.

  • return: true if extract successful, false otherwise.
  • access: protected
boolean deployTarFile (string $path, string $destination)
  • string $path: tar file
  • string $destination: path where the contents of tar file are to be extracted
getBasePath (line 97)
  • return: the root directory storing published asset files
  • access: public
string getBasePath ()
getBaseUrl (line 123)
  • return: the base url that the published asset files can be accessed
  • access: public
string getBaseUrl ()
getPublishedPath (line 188)

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.

  • return: the published file path
  • access: public
string getPublishedPath (string $path)
  • string $path: directory or file path being published
getPublishedUrl (line 204)

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.

  • return: the published URL for the file path
  • access: public
string getPublishedUrl (string $path)
  • string $path: directory or file path being published
hash (line 219)

Generate a CRC32 hash for the directory path. Collisions are higher than MD5 but generates a much smaller hash string.

  • return: hashed string.
  • access: protected
string hash (string $dir)
  • string $dir: string to be hashed.
init (line 81)

Initializes the module.

This method is required by IModule and is invoked by application.

  • access: public
void init (TXmlElement $config)

Redefinition of:
TModule::init()
Initializes the module.
publishFilePath (line 154)

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.

  • return: an absolute URL to the published directory
  • access: public
  • throws: TInvalidDataValueException if the file path to be published is invalid
string publishFilePath (string $path, [boolean $checkTimestamp = false])
  • 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.

Redefinition of:
TApplicationComponent::publishFilePath()
Publishes a file or directory and returns its URL.
publishTarFile (line 292)

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.

  • return: URL path to the directory where the tar file was extracted.
  • access: public
string publishTarFile (string $tarfile, string $md5sum, [boolean $checkTimestamp = false])
  • 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.
setBasePath (line 108)

Sets the root directory storing published asset files.

The directory must be in namespace format.

  • access: public
  • throws: TInvalidOperationException if the module is initialized already
void setBasePath (string $value)
  • string $value: the root directory storing published asset files
setBaseUrl (line 132)
  • access: public
  • throws: TInvalidOperationException if the module is initialized already
void setBaseUrl (string $value)
  • string $value: the base url that the published asset files can be accessed

Inherited Methods

Inherited From TModule

TModule::getID()
TModule::init()
TModule::setID()

Inherited From TApplicationComponent

TApplicationComponent::getApplication()
TApplicationComponent::getRequest()
TApplicationComponent::getResponse()
TApplicationComponent::getService()
TApplicationComponent::getSession()
TApplicationComponent::getUser()
TApplicationComponent::publishAsset()
TApplicationComponent::publishFilePath()

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()
Class Constants
DEFAULT_BASEPATH = 'assets' (line 50)

Default web accessible base path for storing private files

Documentation generated on Mon, 21 Apr 2008 11:30:30 -0400 by phpDocumentor 1.3.0RC4