Skip to content

Commit 2cb0e4f

Browse files
committed
UIMacros: {control x: 1} support named arguments
1 parent 8ffa8fc commit 2cb0e4f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Bridges/ApplicationLatte/UIMacros.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,16 @@ public function macroControl(MacroNode $node, PhpWriter $writer)
9999

100100
$tokens = $node->tokenizer;
101101
$pos = $tokens->position;
102-
$param = $writer->formatArray();
103-
$tokens->position = $pos;
102+
$wrap = false;
104103
while ($tokens->nextToken()) {
105-
if ($tokens->isCurrent('=>') && !$tokens->depth) {
104+
if ($tokens->isCurrent('=>', '(expand)') && !$tokens->depth) {
106105
$wrap = true;
107106
break;
108107
}
109108
}
110-
if (empty($wrap) && $param[0] === '[') {
111-
$param = substr($param, 1, -1); // removes array() or []
112-
}
109+
$tokens->position = $pos;
110+
$param = $wrap ? $writer->formatArray() : $writer->formatArgs();
111+
113112
return "/* line $node->startLine */ "
114113
. ($name[0] === '$' ? "if (is_object($name)) \$_tmp = $name; else " : '')
115114
. '$_tmp = $this->global->uiControl->getComponent(' . $name . '); '

tests/Bridges.Latte/UIMacros.control.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->re
2727
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType([\'param\' => 123]); ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode);
2828
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType([\'param\' => 123]); ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode);
2929
@Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(); echo ($this->filters->striptags)(%a%); ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode); // @ deprecated
30+
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType(param: 123); ?>', $compiler->expandMacro('control', 'form:type, param: 123', '')->openingCode);

0 commit comments

Comments
 (0)