You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
PHTML
44 lines
1.0 KiB
PHTML
4 years ago
|
<?php
|
||
|
/**
|
||
|
* Created by PhpStorm.
|
||
|
* User: eater
|
||
|
* Date: 1/16/18
|
||
|
* Time: 5:25 PM
|
||
|
*/
|
||
|
|
||
|
namespace BitCommunism\Twig\Handler;
|
||
|
|
||
|
|
||
|
use BitCommunism\Http\Handler;
|
||
|
use BitCommunism\Twig\Psr7\TwigStream;
|
||
|
use DI\Container;
|
||
|
use Twig\Environment;
|
||
|
|
||
|
class Twig extends Handler
|
||
|
{
|
||
|
protected $environment;
|
||
|
protected $templateVariables = [];
|
||
|
|
||
|
public function __construct(Environment $environment, Container $container)
|
||
|
{
|
||
|
$this->environment = $environment;
|
||
|
parent::__construct($container);
|
||
|
}
|
||
|
|
||
|
public function setTemplateVariable($key, $value) {
|
||
|
$this->templateVariables[$key] = $value;
|
||
|
}
|
||
|
|
||
|
public function appendTemplateVariables($variables) {
|
||
|
$this->templateVariables = array_merge($this->templateVariables, $variables);
|
||
|
}
|
||
|
|
||
|
public function template($template, $variables) {
|
||
|
$stream = new TwigStream($this->environment);
|
||
|
$stream->setTemplate($template);
|
||
|
$stream->appendVariables($this->templateVariables);
|
||
|
$stream->appendVariables($variables);
|
||
|
|
||
|
return $stream;
|
||
|
}
|
||
|
}
|