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.
* This file is released under the LGPL
* "GNU Lesser General Public License"
* More information can be found here:
* {@link http://www.gnu.org/copyleft/lesser.html}
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public 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) {
$this->compileId =
strtr($compileId, '\\%?=!:;'.
PATH_SEPARATOR, '/-------');
$this->cacheId =
strtr($cacheId, '\\%?=!:;'.
PATH_SEPARATOR, '/-------');
* 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)
* returns the compiled template file name
* @param Dwoo $dwoo the dwoo instance that requests it
* @param Dwoo_ICompiler $compiler the compiler that must be used
// already checked, return compiled file
// template is compiled and has not been modified since the compilation
self::$cache['compiled'][$this->compileId] =
true;
if ($compiler ===
null) {
$compiler =
$dwoo->getDefaultCompilerFactory('string');
if ($compiler ===
null ||
$compiler ===
array('Dwoo_Compiler', 'compilerFactory')) {
include 'Dwoo/Compiler.php';
$compiler->setCustomPlugins($dwoo->getCustomPlugins());
$compiler->setSecurityPolicy($dwoo->getSecurityPolicy());
self::$cache['compiled'][$this->compileId] =
true;
* returns the template source of this template
* returns the resource name for this template class
* returns this template's source filename
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
* @return Dwoo_Template_File|null
public static function templateFactory(Dwoo $dwoo, $resourceId, $cacheTime =
null, $cacheId =
null, $compileId =
null)
$resourceId =
str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $resourceId);
$tpl =
$dwoo->getTemplate();
$resourceId =
dirname($tpl->getResourceIdentifier()).
DIRECTORY_SEPARATOR.
$resourceId;
// prevent template recursion if security is in effect
if ($policy =
$dwoo->getSecurityPolicy()) {
$tpl =
$dwoo->getTemplate();
if ($tpl instanceof
Dwoo_Template_File &&
$resourceId ===
$tpl->getResourceIdentifier()) {
return $dwoo->triggerError('You can not include a template into itself', E_USER_WARNING);
* 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';
Documentation generated on Sun, 03 Aug 2008 15:12:35 +0200 by phpDocumentor 1.4.0