2014-05-14 23:24:20 +10:00
|
|
|
<?php namespace System\Twig;
|
|
|
|
|
2020-10-13 19:14:31 +11:00
|
|
|
use System\Twig\Loader as TwigLoader;
|
2019-03-27 13:15:17 -06:00
|
|
|
use Twig\Environment as TwigEnvironment;
|
2017-08-08 21:55:48 -04:00
|
|
|
use Illuminate\Contracts\View\Engine as EngineInterface;
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* View engine used by the system, used for converting .htm files to twig.
|
|
|
|
*
|
|
|
|
* @package october\system
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
|
|
|
class Engine implements EngineInterface
|
|
|
|
{
|
|
|
|
/**
|
2019-03-27 13:15:17 -06:00
|
|
|
* @var TwigEnvironment
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
|
|
|
protected $environment;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2019-03-27 13:15:17 -06:00
|
|
|
public function __construct(TwigEnvironment $environment)
|
2014-05-14 23:24:20 +10:00
|
|
|
{
|
|
|
|
$this->environment = $environment;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get($path, array $vars = [])
|
|
|
|
{
|
2020-10-13 19:14:31 +11:00
|
|
|
$previousAllow = TwigLoader::$allowInclude;
|
|
|
|
|
|
|
|
TwigLoader::$allowInclude = true;
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
$template = $this->environment->loadTemplate($path);
|
2020-10-13 19:14:31 +11:00
|
|
|
|
|
|
|
TwigLoader::$allowInclude = $previousAllow;
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
return $template->render($vars);
|
|
|
|
}
|
2014-10-18 11:58:50 +02:00
|
|
|
}
|