mirror of
https://github.com/twigphp/Twig.git
synced 2026-11-04 10:05:03 +00:00
Fix compat with older versions of PHP
This commit is contained in:
+1
-1
@@ -131,7 +131,7 @@ class Environment
|
||||
$this->setCache($options['cache']);
|
||||
$this->extensionSet = new ExtensionSet();
|
||||
$this->defaultRuntimeLoader = new FactoryRuntimeLoader([
|
||||
EscaperRuntime::class => fn () => new EscaperRuntime($options['autoescape'], $this->charset),
|
||||
EscaperRuntime::class => function () use ($options) { return new EscaperRuntime($options['autoescape'], $this->charset); },
|
||||
]);
|
||||
|
||||
$this->addExtension(new CoreExtension());
|
||||
|
||||
@@ -21,12 +21,13 @@ use Twig\TwigFilter;
|
||||
|
||||
final class EscaperExtension extends AbstractExtension
|
||||
{
|
||||
private ?Environment $environment = null;
|
||||
private array $escapers = [];
|
||||
private $environment;
|
||||
private $escapers = [];
|
||||
private $escaper;
|
||||
|
||||
public function __construct(
|
||||
private EscaperRuntime $escaper,
|
||||
) {
|
||||
public function __construct(EscaperRuntime $escaper)
|
||||
{
|
||||
$this->escaper = $escaper;
|
||||
}
|
||||
|
||||
public function getTokenParsers(): array
|
||||
@@ -94,7 +95,7 @@ final class EscaperExtension extends AbstractExtension
|
||||
{
|
||||
trigger_deprecation('twig/twig', '3.10', 'The "%s()" method is deprecated, use the "Twig\Runtime\EscaperRuntime::setEscaper()" method instead (be warned that Environment is not passed anymore to the callable).', __METHOD__);
|
||||
|
||||
if (!$this->environment) {
|
||||
if (!isset($this->environment)) {
|
||||
throw new \LogicException('You must call setEnvironment() before calling setEscaper().');
|
||||
}
|
||||
|
||||
|
||||
@@ -27,16 +27,17 @@ final class EscaperRuntime implements RuntimeExtensionInterface
|
||||
/** @internal */
|
||||
public $safeLookup = [];
|
||||
|
||||
private $charset;
|
||||
|
||||
/**
|
||||
* @param string|false|callable $defaultStrategy An escaping strategy
|
||||
*
|
||||
* @see setDefaultStrategy()
|
||||
*/
|
||||
public function __construct(
|
||||
$defaultStrategy = 'html',
|
||||
private string $charset = 'UTF-8',
|
||||
) {
|
||||
public function __construct($defaultStrategy = 'html', $charset = 'UTF-8')
|
||||
{
|
||||
$this->setDefaultStrategy($defaultStrategy);
|
||||
$this->charset = $charset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +128,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function escape($string, string $strategy = 'html', ?string $charset = null, bool $autoescape = false): mixed
|
||||
public function escape($string, string $strategy = 'html', ?string $charset = null, bool $autoescape = false)
|
||||
{
|
||||
if ($autoescape && $string instanceof Markup) {
|
||||
return $string;
|
||||
|
||||
Reference in New Issue
Block a user