|
| 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 Template |
| 18 | +{ |
| 19 | + /** @var Latte\Template */ |
| 20 | + private $template; |
| 21 | + |
| 22 | + |
| 23 | + public function __construct(Latte\Template $template) |
| 24 | + { |
| 25 | + $this->template = $template; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Call a template run-time filter. |
| 30 | + */ |
| 31 | + public function __call($name, $args) |
| 32 | + { |
| 33 | + return call_user_func_array($this->template->filters->$name, $args); |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + /** |
| 38 | + * Sets a template parameter. |
| 39 | + * @return void |
| 40 | + */ |
| 41 | + public function __set($name, $value) |
| 42 | + { |
| 43 | + $this->template->params[$name] = $value; |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + /** |
| 48 | + * Returns a template parameter. |
| 49 | + * @return mixed value |
| 50 | + */ |
| 51 | + public function &__get($name) |
| 52 | + { |
| 53 | + if (!array_key_exists($name, $this->template->params)) { |
| 54 | + trigger_error("The variable '$name' does not exist in template."); |
| 55 | + } |
| 56 | + return $this->template->params[$name]; |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + /** |
| 61 | + * Determines whether parameter is defined. |
| 62 | + * @return bool |
| 63 | + */ |
| 64 | + public function __isset($name) |
| 65 | + { |
| 66 | + return isset($this->template->params[$name]); |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + /** |
| 71 | + * Removes a template parameter. |
| 72 | + * @param string name |
| 73 | + * @return void |
| 74 | + */ |
| 75 | + public function __unset($name) |
| 76 | + { |
| 77 | + unset($this->template->params[$name]); |
| 78 | + } |
| 79 | + |
| 80 | +} |
0 commit comments