- Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- int(3) bool(true) bool(true) int(1) bool(true) bool(false) int(2) bool(false) bool(true) int(0) bool(false) bool(false)
<?php
class Twig {
const TWIG_PREFIX = 1;
const SHORT = 2;
public static function getMode(string $input): int
{
$mode = 0;
if (str_contains($input, '<twig:')) {
$mode |= Twig::TWIG_PREFIX;
}
if (preg_match_all('/<([A-Z][a-zA-Z0-9_:-]+)([^>]*)>/', $input, $matches, \PREG_SET_ORDER)) {
$mode |= Twig::SHORT;
}
return $mode;
}
}
// Both
$input = '<twig:test></twig:test> <Test>test</Test>';
$mode = Twig::getMode($input);
var_dump($mode);
$hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX);
$hasShort = (bool) ($mode & Twig::SHORT);
var_dump($hasTwigPrefix);
var_dump($hasShort);
// Twig
$input = '<twig:test></twig:test>';
$mode = Twig::getMode($input);
var_dump($mode);
$hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX);
$hasShort = (bool) ($mode & Twig::SHORT);
var_dump($hasTwigPrefix);
var_dump($hasShort);
// Short
$input = '<Test>test</Test>';
$mode = Twig::getMode($input);
var_dump($mode);
$hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX);
$hasShort = (bool) ($mode & Twig::SHORT);
var_dump($hasTwigPrefix);
var_dump($hasShort);
// Nothing
$input = '<section>test</section>';
$mode = Twig::getMode($input);
var_dump($mode);
$hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX);
$hasShort = (bool) ($mode & Twig::SHORT);
var_dump($hasTwigPrefix);
var_dump($hasShort);