Skip to content

Commit c9f5119

Browse files
committed
UIRuntime: created variable $template for back compatibility
1 parent c73d33b commit c9f5119

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

src/Bridges/ApplicationLatte/UIRuntime.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class UIRuntime
2626
*/
2727
public static function initialize(Latte\Template $template, $blockQueue)
2828
{
29+
// back compatibility
30+
new VariableTemplate($template);
31+
2932
// snippet support
3033
$params = $template->getParameters();
3134
if (!$template->getParentName() && !empty($params['_control']->snippetMode)) {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nette Framework (https://nette.org)
5+
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
namespace Nette\Bridges\ApplicationLatte;
9+
10+
use Latte;
11+
12+
13+
/**
14+
* Variable $template for back compatibility.
15+
* @internal
16+
*/
17+
class VariableTemplate extends Latte\Template
18+
{
19+
/** @var Latte\Template */
20+
private $template;
21+
22+
23+
public function __construct(Latte\Template $template)
24+
{
25+
$this->template = $template;
26+
$template->params['template'] = $this;
27+
}
28+
29+
/**
30+
* Call a template run-time filter.
31+
*/
32+
public function __call($name, $args)
33+
{
34+
return call_user_func_array($this->template->filters->$name, $args);
35+
}
36+
37+
38+
/**
39+
* Sets a template parameter.
40+
* @return void
41+
*/
42+
public function __set($name, $value)
43+
{
44+
$this->template->params[$name] = $value;
45+
}
46+
47+
48+
/**
49+
* Returns a template parameter.
50+
* @return mixed value
51+
*/
52+
public function &__get($name)
53+
{
54+
if (!array_key_exists($name, $this->template->params)) {
55+
trigger_error("The variable '$name' does not exist in template.");
56+
}
57+
return $this->template->params[$name];
58+
}
59+
60+
61+
/**
62+
* Determines whether parameter is defined.
63+
* @return bool
64+
*/
65+
public function __isset($name)
66+
{
67+
return isset($this->template->params[$name]);
68+
}
69+
70+
71+
/**
72+
* Removes a template parameter.
73+
* @param string name
74+
* @return void
75+
*/
76+
public function __unset($name)
77+
{
78+
unset($this->template->params[$name]);
79+
}
80+
81+
}

0 commit comments

Comments
 (0)