Source for file File.php
Documentation is available at File.php
* represents a Dwoo template contained in a file
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* include path(s) to look into to find this template
* resolved path cache when looking for a file in multiple include paths
* this is reset when the include path is changed
* creates a template from a file
* @param string $file the path to the template file, make sure it exists
* @param int $cacheTime duration of the cache validity for this template,
* if null it defaults to the Dwoo instance that will
* @param string $cacheId the unique cache identifier of this page or anything else that
* makes this template's content unique, if null it defaults
* @param string $compileId the unique compiled identifier, which is used to distinguish this
* template from others, if null it defaults to the filename+bits of the path
* @param mixed $includePath a string for a single path to look into for the given file, or an array of paths
public function __construct($file, $cacheTime =
null, $cacheId =
null, $compileId =
null, $includePath =
null)
if ($compileId !==
null) {
* sets the include path(s) to where the given template filename must be looked up
* @param mixed $paths the path to look into, can be string for a single path or an array of paths
* return the current include path(s)
* Checks if compiled file is valid (exists and it's the modification is greater or
* equal to the modification time of the template file)
* @return boolean True cache file existance and it's modification time
* returns the template source of this template
* returns the resource name for this template class
* returns this template's source filename
$path =
rtrim($path, DIRECTORY_SEPARATOR);
throw
new Dwoo_Exception('Template "'.
$this->file.
'" could not be found in any of your include path(s)');
* returns an unique value identifying the current version of this template,
* in this case it's the unix timestamp of the last modification
* returns a new template object from the given include name, null if no include is
* possible (resource not found), or false if include is not permitted by this resource type
* @param Dwoo $dwoo the dwoo instance requiring it
* @param mixed $resourceId the filename (relative to this template's dir) of the template to include
* @param int $cacheTime duration of the cache validity for this template,
* if null it defaults to the Dwoo instance that will
* @param string $cacheId the unique cache identifier of this page or anything else that
* makes this template's content unique, if null it defaults
* @param string $compileId the unique compiled identifier, which is used to distinguish this
* template from others, if null it defaults to the filename+bits of the path
* @param Dwoo_ITemplate $parentTemplate the template that is requesting a new template object (through
* an include, extends or any other plugin)
* @return Dwoo_Template_File|null
public static function templateFactory(Dwoo $dwoo, $resourceId, $cacheTime =
null, $cacheId =
null, $compileId =
null, Dwoo_ITemplate $parentTemplate =
null)
if (DIRECTORY_SEPARATOR ===
'\\') {
$resourceId =
str_replace(array("\t", "\n", "\r", "\f", "\v"), array('\\t', '\\n', '\\r', '\\f', '\\v'), $resourceId);
$resourceId =
strtr($resourceId, '\\', '/');
if ($parentTemplate ===
null) {
$parentTemplate =
$dwoo->getTemplate();
if ($includePath =
$parentTemplate->getIncludePath()) {
if (strstr($resourceId, '../')) {
throw
new Dwoo_Exception('When using an include path you can not reference a template into a parent directory (using ../)');
$resourceId =
dirname($parentTemplate->getResourceIdentifier()).
DIRECTORY_SEPARATOR.
$resourceId;
if ($policy =
$dwoo->getSecurityPolicy()) {
if (preg_match('{^([a-z]+?)://}i', $resourceId)) {
throw
new Dwoo_Security_Exception('The security policy prevents you to read files from external sources : <em>'.
$resourceId.
'</em>.');
$dirs =
$policy->getAllowedDirectories();
foreach ($dirs as $dir=>
$dummy) {
if (strpos($resourceId, $dir) ===
0) {
$class =
'Dwoo_Template_File';
return new $class($resourceId, $cacheTime, $cacheId, $compileId, $includePath);
* returns the full compiled file name and assigns a default value to it if
* @param Dwoo $dwoo the dwoo instance that requests the file name
* @return string the full path to the compiled file
// no compile id was provided, set default
return $dwoo->getCompileDir() .
$this->compileId.
'.d'.
Dwoo::RELEASE_TAG.
'.php';
* returns some php code that will check if this template has been modified or not
* if the function returns null, the template will be instanciated and then the Uid checked
Documentation generated on Sun, 07 Feb 2010 17:53:45 +0000 by phpDocumentor 1.4.0