Skip to content

Commit 141a241

Browse files
committed
Latte: removed usage of provider 'uiPresenter'
1 parent c3e0a43 commit 141a241

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

src/Bridges/ApplicationLatte/UIMacros.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public function macroLink(MacroNode $node, PhpWriter $writer)
115115
{
116116
$node->modifiers = preg_replace('#\|safeurl\s*(?=\||\z)#i', '', $node->modifiers);
117117
return $writer->using($node)
118-
->write('echo %escape(%modify('
119-
. ($node->name === 'plink' ? '$this->global->uiPresenter' : '$this->global->uiControl')
118+
->write('echo %escape(%modify($this->global->uiControl'
119+
. ($node->name === 'plink' ? '->getPresenter()' : '')
120120
. '->link(%node.word, %node.array?)))'
121121
);
122122
}
@@ -131,8 +131,8 @@ public function macroIfCurrent(MacroNode $node, PhpWriter $writer)
131131
throw new CompileException('Modifiers are not allowed in ' . $node->getNotation());
132132
}
133133
return $writer->write($node->args
134-
? 'if ($this->global->uiPresenter->isLinkCurrent(%node.word, %node.array?)) {'
135-
: 'if ($this->global->uiPresenter->getLastCreatedRequestFlag("current")) {'
134+
? 'if ($this->global->uiControl->getPresenter()->isLinkCurrent(%node.word, %node.array?)) {'
135+
: 'if ($this->global->uiControl->getPresenter()->getLastCreatedRequestFlag("current")) {'
136136
);
137137
}
138138

@@ -145,6 +145,6 @@ public function macroExtends(MacroNode $node, PhpWriter $writer)
145145
if ($node->modifiers || $node->parentNode || $node->args !== 'auto') {
146146
return $this->extends = false;
147147
}
148-
$this->extends = $writer->write('$this->parentName = $this->global->uiPresenter->findLayoutTemplateFile();');
148+
$this->extends = $writer->write('$this->parentName = $this->global->uiControl->getPresenter()->findLayoutTemplateFile();');
149149
}
150150
}

tests/Bridges.Latte/Template.getParentName().phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require __DIR__ . '/../bootstrap.php';
1111

1212
$presenter = Mockery::mock(Nette\Application\UI\Presenter::class)
1313
->shouldReceive('findLayoutTemplateFile')->andReturn('layout.latte')
14+
->shouldReceive('getPresenter')->andReturnSelf()
1415
->mock();
1516

1617
$latte = new Latte\Engine;
@@ -49,7 +50,7 @@ $template = $latte->createTemplate('{extends none}');
4950
$template->prepare();
5051
Assert::null($template->getParentName());
5152

52-
$latte->addProvider('uiPresenter', $presenter);
53+
$latte->addProvider('uiControl', $presenter);
5354
$template = $latte->createTemplate('{extends auto}');
5455
$template->prepare();
5556
Assert::same('layout.latte', $template->getParentName());

tests/Bridges.Latte/UIMacros.link.2.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class MockControl
2323
array_unshift($args, $destination);
2424
return 'link:' . strtr(json_encode($args), '"', "'");
2525
}
26+
27+
28+
public function getPresenter()
29+
{
30+
return new MockPresenter;
31+
}
2632
}
2733

2834

@@ -50,7 +56,6 @@ $latte->setLoader(new Latte\Loaders\StringLoader);
5056
UIMacros::install($latte->getCompiler());
5157

5258
$latte->addProvider('uiControl', new MockControl);
53-
$latte->addProvider('uiPresenter', new MockPresenter);
5459
$params['action'] = 'login';
5560
$params['arr'] = ['link' => 'login', 'param' => 123];
5661

tests/Bridges.Latte/UIMacros.renderSnippets.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class InnerControl extends Nette\Application\UI\Control
1919
{
2020
$latte = new Latte\Engine;
2121
UIMacros::install($latte->getCompiler());
22-
$latte->addProvider('uiPresenter', $this->getPresenter());
2322
$latte->addProvider('uiControl', $this);
2423
$latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($this));
2524
$params['say'] = 'Hello';

tests/Bridges.Latte/UIMacros.renderSnippets2.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class InnerControl extends Nette\Application\UI\Control
2828
$latte = new Latte\Engine;
2929
$latte->setLoader(new Latte\Loaders\StringLoader);
3030
UIMacros::install($latte->getCompiler());
31-
$latte->addProvider('uiPresenter', $this->getPresenter());
3231
$latte->addProvider('uiControl', $this);
3332
$latte->addProvider('snippetBridge', new SnippetBridge($this));
3433
$params['say'] = 'Hello';
@@ -41,7 +40,6 @@ class InnerControl extends Nette\Application\UI\Control
4140
$latte = new Latte\Engine;
4241
$latte->setLoader(new Latte\Loaders\StringLoader);
4342
UIMacros::install($latte->getCompiler());
44-
$latte->addProvider('uiPresenter', $this->getPresenter());
4543
$latte->addProvider('uiControl', $this);
4644
$latte->addProvider('snippetBridge', new SnippetBridge($this));
4745
$params['say'] = 'world';

tests/Bridges.Latte/UIMacros.renderSnippets3.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class TestControl extends Nette\Application\UI\Control
2020
$latte = new Latte\Engine;
2121
$latte->setLoader(new Latte\Loaders\StringLoader);
2222
UIMacros::install($latte->getCompiler());
23-
$latte->addProvider('uiPresenter', $this->getPresenter());
2423
$latte->addProvider('uiControl', $this);
2524
$latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($this));
2625
$latte->render('{snippet foo}hello{/snippet}');

0 commit comments

Comments
 (0)