Skip to content
Permalink
Browse files

TemplateFactory: sets only properties that exist (BC break)

  • Loading branch information
dg committed Mar 4, 2020
1 parent 638ab6a commit ce69f1b8c0af771859dd3ec4c2202c23d994acc8
@@ -93,13 +93,27 @@ public function createTemplate(UI\Control $control = null): UI\ITemplate
}

// default parameters
$template->user = $this->user;
$template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->withoutUserInfo()->getBaseUrl(), '/') : null;
$template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
$template->flashes = [];
$baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->withoutUserInfo()->getBaseUrl(), '/') : null;
$flashes = $presenter instanceof UI\Presenter && $presenter->hasFlashSession()
? (array) $presenter->getFlashSession()->{$control->getParameterId('flash')}
: [];

$params = [
'user' => $this->user,
'baseUrl' => $baseUrl,
'basePath' => $baseUrl ? preg_replace('#https?://[^/]+#A', '', $baseUrl) : null,
'flashes' => $flashes,
'control' => $control,
'presenter' => $presenter,
];

foreach ($params as $key => $value) {
if (property_exists($template, $key)) {
$template->$key = $value;
}
}

if ($control) {
$template->control = $control;
$template->presenter = $presenter;
$latte->addProvider('uiControl', $control);
$latte->addProvider('uiPresenter', $presenter);
$latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($control));
@@ -112,11 +126,6 @@ public function createTemplate(UI\Control $control = null): UI\ITemplate
}
$latte->addProvider('cacheStorage', $this->cacheStorage);

if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) {
$id = $control->getParameterId('flash');
$template->flashes = (array) $presenter->getFlashSession()->$id;
}

$this->onCreate($template);

return $template;
@@ -7,6 +7,7 @@
declare(strict_types=1);

use Nette\Application\UI;
use Nette\Bridges\ApplicationLatte\DefaultTemplate;
use Nette\Bridges\ApplicationLatte\ILatteFactory;
use Nette\Bridges\ApplicationLatte\Template;
use Nette\Bridges\ApplicationLatte\TemplateFactory;
@@ -18,7 +19,7 @@ require __DIR__ . '/../bootstrap.php';
Tester\Environment::bypassFinals();


class TemplateMock extends Template
class TemplateMock extends DefaultTemplate
{
private $file = 'ko';

0 comments on commit ce69f1b

Please sign in to comment.
You can’t perform that action at this time.