Fix map() template function

databind
Vitaliy Filippov 2015-04-10 15:30:57 +03:00
parent b1843eba7d
commit cd71d391c8
2 changed files with 17 additions and 7 deletions

View File

@ -4,7 +4,7 @@
* Homepage: http://yourcmc.ru/wiki/VMX::Template * Homepage: http://yourcmc.ru/wiki/VMX::Template
* License: GNU GPLv3 or later * License: GNU GPLv3 or later
* Author: Vitaliy Filippov, 2006-2015 * Author: Vitaliy Filippov, 2006-2015
* Version: V3 (LALR), 2015-04-08 * Version: V3 (LALR), 2015-04-10
* *
* This file contains the implementation of VMX::Template compiler. * This file contains the implementation of VMX::Template compiler.
* It is only used when a template is compiled in runtime. * It is only used when a template is compiled in runtime.
@ -634,19 +634,29 @@ $code
} }
/* map() */ /* map() */
// FIXME: Я думаю, что это не работает :-)
function function_map($f) function function_map($f)
{ {
if (!method_exists($this, "function_$f")) if (!preg_match('/^(["\'])([a-z_]+)\1$/s', $f, $m))
{
$this->lexer->warn("Non-constant function specified for map(): $f");
return 'false';
}
$fn = $m[2];
if (isset(self::$functions[$fn]))
{
// Function alias
$fn = self::$functions[$fn];
}
if (!method_exists($this, "function_$fn"))
{ {
$this->lexer->warn("Unknown function specified for map(): $f"); $this->lexer->warn("Unknown function specified for map(): $f");
return 'false'; return 'false';
} }
$f = "function_$f"; $fn = "function_$fn";
$f = $this->$f('$arg'); $fn = $this->$fn('$arg');
$args = func_get_args(); $args = func_get_args();
array_shift($args); array_shift($args);
return "call_user_func('array_map', create_function('$arg', $f), self::merge_to_array(".implode(", ", $args)."))"; return "array_map(function(\$arg) { return $fn; }, self::merge_to_array(".implode(", ", $args)."))";
} }
} }

View File

@ -8,7 +8,7 @@
* Homepage: http://yourcmc.ru/wiki/VMX::Template * Homepage: http://yourcmc.ru/wiki/VMX::Template
* License: GNU GPLv3 or later * License: GNU GPLv3 or later
* Author: Vitaliy Filippov, 2006-2015 * Author: Vitaliy Filippov, 2006-2015
* Version: V3 (LALR), 2015-04-08 * Version: V3 (LALR), 2015-04-10
* *
* The template engine is split into two parts: * The template engine is split into two parts:
* (1) This file - always used when running templates * (1) This file - always used when running templates