Skip to content

Commit

Permalink
UIMacros: modifiers are deprecated in {control}, {link} and {plink}
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 26, 2020
1 parent 9b0b6c8 commit e6b3ed4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/Bridges/ApplicationLatte/UIMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public function finalize()
*/
public function macroControl(MacroNode $node, PhpWriter $writer)
{
if ($node->modifiers) {
trigger_error('Modifiers are deprecated in ' . $node->getNotation(), E_USER_DEPRECATED);
}
$words = $node->tokenizer->fetchWords();
if (!$words) {
throw new CompileException('Missing control name in {control}');
Expand Down Expand Up @@ -120,6 +123,9 @@ public function macroControl(MacroNode $node, PhpWriter $writer)
*/
public function macroLink(MacroNode $node, PhpWriter $writer)
{
if ($node->modifiers) {
trigger_error('Modifiers are deprecated in ' . $node->getNotation(), E_USER_DEPRECATED);
}
$node->modifiers = preg_replace('#\|safeurl\s*(?=\||$)#Di', '', $node->modifiers);
return $writer->using($node, $this->getCompiler())
->write('echo %escape(%modify('
Expand Down Expand Up @@ -161,6 +167,9 @@ public function macroExtends(MacroNode $node, PhpWriter $writer)
*/
public function macroTemplatePrint(MacroNode $node)
{
if ($node->modifiers) {
throw new CompileException('Modifiers are not allowed in ' . $node->getNotation());
}
$this->printTemplate = var_export($node->tokenizer->fetchWord() ?: null, true);
}
}
4 changes: 2 additions & 2 deletions tests/Bridges.Latte/UIMacros.control.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ UIMacros::install($compiler);

// {control ...}
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(); ?>', $compiler->expandMacro('control', 'form', '')->openingCode);
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(); echo ($this->filters->filter)(%a%); ?>', $compiler->expandMacro('control', 'form', 'filter')->openingCode);
@Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(); echo ($this->filters->filter)(%a%); ?>', $compiler->expandMacro('control', 'form', 'filter')->openingCode); // @ deprecated
Assert::match('<?php %a% if (is_object($form)) %a% else %a% $this->global->uiControl->getComponent($form); %a%->render(); ?>', $compiler->expandMacro('control', '$form', '')->openingCode);
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType(); ?>', $compiler->expandMacro('control', 'form:type', '')->openingCode);
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->{"render$type"}(); ?>', $compiler->expandMacro('control', 'form:$type', '')->openingCode);
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType(\'param\'); ?>', $compiler->expandMacro('control', 'form:type param', '')->openingCode);
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(array_merge([], $params, [])); ?>', $compiler->expandMacro('control', 'form (expand) $params', '')->openingCode);
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType([\'param\' => 123]); ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode);
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->renderType([\'param\' => 123]); ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode);
Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(); echo ($this->filters->striptags)(%a%); ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode);
@Assert::match('<?php %a% $this->global->uiControl->getComponent("form"); %a%->render(); echo ($this->filters->striptags)(%a%); ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode); // @ deprecated
2 changes: 1 addition & 1 deletion tests/Bridges.Latte/UIMacros.link.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ UIMacros::install($compiler);

// {link ...}
Assert::same('<?php echo $this->global->uiControl->link("p") ?>', $compiler->expandMacro('link', 'p', '')->openingCode);
Assert::same('<?php echo ($this->filters->filter)($this->global->uiControl->link("p")) ?>', $compiler->expandMacro('link', 'p', 'filter')->openingCode);
@Assert::same('<?php echo ($this->filters->filter)($this->global->uiControl->link("p")) ?>', $compiler->expandMacro('link', 'p', 'filter')->openingCode); // @ deprecated
Assert::same('<?php echo $this->global->uiControl->link("p:a") ?>', $compiler->expandMacro('link', 'p:a', '')->openingCode);
Assert::same('<?php echo $this->global->uiControl->link($dest) ?>', $compiler->expandMacro('link', '$dest', '')->openingCode);
Assert::same('<?php echo $this->global->uiControl->link($p:$a) ?>', $compiler->expandMacro('link', '$p:$a', '')->openingCode);
Expand Down

0 comments on commit e6b3ed4

Please sign in to comment.