misuzu/src/Twig.php

24 lines
630 B
PHP
Raw Normal View History

2018-08-15 03:12:58 +02:00
<?php
namespace Misuzu;
use Twig_Environment;
use Twig_LoaderInterface;
use UnexpectedValueException;
2019-06-10 19:04:53 +02:00
final class Twig extends Twig_Environment {
2018-08-15 03:12:58 +02:00
protected static $instance = null;
2019-06-10 19:04:53 +02:00
public static function instance(): Twig_Environment {
2018-08-15 03:12:58 +02:00
return self::$instance;
}
2019-06-10 19:04:53 +02:00
public function __construct(Twig_LoaderInterface $loader, array $options = []) {
if(self::$instance !== null) {
2018-08-15 03:12:58 +02:00
throw new UnexpectedValueException('Instance of Twig already present, use the static instance() function.');
}
parent::__construct($loader, $options);
self::$instance = $this;
}
}