Support block calls with positional parameters in PHP version
parent
cc4434a2fe
commit
7b2f556c71
|
@ -4,7 +4,7 @@
|
|||
* Homepage: http://yourcmc.ru/wiki/VMX::Template
|
||||
* License: GNU GPLv3 or later
|
||||
* Author: Vitaliy Filippov, 2006-2015
|
||||
* Version: V3 (LALR), 2015-02-17
|
||||
* Version: V3 (LALR), 2015-03-09
|
||||
*
|
||||
* This file contains the implementation of VMX::Template compiler.
|
||||
* It is only used when a template is compiled in runtime.
|
||||
|
@ -194,7 +194,7 @@ class VMXTemplateCompiler
|
|||
foreach ($this->st->functions as $n => $f)
|
||||
{
|
||||
$code .= $f['body'];
|
||||
$functions[$n] = true;
|
||||
$functions[$n] = $f['args'];
|
||||
}
|
||||
|
||||
// Assemble the class code
|
||||
|
@ -225,7 +225,7 @@ $code
|
|||
$fn = self::$functions[$fn];
|
||||
}
|
||||
$argv = [];
|
||||
$q = @self::$functionSafeness[$fn];
|
||||
$q = isset(self::$functionSafeness[$fn]) ? self::$functionSafeness[$fn] : false;
|
||||
if ($q > 0)
|
||||
{
|
||||
$q = isset($args[$q-1]) ? $args[$q-1][1] : true;
|
||||
|
@ -234,7 +234,7 @@ $code
|
|||
{
|
||||
$q = true;
|
||||
}
|
||||
else
|
||||
elseif ($q == self::Q_IF_ALL || $q == self::Q_ALL_BUT_FIRST)
|
||||
{
|
||||
$q = true;
|
||||
$n = count($args);
|
||||
|
@ -259,8 +259,9 @@ $code
|
|||
}
|
||||
else
|
||||
{
|
||||
$this->lexer->warn("Unknown function: '$fn'");
|
||||
$r = "false";
|
||||
// A block reference or unknown function
|
||||
$r = "\$this->parent->call_block_list('$fn', array(".implode(', ', $argv)."), '".addcslashes($this->lexer->errorinfo(), "'\\")."')";
|
||||
$q = true;
|
||||
}
|
||||
return [ $r, $q ];
|
||||
}
|
||||
|
|
23
template.php
23
template.php
|
@ -8,7 +8,7 @@
|
|||
* Homepage: http://yourcmc.ru/wiki/VMX::Template
|
||||
* License: GNU GPLv3 or later
|
||||
* Author: Vitaliy Filippov, 2006-2015
|
||||
* Version: V3 (LALR), 2015-02-17
|
||||
* Version: V3 (LALR), 2015-03-09
|
||||
*
|
||||
* The template engine is split into two parts:
|
||||
* (1) This file - always used when running templates
|
||||
|
@ -65,7 +65,7 @@ class VMXTemplate
|
|||
const TS_RFC822 = 7;
|
||||
|
||||
// Version of code classes, saved into static $version
|
||||
const CODE_VERSION = 4;
|
||||
const CODE_VERSION = 5;
|
||||
|
||||
// Data passed to the template
|
||||
var $tpldata = array();
|
||||
|
@ -296,11 +296,11 @@ class VMXTemplate
|
|||
);
|
||||
return NULL;
|
||||
}
|
||||
foreach ($class::$functions as $loaded_function => $true)
|
||||
foreach ($class::$functions as $loaded_function => $args)
|
||||
{
|
||||
// FIXME Do it better
|
||||
// Remember functions during file loading
|
||||
$this->function_search_path[$loaded_function][] = $fn;
|
||||
$this->function_search_path[$loaded_function][] = array($fn, $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -459,10 +459,21 @@ class VMXTemplate
|
|||
if (isset($this->function_search_path[$block]))
|
||||
{
|
||||
// FIXME maybe do it better!
|
||||
$fn = $this->function_search_path[$block][0];
|
||||
$fn = $this->function_search_path[$block][0][0];
|
||||
return $this->parse_real($fn, NULL, $block, $args);
|
||||
}
|
||||
throw new VMXTemplateException("$errorinfo Unknown block '$block'");
|
||||
throw new VMXTemplateException("Unknown block '$block'$errorinfo");
|
||||
}
|
||||
|
||||
function call_block_list($block, $args, $errorinfo)
|
||||
{
|
||||
if (isset($this->function_search_path[$block]))
|
||||
{
|
||||
$fun = $this->function_search_path[$block][0];
|
||||
$args = array_combine($fun[1], array_pad(array_slice($args, 0, count($fun[1])), count($fun[1]), NULL));
|
||||
return $this->parse_real($fun[0], NULL, $block, $args);
|
||||
}
|
||||
throw new VMXTemplateException("Unknown block or function '$block'$errorinfo");
|
||||
}
|
||||
|
||||
static function array1($a)
|
||||
|
|
Loading…
Reference in New Issue