Fix functions check

databind
vitalif 2013-06-17 22:52:35 +00:00 committed by Vitaliy Filippov
parent 92dab3ce32
commit 4898b9598a
2 changed files with 13 additions and 7 deletions

View File

@ -186,13 +186,15 @@ class VMXTemplateCompiler
// Generate code for functions // Generate code for functions
$code = ''; $code = '';
foreach ($this->st->functions as $f) $functions = array();
foreach ($this->st->functions as $n => $f)
{ {
$code .= $f['body']; $code .= $f['body'];
$functions[$n] = true;
} }
// Assemble the class code // Assemble the class code
$functions = var_export(array_keys($this->st->functions), true); $functions = var_export($functions, true);
$rfn = addcslashes($this->options->input_filename, '\\\''); $rfn = addcslashes($this->options->input_filename, '\\\'');
$code = "<?php // {$this->options->input_filename} $code = "<?php // {$this->options->input_filename}
class Template_$func_ns extends VMXTemplate { class Template_$func_ns extends VMXTemplate {

View File

@ -65,7 +65,7 @@ class VMXTemplate
const TS_RFC822 = 7; const TS_RFC822 = 7;
// Version of code classes, saved into static $version // Version of code classes, saved into static $version
const CODE_VERSION = 3; const CODE_VERSION = 4;
// Data passed to the template // Data passed to the template
var $tpldata = array(); var $tpldata = array();
@ -285,11 +285,15 @@ class VMXTemplate
} }
if (!class_exists($class) || !isset($class::$version) || $class::$version < self::CODE_VERSION) if (!class_exists($class) || !isset($class::$version) || $class::$version < self::CODE_VERSION)
{ {
$this->options->error("MD5 collision :) file=$fn, cache=$file", true); // Force recompile
$this->failed[$fn] = true; $file = $this->compile($text, $fn, true);
$this->options->error(
"Invalid or stale cache '$file' for template '$fn'. Caused by one of:".
" template upgrade (error should go away on next run), two templates with same content (change or merge), or an MD5 collision :)", true
);
return NULL; return NULL;
} }
foreach ($class::$functions as $loaded_function) foreach ($class::$functions as $loaded_function => $true)
{ {
// FIXME Do it better // FIXME Do it better
// Remember functions during file loading // Remember functions during file loading
@ -299,7 +303,7 @@ class VMXTemplate
} }
if (!isset($class::$functions[$func])) if (!isset($class::$functions[$func]))
{ {
$this->options->error("No function '$func' found in template $fn", true); $this->options->error("No function '$func' found in ".($fn ? "template $fn" : 'inline template'), true);
return NULL; return NULL;
} }
$func = "fn_$func"; $func = "fn_$func";