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}
* @author Jordi Boggiano <j.boggiano@seld.be>
* @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) {
* 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')) {
$compiler->setCustomPlugins($dwoo->getCustomPlugins());
$compiler->setSecurityPolicy($dwoo->getSecurityPolicy());
if ($this->chmod !==
null) {
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
* @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) {
return new Dwoo_Template_File($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';
Documentation generated on Sun, 07 Sep 2008 23:57:47 +0200 by phpDocumentor 1.4.0