forked from GNUsocial/gnu-social
[TWIG] Add instanceof
test
Use with: {% if var is instanceof(Namespace\Class) %}
This commit is contained in:
parent
2d8b220e92
commit
1107d8257d
@ -32,6 +32,7 @@ namespace App\Twig;
|
|||||||
|
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
use Twig\TwigTest;
|
||||||
|
|
||||||
class Extension extends AbstractExtension
|
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
|
* get twig functions
|
||||||
*
|
*
|
||||||
|
@ -124,6 +124,11 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface
|
|||||||
&& (preg_match(pattern: $re_has_gecko, 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;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user