public function __construct($str) { static $templateFunctions; if (!$templateFunctions) { $templateFunctions = new Functions(); } $str = Template::unTokenize($str); // Parse all arg function calls in the passed string, // callback creates default values. $self = $this; $captureCallback = function ($str) use(&$self) { $args = Functions::parseArgsSimple($str); $position = array_shift($args); // Match the argument index integer. if (!isset($position) || !ctype_digit($position)) { return ''; } // Store the default value. $defaultValue = isset($args[0]) ? $args[0] : null; if (isset($defaultValue)) { $self->defaults[$position] = $defaultValue; } // Update argument count. $argNumber = (int) $position + 1; $self->argCount = max($self->argCount, $argNumber); return "?a{$position}?"; }; $templateFunctions->register['#'] = $captureCallback; $templateFunctions->register['arg'] = $captureCallback; $this->string = $templateFunctions->apply($str); }
function loop($process) { $process->string->pregReplaceCallback(LOOP_PATT, function ($m) { return Template::tokenize(loop_unroll(Template::unTokenize($m[0]))); }); }