PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class 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 setBasePath BasePath property together with the setBaseUrl 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 TAssetManager::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 getBasePath BasePath and getBaseUrl BaseUrl are configurable properties of TAssetManager. Make sure that BasePath is a namespace pointing to a valid directory writable by the Web server process.

TComponent
Extended by TApplicationComponent
Extended by TModule implements IModule
Extended by TAssetManager
Package: System\Web
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Web/TAssetManager.php
Methods summary
public
# init( TXmlElement $config )

Initializes the module. This method is required by IModule and is invoked by application.

Initializes the module. This method is required by IModule and is invoked by application.

Parameters

$config
TXmlElement
module configuration

Overrides

TModule::init()
public string
# getBasePath( )

Returns

string
the root directory storing published asset files
public
# setBasePath( string $value )

Sets the root directory storing published asset files. The directory must be in namespace format.

Sets the root directory storing published asset files. The directory must be in namespace format.

Parameters

$value
string
the root directory storing published asset files

Throws

TInvalidOperationException
if the module is initialized already
public string
# getBaseUrl( )

Returns

string
the base url that the published asset files can be accessed
public
# setBaseUrl( string $value )

Parameters

$value
string
the base url that the published asset files can be accessed

Throws

TInvalidOperationException
if the module is initialized already
public string
# publishFilePath( string $path, boolean $checkTimestamp = false )

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.

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.

Parameters

$path
string
the path to be published
$checkTimestamp
boolean
If true, file modification time will be checked even if the application is in performance mode.

Returns

string
an absolute URL to the published directory

Throws

TInvalidDataValueException
if the file path to be published is invalid

Overrides

TApplicationComponent::publishFilePath()
public array
# getPublished( )

Returns

array
List of published assets

Since

3.1.6
protected
# setPublished( mixed $values = array() )

Parameters

$values
mixed
$values List of published assets

Since

3.1.6
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.

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.

Parameters

$path
string
directory or file path being published

Returns

string
the published file path
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.

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.

Parameters

$path
string
directory or file path being published

Returns

string
the published URL for the 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.

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

Parameters

$dir
string
string to be hashed.

Returns

string
hashed string.
protected
# 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.

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

Parameters

$src
string
source file path
$dst
string
destination directory (if not exists, it will be created)
public
# 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.

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.

Parameters

$src
string
the source directory
$dst
string
the destination directory

Todo

a generic solution to ignore certain directories and files
public string
# publishTarFile( string $tarfile, string $md5sum, boolean $checkTimestamp = false )

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.

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.

Parameters

$tarfile
string
tar filename
$md5sum
string
MD5 checksum for the corresponding tar file.
$checkTimestamp
boolean
Wether or not to check the time stamp of the file for publishing. Defaults to false.

Returns

string
URL path to the directory where the tar file was extracted.
protected boolean
# deployTarFile( string $path, string $destination )

Extracts the tar file to the destination directory. N.B Tar file must not be compressed.

Extracts the tar file to the destination directory. N.B Tar file must not be compressed.

Parameters

$path
string
tar file
$destination
string
path where the contents of tar file are to be extracted

Returns

boolean
true if extract successful, false otherwise.
Methods inherited from TModule
getID(), setID()
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), getUser(), publishAsset()
Methods inherited from TComponent
__call(), __construct(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants summary
string DEFAULT_BASEPATH 'assets'
#

Default web accessible base path for storing private files

Default web accessible base path for storing private files

Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO