Perforce Chronicle 2012.2/486814
API Documentation
|
Provide a local file backend for Asset Handling. More...
Public Member Functions | |
__construct (array $options=null) | |
Constructor allows passing options for outputPath or basePath. | |
exists ($id) | |
Check if the given ID exists in storage. | |
getBasePath () | |
Returns the base path presently in use. | |
getOutputPath () | |
Returns the output path presently in use or null. | |
isOffsite () | |
Used to determine if the asset handler will be storing assets offsite or not. | |
put ($id, $data) | |
Store the passed data using indicated ID. | |
setBasePath ($path) | |
Sets the base path to use. | |
setOutputPath ($path) | |
Sets the output path to use. | |
uri ($id) | |
Provide a URI for the indicated asset ID. | |
Protected Attributes | |
$_basePath | |
$_outputPath |
Provide a local file backend for Asset Handling.
This is the default backend and is intended for single web server deployments. If you wish to use this backend with horizontally scaled web servers the output path should point to a shared storage location (e.g. nfs).
P4Cms_AssetHandler_File::__construct | ( | array $ | options = null | ) |
Constructor allows passing options for outputPath or basePath.
array | $options | Options to use on this instance |
{ if (isset($options['outputPath'])) { $this->setOutputPath($options['outputPath']); } if (isset($options['basePath'])) { $this->setBasePath($options['basePath']); } }
P4Cms_AssetHandler_File::exists | ( | $ | id | ) |
Check if the given ID exists in storage.
string | $id | The ID to test |
Implements P4Cms_AssetHandlerInterface.
{ if (!$this->getOutputPath()) { return false; } return file_exists($this->getOutputPath() . '/' . $id); }
P4Cms_AssetHandler_File::getBasePath | ( | ) |
Returns the base path presently in use.
Defaults to the value of BASE_PATH define if not set.
{
return $this->_basePath ?: BASE_PATH;
}
P4Cms_AssetHandler_File::getOutputPath | ( | ) |
Returns the output path presently in use or null.
{
return $this->_outputPath;
}
P4Cms_AssetHandler_File::isOffsite | ( | ) |
Used to determine if the asset handler will be storing assets offsite or not.
Assets such as CSS need to know this so they can decide if they need to include the site's url when referencing images.
Implements P4Cms_AssetHandlerInterface.
{ return false; }
P4Cms_AssetHandler_File::put | ( | $ | id, |
$ | data | ||
) |
Store the passed data using indicated ID.
Will clobber any existing entry with the same ID.
string | $id | The ID to store under |
string | $data | The data to store |
Implements P4Cms_AssetHandlerInterface.
{ if (!$this->getOutputPath()) { return false; } $result = @file_put_contents($this->getOutputPath() . '/' . $id, $data); // if we failed to write, log as a warning and return false. if ($result === false) { $writable = is_writable($this->getOutputPath()); $message = "Failed to put asset '" . $id . "'. Output path is " . ($writable ? '' : 'not ') . 'writable'; P4Cms_Log::log($message, P4Cms_Log::WARN); return false; } else { return true; } }
P4Cms_AssetHandler_File::setBasePath | ( | $ | path | ) |
Sets the base path to use.
Set to null to enable default base path.
string | null | $path | The base path to use or null for default |
{ if (!is_string($path) && !is_null($path)) { throw new InvalidArgumentException('Path must be a string or null'); } $this->_basePath = $path ? rtrim($path, '/\\') : $path; return $this; }
P4Cms_AssetHandler_File::setOutputPath | ( | $ | path | ) |
Sets the output path to use.
string | null | $path | The output path |
{ if (!is_string($path) && !is_null($path)) { throw new InvalidArgumentException('Path must be a string or null'); } // if we have a path strip trailing slashes and try to ensure it exists if ($path) { $path = rtrim($path, '/\\'); @mkdir($path, 0755, true); } $this->_outputPath = $path; return $this; }
P4Cms_AssetHandler_File::uri | ( | $ | id | ) |
Provide a URI for the indicated asset ID.
string | $id | The ID to get a URI for |
Implements P4Cms_AssetHandlerInterface.
{ if (!$this->getOutputPath()) { return false; } $request = Zend_Controller_Front::getInstance()->getRequest(); $baseUrl = isset($request) ? $request->getBaseUrl() : ''; return $baseUrl . str_replace($this->getBasePath(), '', $this->getOutputPath()) . "/" . $id; }
P4Cms_AssetHandler_File::$_basePath [protected] |
P4Cms_AssetHandler_File::$_outputPath [protected] |