Commit 770f1f70 by Seldaek

Small fixes here and there

git-svn-id: svn://dwoo.org/dwoo/trunk@195 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent b9d663a3
......@@ -5,6 +5,8 @@
IPluginProxy interface, that's it
+ Compiler: the modifier syntax (|foo) can now be applied on functions and on
complex variables i.e. {$obj->getStuff()|upper} or {lower('foo')|upper}
* ZendFramework: major overhaul thanks to Denis Arh, templates files should
probably be moved in the scripts subfolder after this update though
* Plugins: improved the dump plugin, it now displays object's properties
and optionally public methods (if the new show_methods arg is set to true)
- thanks to Stephan Wentz for the patch
......
......@@ -1406,6 +1406,9 @@ class Dwoo
$tree =& $this->scopeTree;
$data =& $this->data;
if (!is_string($scope)) {
return $this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR);
}
if (strstr($scope, '.') === false && strstr($scope, '->') === false) {
$this->scope[$scope] = $value;
} else {
......
......@@ -103,54 +103,18 @@ class Dwoo_Template_File extends Dwoo_Template_String
{
return $this->includePath;
}
/**
* 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
* @return string
* Checks if compiled file is valid (exists and it's the modification is greater or
* equal to the modification time of the template file)
*
* @param string file
* @return boolean True cache file existance and it's modification time
*/
public function getCompiledTemplate(Dwoo $dwoo, Dwoo_ICompiler $compiler = null)
{
$compiledFile = $this->getCompiledFilename($dwoo);
if ($this->compilationEnforced !== true && isset(self::$cache['compiled'][$this->compileId]) === true) {
// already checked, return compiled file
} elseif ($this->compilationEnforced !== true && file_exists($compiledFile)===true && (int)$this->getUid() <= filemtime($compiledFile)) {
// template is compiled and has not been modified since the compilation
self::$cache['compiled'][$this->compileId] = true;
} else {
// compiles the template
$this->compilationEnforced = false;
if ($compiler === null) {
$compiler = $dwoo->getDefaultCompilerFactory($this->getResourceName());
if ($compiler === null || $compiler === array('Dwoo_Compiler', 'compilerFactory')) {
if (class_exists('Dwoo_Compiler', false) === false) {
include DWOO_DIRECTORY . 'Dwoo/Compiler.php';
}
$compiler = Dwoo_Compiler::compilerFactory();
} else {
$compiler = call_user_func($compiler);
}
}
$this->compiler = $compiler;
$compiler->setCustomPlugins($dwoo->getCustomPlugins());
$compiler->setSecurityPolicy($dwoo->getSecurityPolicy());
$this->makeDirectory(dirname($compiledFile));
file_put_contents($compiledFile, $compiler->compile($dwoo, $this));
if ($this->chmod !== null) {
chmod($compiledFile, $this->chmod);
}
self::$cache['compiled'][$this->compileId] = true;
}
return $compiledFile;
protected function isValidCompiledFile($file) {
return parent::isValidCompiledFile($file) && (int)$this->getUid() <= filemtime($file);
}
/**
......
......@@ -346,7 +346,7 @@ class Dwoo_Template_String implements Dwoo_ITemplate
if ($this->compilationEnforced !== true && isset(self::$cache['compiled'][$this->compileId]) === true) {
// already checked, return compiled file
} elseif ($this->compilationEnforced !== true && file_exists($compiledFile)===true) {
} elseif ($this->compilationEnforced !== true && $this->isValidCompiledFile($compiledFile)) {
// template is compiled
self::$cache['compiled'][$this->compileId] = true;
} else {
......@@ -381,6 +381,16 @@ class Dwoo_Template_String implements Dwoo_ITemplate
return $compiledFile;
}
/**
* Checks if compiled file is valid (it exists)
*
* @param string file
* @return boolean True cache file existance
*/
protected function isValidCompiledFile($file) {
return file_exists($file);
}
/**
* returns a new template string object with the resource id being the template source code
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment