diff --git a/src/Twig/Extension.php b/src/Twig/Extension.php index d60329fbf7..d6376a1397 100644 --- a/src/Twig/Extension.php +++ b/src/Twig/Extension.php @@ -32,6 +32,7 @@ namespace App\Twig; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; +use Twig\TwigTest; class Extension extends AbstractExtension { @@ -42,6 +43,13 @@ class Extension extends AbstractExtension ]; } + public function getTests() + { + return [ + new TwigTest('instanceof', [Runtime::class, 'isInstanceOf']), + ]; + } + /** * get twig functions * diff --git a/src/Twig/Runtime.php b/src/Twig/Runtime.php index 5e7554e4a0..129aa9429b 100644 --- a/src/Twig/Runtime.php +++ b/src/Twig/Runtime.php @@ -119,11 +119,16 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface public function isFirefox(): bool { $re_has_chrome = '/.*(?i)\bchrome\b.*/m'; - $re_has_gecko = '/.*(?i)\bgecko\b.*/m'; + $re_has_gecko = '/.*(?i)\bgecko\b.*/m'; return (preg_match(pattern: $re_has_chrome, subject: $this->request->headers->get('User-Agent')) !== 1) && (preg_match(pattern: $re_has_gecko, subject: $this->request->headers->get('User-Agent')) === 1); } + public function isInstanceOf($var, string $instance): bool + { + return $var instanceof $instance; + } + // ---------------------------------------------------------- /**