| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of Twig. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
namespace ElementorDeps\Twig; |
| 12 |
|
| 13 |
/** |
| 14 |
* Exposes a template to userland. |
| 15 |
* |
| 16 |
* @author Fabien Potencier <fabien@symfony.com> |
| 17 |
*/ |
| 18 |
final class TemplateWrapper |
| 19 |
{ |
| 20 |
private $env; |
| 21 |
private $template; |
| 22 |
/** |
| 23 |
* This method is for internal use only and should never be called |
| 24 |
* directly (use Twig\Environment::load() instead). |
| 25 |
* |
| 26 |
* @internal |
| 27 |
*/ |
| 28 |
public function __construct(Environment $env, Template $template) |
| 29 |
{ |
| 30 |
$this->env = $env; |
| 31 |
$this->template = $template; |
| 32 |
} |
| 33 |
public function render(array $context = []) : string |
| 34 |
{ |
| 35 |
return $this->template->render($context); |
| 36 |
} |
| 37 |
public function display(array $context = []) |
| 38 |
{ |
| 39 |
// using func_get_args() allows to not expose the blocks argument |
| 40 |
// as it should only be used by internal code |
| 41 |
$this->template->display($context, \func_get_args()[1] ?? []); |
| 42 |
} |
| 43 |
public function hasBlock(string $name, array $context = []) : bool |
| 44 |
{ |
| 45 |
return $this->template->hasBlock($name, $context); |
| 46 |
} |
| 47 |
/** |
| 48 |
* @return string[] An array of defined template block names |
| 49 |
*/ |
| 50 |
public function getBlockNames(array $context = []) : array |
| 51 |
{ |
| 52 |
return $this->template->getBlockNames($context); |
| 53 |
} |
| 54 |
public function renderBlock(string $name, array $context = []) : string |
| 55 |
{ |
| 56 |
return $this->template->renderBlock($name, $this->env->mergeGlobals($context)); |
| 57 |
} |
| 58 |
public function displayBlock(string $name, array $context = []) |
| 59 |
{ |
| 60 |
$context = $this->env->mergeGlobals($context); |
| 61 |
foreach ($this->template->yieldBlock($name, $context) as $data) { |
| 62 |
echo $data; |
| 63 |
} |
| 64 |
} |
| 65 |
public function getSourceContext() : Source |
| 66 |
{ |
| 67 |
return $this->template->getSourceContext(); |
| 68 |
} |
| 69 |
public function getTemplateName() : string |
| 70 |
{ |
| 71 |
return $this->template->getTemplateName(); |
| 72 |
} |
| 73 |
/** |
| 74 |
* @internal |
| 75 |
* |
| 76 |
* @return Template |
| 77 |
*/ |
| 78 |
public function unwrap() |
| 79 |
{ |
| 80 |
return $this->template; |
| 81 |
} |
| 82 |
} |
| 83 |
|