';
+ $linkToObject[] .= '
';
+ $linkToObject[] .= '
documentService = $documentService;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getFunctions(): array
+ {
+ return [
+ new TwigFunction('twigExtensionLocalizedLinks',
+ [$this, 'getLocalizedLinks']),
+ new TwigFunction('twigExtensionLanguageFlag',
+ [$this, 'getLanguageFlag'])
+ ];
+ }
+
+ public function getLocalizedLinks(Document $document): array
+ {
+ $translations = $this->documentService->getTranslations($document);
+
+ $links = [];
+ foreach (Tool::getValidLanguages() as $language) {
+ $target = trim('/' . $language);
+
+ //skip if root document for local is missing
+ if (!(Document::getByPath($target) instanceof Document)) {
+ continue;
+ }
+
+ if (isset($translations[$language])) {
+ $localizedDocument = Document::getById($translations[$language]);
+ if ($localizedDocument) {
+ $target = $localizedDocument->getFullPath();
+ }
+ }
+
+ $links[$language] = [
+ 'link' => $target,
+ 'text' => \Locale::getDisplayLanguage($language)
+ ];
+ }
+
+ return $links;
+ }
+
+ /**
+ * @param string $language
+ * @return string
+ */
+ public function getLanguageFlag(string $language): string
+ {
+ $flag = '';
+ if (Tool::isValidLanguage($language)) {
+ $flag = self::getLanguageFlagFile($language);
+ }
+ $flag = preg_replace('@^' . preg_quote(PIMCORE_WEB_ROOT, '@') . '@', '', $flag);
+
+ return $flag;
+ }
+
+ /**
+ * @param string $language
+ *
+ * @return string
+ */
+ public static function getLanguageFlagFile(string $language): string
+ {
+ $basePath = '/bundles/pimcoreadmin/img/flags';
+ $code = strtolower($language);
+ $iconPath = $basePath . '/countries/_unknown.svg';
+
+ $languageCountryMapping = [
+ 'aa' => 'er', 'af' => 'za', 'am' => 'et', 'as' => 'in', 'ast' => 'es', 'asa' => 'tz',
+ 'az' => 'az', 'bas' => 'cm', 'eu' => 'es', 'be' => 'by', 'bem' => 'zm', 'bez' => 'tz', 'bg' => 'bg',
+ 'bm' => 'ml', 'bn' => 'bd', 'br' => 'fr', 'brx' => 'in', 'bs' => 'ba', 'cs' => 'cz', 'da' => 'dk',
+ 'de' => 'de', 'dz' => 'bt', 'el' => 'gr', 'en' => 'gb', 'es' => 'es', 'et' => 'ee', 'fi' => 'fi',
+ 'fo' => 'fo', 'fr' => 'fr', 'ga' => 'ie', 'gv' => 'im', 'he' => 'il', 'hi' => 'in', 'hr' => 'hr',
+ 'hu' => 'hu', 'hy' => 'am', 'id' => 'id', 'ig' => 'ng', 'is' => 'is', 'it' => 'it', 'ja' => 'jp',
+ 'ka' => 'ge', 'os' => 'ge', 'kea' => 'cv', 'kk' => 'kz', 'kl' => 'gl', 'km' => 'kh', 'ko' => 'kr',
+ 'lg' => 'ug', 'lo' => 'la', 'lt' => 'lt', 'mg' => 'mg', 'mk' => 'mk', 'mn' => 'mn', 'ms' => 'my',
+ 'mt' => 'mt', 'my' => 'mm', 'nb' => 'no', 'ne' => 'np', 'nl' => 'nl', 'nn' => 'no', 'pl' => 'pl',
+ 'pt' => 'pt', 'ro' => 'ro', 'ru' => 'ru', 'sg' => 'cf', 'sk' => 'sk', 'sl' => 'si', 'sq' => 'al',
+ 'sr' => 'rs', 'sv' => 'se', 'swc' => 'cd', 'th' => 'th', 'to' => 'to', 'tr' => 'tr', 'tzm' => 'ma',
+ 'uk' => 'ua', 'uz' => 'uz', 'vi' => 'vn', 'zh' => 'cn', 'gd' => 'gb-sct', 'gd-gb' => 'gb-sct',
+ 'cy' => 'gb-wls', 'cy-gb' => 'gb-wls', 'fy' => 'nl', 'xh' => 'za', 'yo' => 'bj', 'zu' => 'za',
+ 'ta' => 'lk', 'te' => 'in', 'ss' => 'za', 'sw' => 'ke', 'so' => 'so', 'si' => 'lk', 'ii' => 'cn',
+ 'zh-hans' => 'cn', 'sn' => 'zw', 'rm' => 'ch', 'pa' => 'in', 'fa' => 'ir', 'lv' => 'lv', 'gl' => 'es',
+ 'fil' => 'ph',
+ ];
+
+ if (array_key_exists($code, $languageCountryMapping)) {
+ $iconPath = $basePath . '/countries/' . $languageCountryMapping[$code] . '.svg';
+ }
+
+ return $iconPath;
+ }
+}
diff --git a/src/Twig/Extension/TwigQrCode.php b/src/Twig/Extension/TwigQrCode.php
new file mode 100644
index 0000000..5cf8ec2
--- /dev/null
+++ b/src/Twig/Extension/TwigQrCode.php
@@ -0,0 +1,71 @@
+translator = $translator;
+ }
+
+ public function getFunctions(): array
+ {
+ return [
+ new TwigFunction('twigExtensionQrImage',
+ [$this, 'getQrImg'], ['is_safe' => ['html']])
+ ];
+ }
+
+ public function getQrImg(
+ string $qrData,
+ int $size = 150,
+ int $margin = 0,
+ array $qrColor = [0, 0, 0],
+ array $bgColor = [255, 225, 255]
+ ): string
+ {
+
+ $qrImg = [];
+ $qrImg[] .= '
getQrData($qrData, $size, $margin, $qrColor, $bgColor)->getDataUri() . '" ';
+ $qrImg[] .= 'alt="' . $this->translator->trans("scan me") . '"/>';
+
+ return join($qrImg);
+ }
+
+ public function getQrData(
+ string $data,
+ int $size,
+ int $margin,
+ array $qrColor,
+ array $bgColor
+ ): ResultInterface
+ {
+ $writer = new SvgWriter();
+ $qrCode = QrCode::create($data)
+ ->setEncoding(new Encoding('UTF-8'))
+ ->setErrorCorrectionLevel(new ErrorCorrectionLevelQuartile())
+ ->setSize($size)
+ ->setMargin($margin)
+ ->setRoundBlockSizeMode(new RoundBlockSizeModeEnlarge())
+ ->setForegroundColor(new Color($qrColor[0], $qrColor[1], $qrColor[2]))
+ ->setBackgroundColor(new Color($bgColor[0], $bgColor[1], $bgColor[2]));
+
+ return $writer->write($qrCode);
+ }
+}
diff --git a/src/Twig/Extension/TwigSvgFun.php b/src/Twig/Extension/TwigSvgFun.php
new file mode 100644
index 0000000..4e45560
--- /dev/null
+++ b/src/Twig/Extension/TwigSvgFun.php
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+ '.$value.'';
+
+ return $svg;
+ }
+
+}
diff --git a/src/Twig/Filter/TwigArrayFilters.php b/src/Twig/Filter/TwigArrayFilters.php
new file mode 100644
index 0000000..5443da0
--- /dev/null
+++ b/src/Twig/Filter/TwigArrayFilters.php
@@ -0,0 +1,54 @@
+ 'year',
+ 'm' => 'month',
+ 'd' => 'day',
+ 'h' => 'hour',
+ 'i' => 'minute',
+ 's' => 'second',
+ ];
+
+ private $translator;
+
+ public function __construct(TranslatorInterface $translator = null)
+ {
+ // Ignore the IdentityTranslator, otherwise the parameters won't be replaced properly
+ if ($translator instanceof IdentityTranslator) {
+ $translator = null;
+ }
+ $this->translator = $translator;
+ }
+
+ public function getFilters(): array
+ {
+ return [
+ new TwigFilter('twigFilterPassedTimeToNow',
+ [$this, 'passedTimeToNow'], ['needs_environment' => true])
+ ];
+ }
+
+ /**
+ * Filters for converting dates to a time ago string like Facebook and Twitter has.
+ *
+ * @param string|\DateTime $date a string or DateTime object to convert
+ * @param string|\DateTime $now A string or DateTime object to compare with. If none given, the current time will be used.
+ *
+ * @return string the converted time
+ */
+ public function passedTimeToNow(
+ Environment $env,
+ string $date,
+ string $now = null
+ )
+ {
+ if (1 === preg_match('~^[1-9][0-9]*$~', $date)) {
+
+ // Convert both dates to DateTime instances.
+ $date = twig_date_converter($env, $date);
+ $now = twig_date_converter($env, $now);
+
+ // Get the difference between the two DateTime objects.
+ $diff = $date->diff($now);
+
+ // Check for each interval if it appears in the $diff object.
+ foreach (self::$units as $attribute => $unit) {
+ $count = $diff->$attribute;
+
+ if (0 !== $count) {
+ return $this->getPluralizedInterval($count, $diff->invert, $unit);
+ }
+ }
+
+ return '';
+ } else {
+
+ return $date;
+ }
+ }
+
+ private function getPluralizedInterval(
+ $count,
+ $invert,
+ $unit
+ )
+ {
+ if ($this->translator) {
+ $id = sprintf('diff.%s.%s', $invert ? 'in' : 'ago', $unit);
+
+ return $this->translator->trans($id, (array)$count, ['%count%' => $count], 'date');
+ }
+
+ if (1 !== $count) {
+ $unit .= 's';
+ }
+
+ return $invert ? "in $count $unit" : "$count $unit ago";
+ }
+}
diff --git a/src/Twig/Filter/TwigFileGetContents.php b/src/Twig/Filter/TwigFileGetContents.php
new file mode 100644
index 0000000..cd664af
--- /dev/null
+++ b/src/Twig/Filter/TwigFileGetContents.php
@@ -0,0 +1,36 @@
+ ['html']])
+ ];
+ }
+
+ public function getFileGetContents(string $file): string
+ {
+ $relativPath = "/" . trim($file, '/');
+ $rootPath = PIMCORE_WEB_ROOT . $relativPath;
+ $assetPath = PIMCORE_WEB_ROOT . '/var/assets/' . $relativPath;
+
+ if (is_file($rootPath)) {
+ return file_get_contents($rootPath);
+ }
+
+ if (is_file($assetPath)) {
+ return file_get_contents($assetPath);
+ }
+
+ return $file;
+ }
+}
diff --git a/src/Twig/Filter/TwigFormatPrice.php b/src/Twig/Filter/TwigFormatPrice.php
new file mode 100644
index 0000000..23c59b3
--- /dev/null
+++ b/src/Twig/Filter/TwigFormatPrice.php
@@ -0,0 +1,32 @@
+ ['html']]),
+ new TwigFilter('twigFilterHrefEmail',
+ [$this, 'getHrefEmail'], ['is_safe' => ['html']]),
+ new TwigFilter('twigFilterHrefPhone',
+ [$this, 'getHrefPhone'], ['is_safe' => ['html']]),
+ new TwigFilter('twigFilterHrefWhatsApp',
+ [$this, 'getHrefWhatsApp'], ['is_safe' => ['html']]),
+ new TwigFilter('twigFilterHrefSocialMedia',
+ [$this, 'getHrefSocialMedia'], ['is_safe' => ['html']]),
+ ];
+ }
+
+ public function getHrefUrl(
+ string $url,
+ string $class = '',
+ string $target = '_blank'
+ ): string
+ {
+ if (filter_var($url, FILTER_VALIDATE_URL)) {
+ $webLink = [];
+ $webLink[] .= '';
+ $webLink[] .= str_replace(['http://', 'https://'], '', $url);
+ $webLink[] .= '';
+
+ return join($webLink);
+ } else {
+
+ return $url;
+ }
+ }
+
+ public function getHrefEmail(
+ string $email,
+ string $class = '',
+ string $subject = '',
+ string $body = '',
+ string $cc = '',
+ string $bcc = ''
+ ): string
+ {
+ if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
+
+ $emailLink = [];
+ $emailLink[] .= '
strToASCII('mailto:' . $email);
+ $emailLink[] .= $subject != '' ? '?subject=' . $subject : '';
+ $emailLink[] .= $body != '' ? '&body=' . $body : '';
+ $emailLink[] .= $cc != '' && filter_var($cc, FILTER_VALIDATE_EMAIL) ? '&cc=' . $this->strToASCII($cc) : '';
+ $emailLink[] .= $bcc != '' && filter_var($bcc, FILTER_VALIDATE_EMAIL) ? '&bcc=' . $this->strToASCII($bcc) : '';
+ $emailLink[] .= '">';
+ $emailLink[] .= $this->strToASCII($email);
+ $emailLink[] .= '';
+
+ return join($emailLink);
+
+ } else {
+
+ return $email;
+ }
+ }
+
+ public function getHrefPhone(
+ string $phone,
+ string $hrefPrefix = 'tel:',
+ string $countryCode = '+41',
+ ): string
+ {
+ return $this->getPhoneBaseLink($phone, $hrefPrefix, $countryCode);
+ }
+
+ public function getHrefWhatsApp(
+ string $phone,
+ string $hrefPrefix = 'https://wa.me/',
+ string $countryCode = '+41'
+ ): string
+ {
+ return $this->getPhoneBaseLink($phone, $hrefPrefix, $countryCode);
+ }
+
+ public function getPhoneBaseLink(
+ string $phone,
+ string $hrefPrefix,
+ string $countryCode
+ ): string
+ {
+ $nrToSanitize = $phone;
+ $number = filter_var($nrToSanitize, FILTER_SANITIZE_NUMBER_INT);
+
+ if (preg_match('/^[0-9]{10}+$/', $number)) {
+
+ $phoneLink = [];
+ $phoneLink[] .= '
strToASCII($phone);
+ $phoneLink[] .= '';
+
+ return join($phoneLink);
+
+ } else {
+
+ return $phone;
+ }
+ }
+
+ public function getHrefSocialMedia(
+ string $url,
+ string $name = 'bootstrap'
+ ): string
+ {
+ if (filter_var($url, FILTER_VALIDATE_URL)) {
+ $smLink = [];
+ $smLink[] .= '
';
+ $smLink[] .= (new TwigBootstrapSvgIcon)->getBootstrapSvgIcon($name);
+ $smLink[] .= '';
+
+ return join($smLink);
+ } else {
+
+ return $url;
+ }
+ }
+
+ public function strToASCII(string $string): string
+ {
+ $output = '';
+ for ($i = 0; $i < strlen($string); $i++) {
+ $output .= '' . ord($string[$i]) . ';';
+ }
+ return $output;
+ }
+
+}
diff --git a/src/Twig/Filter/TwigImages.php b/src/Twig/Filter/TwigImages.php
new file mode 100644
index 0000000..22e5d8c
--- /dev/null
+++ b/src/Twig/Filter/TwigImages.php
@@ -0,0 +1,90 @@
+ ['html']]),
+ new TwigFilter('twigFilterImgThumbConfig', [$this, 'getImgThumbConfig'], ['is_safe' => ['html']]),
+ new TwigFilter('twigFilterCssBgImg', [$this, 'getCssBgImg'], ['is_safe' => ['html']]),
+ ];
+ }
+
+ public function getImgThumbnail(
+ object $image,
+ string $thumbnailName = null,
+ string $cssClass = 'img-fluid',
+ string $alt = '',
+ array $attrData = [],
+ ): string|object
+ {
+ if ($image->getImage() instanceof Asset\Image) {
+ $attributes = ["class" => $cssClass, "alt" => $alt];
+ $array = array_merge($attributes, $attrData);
+
+ $img = $image->getThumbnail($thumbnailName)->getHtml(['imgAttributes' => $array]);
+ return $img;
+
+ } else {
+
+ return $image;
+ }
+ }
+
+ public function getImgThumbConfig(
+ object $image,
+ string $cssClass = 'img-fluid',
+ string $alt = '',
+ int $width = 250,
+ int $height = null,
+ int $quality = 90,
+ string $format = 'webp',
+ array $attrData = [],
+ bool $aspectratio = true,
+ ): string|object
+ {
+ if ($image->getImage() instanceof Asset\Image) {
+ $attributes = ["class" => $cssClass, "alt" => $alt];
+ $array = array_merge($attributes, $attrData);
+
+ $img = $image->getThumbnail([
+ "width" => $width,
+ "height" => $height,
+ "aspectratio" => $aspectratio,
+ "quality" => $quality,
+ "format" => $format
+ ])->getHtml(['imgAttributes' => $array]);
+
+ return $img;
+ } else {
+ return $image;
+ }
+ }
+
+ public function getCssBgImg(
+ object $image,
+ string $thumbnailName = null,
+ ): string
+ {
+ if ($image->getImage() instanceof Asset\Image) {
+ $thumb = $image->getThumbnail($thumbnailName);
+
+ return ' style="background-image: url(' . $thumb . ');" ';
+ }
+
+ return '';
+ }
+
+}
diff --git a/src/Twig/Filter/TwigStringFilters.php b/src/Twig/Filter/TwigStringFilters.php
new file mode 100644
index 0000000..39b18c7
--- /dev/null
+++ b/src/Twig/Filter/TwigStringFilters.php
@@ -0,0 +1,53 @@
+getStringNormalizer($string) );
+ }
+
+ public static function getStringNormalizer(string $string): string
+ {
+
+ $search = ['~','¨','^','?', '\'', '"', '/', '-', '+', '.', ',', ';', '(', ')', ' ', '&', 'ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß', 'É', 'é', 'È', 'è', 'Ê', 'ê', 'E', 'e', 'Ë', 'ë',
+ 'À', 'à', 'Á', 'á', 'Å', 'å', 'a', 'Â', 'â', 'Ã', 'ã', 'ª', 'Æ', 'æ', 'C', 'c', 'Ç', 'ç', 'C', 'c', 'Í', 'í', 'Ì', 'ì', 'Î', 'î', 'Ï', 'ï',
+ 'Ó', 'ó', 'Ò', 'ò', 'Ô', 'ô', 'º', 'Õ', 'õ', 'Œ', 'O', 'o', 'Ø', 'ø', 'Ú', 'ú', 'Ù', 'ù', 'Û', 'û', 'U', 'u', 'U', 'u', 'Š', 'š', 'S', 's',
+ 'Ž', 'ž', 'Z', 'z', 'Z', 'z', 'L', 'l', 'N', 'n', 'Ñ', 'ñ', '¡', '¿', 'Ÿ', 'ÿ', '_', ':' ];
+ $replace = ['','','', '', '', '', '', '-', '', '', '-', '-', '', '', '-', '', 'ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e',
+ 'A', 'a', 'A', 'a', 'A', 'a', 'a', 'A', 'a', 'A', 'a', 'a', 'AE', 'ae', 'C', 'c', 'C', 'c', 'C', 'c', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i',
+ 'O', 'o', 'O', 'o', 'O', 'o', 'o', 'O', 'o', 'OE', 'O', 'o', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'S', 's', 'S', 's',
+ 'Z', 'z', 'Z', 'z', 'Z', 'z', 'L', 'l', 'N', 'n', 'N', 'n', '', '', 'Y', 'y', '-', '-' ];
+
+ $value = str_replace($search, $replace, $string);
+
+ return $value;
+ }
+}
diff --git a/src/Twig/Filter/TwigTextFilters.php b/src/Twig/Filter/TwigTextFilters.php
new file mode 100644
index 0000000..b56f86f
--- /dev/null
+++ b/src/Twig/Filter/TwigTextFilters.php
@@ -0,0 +1,78 @@
+
+ * https://github.com/twigphp/Twig-extensions/blob/master/src/TextExtension.php
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ * https://github.com/twigphp/Twig-extensions/blob/master/LICENSE
+ */
+
+namespace SergeDesign\PimcoreCustomTwigBundle\Twig\Filter;
+
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFilter;
+use Twig\Environment;
+
+class TwigTextFilters extends AbstractExtension
+{
+ public function getFilters(): array
+ {
+ return [
+ new TwigFilter('twigFilterTruncate',
+ [$this, 'getTruncateFilter'], ['needs_environment' => true, 'is_safe' => ['html']]),
+ new TwigFilter('twigFilterWordwrap',
+ [$this, 'getWordwrapFilter'], ['needs_environment' => true, 'is_safe' => ['html']]),
+ ];
+ }
+
+ public function getTruncateFilter(
+ Environment $env,
+ string $value,
+ int $length = 30,
+ bool $preserve = false,
+ string $separator = '...'
+ ): string
+ {
+ if (mb_strlen($value, $env->getCharset()) > $length) {
+ if ($preserve) {
+ // If breakpoint is on the last word, return the value without separator.
+ if (false === ($breakpoint = mb_strpos($value, ' ', $length, $env->getCharset()))) {
+ return $value;
+ }
+ $length = $breakpoint;
+ }
+ return rtrim(mb_substr($value, 0, $length, $env->getCharset())) . $separator;
+ }
+ return $value;
+ }
+
+ public function getWordwrapFilter(
+ Environment $env,
+ string $value,
+ int $length = 50,
+ string $separator = "\r\n",
+ bool $preserve = false
+ ): string
+ {
+ $sentences = [];
+ $previous = mb_regex_encoding();
+ mb_regex_encoding($env->getCharset());
+
+ $pieces = mb_split($separator, $value);
+ mb_regex_encoding($previous);
+
+ foreach ($pieces as $piece) {
+ while (!$preserve && mb_strlen($piece, $env->getCharset()) > $length) {
+ $sentences[] = mb_substr($piece, 0, $length, $env->getCharset());
+ $piece = mb_substr($piece, $length, 2048, $env->getCharset());
+ }
+ $sentences[] = $piece;
+ }
+ return nl2br(implode($separator, $sentences));
+ }
+}
diff --git a/src/Twig/Filter/TwigUnixToTime.php b/src/Twig/Filter/TwigUnixToTime.php
new file mode 100644
index 0000000..5f03294
--- /dev/null
+++ b/src/Twig/Filter/TwigUnixToTime.php
@@ -0,0 +1,69 @@
+translator = $translator;
+ }
+
+ public function getFilters(): array
+ {
+ return [
+ new TwigFilter('twigFilterUnixTimestampToTime',
+ [$this, 'getUnixTimestampToTime'], ['is_safe' => ['html']]),
+ ];
+ }
+
+ public function getUnixTimestampToTime(int $unixTimeStamp): string
+ {
+
+ if (is_numeric($unixTimeStamp)) {
+
+ $days = floor($unixTimeStamp / 86400);
+ $hrs = floor($unixTimeStamp / 3600);
+ $mins = intval(($unixTimeStamp / 60) % 60);
+ $sec = intval($unixTimeStamp % 60);
+
+ if ($days > 1) {
+ $stringDays = 'Days';
+ } else {
+ $stringDays = 'Day';
+ }
+
+ if ($days > 0) {
+ //echo $days;exit;
+ $hrs = str_pad($hrs, 2, '0', STR_PAD_LEFT);
+ $hours = $hrs - ($days * 24);
+ $return_days = $days . ' ' . $this->translator->trans($stringDays) . ' ';
+
+ $hrs = str_pad($hours, 2, '0', STR_PAD_LEFT);
+ } else {
+ $return_days = "";
+ $hrs = str_pad($hrs, 2, '0', STR_PAD_LEFT);
+ }
+
+ $mins = str_pad($mins, 2, '0', STR_PAD_LEFT);
+
+ if ($sec > 0) {
+ $sec = ':' . str_pad($sec, 2, '0', STR_PAD_LEFT);
+ } else {
+ $sec = '';
+ }
+ return $return_days . $hrs . ":" . $mins . $sec;
+
+ } else {
+ return $unixTimeStamp;
+ }
+ }
+
+}
diff --git a/src/Twig/Statements/TwigSwitch.php b/src/Twig/Statements/TwigSwitch.php
new file mode 100644
index 0000000..df2077f
--- /dev/null
+++ b/src/Twig/Statements/TwigSwitch.php
@@ -0,0 +1,18 @@
+container = $container;
+ }
+
+ public function getFunctions(): array
+ {
+ return [
+ new TwigFunction('twigTestBundleChecker', [$this, 'getBundleChecker']),
+ ];
+ }
+
+ public function getBundleChecker(string $bundle): bool
+ {
+ return array_key_exists(
+ $bundle,
+ $this->container->getParameter('kernel.bundles')
+ );
+ }
+
+}
diff --git a/src/Twig/Test/TwigTests.php b/src/Twig/Test/TwigTests.php
new file mode 100644
index 0000000..e808bd6
--- /dev/null
+++ b/src/Twig/Test/TwigTests.php
@@ -0,0 +1,66 @@
+getMimeType() === "image/svg+xml";
+ }),
+ new TwigTest('twigTestIsArray', function (mixed $value): bool {
+ return is_array($value);
+ }),
+ new TwigTest('twigTestIsBoolean', function (mixed $value): bool {
+ return is_bool($value);
+ }),
+ new TwigTest('twigTestIsCallable', function (mixed $value): bool {
+ return is_callable($value);
+ }),
+ new TwigTest('twigTestIsCountable', function (mixed $value): bool {
+ return is_countable($value);
+ }),
+ new TwigTest('twigTestIsDir', function (string $value): bool {
+ return is_dir($value);
+ }),
+ new TwigTest('twigTestIsFloat', function (mixed $value): bool {
+ return is_float($value);
+ }),
+ new TwigTest('twigTestIsInt', function (mixed $value): bool {
+ return is_int($value);
+ }),
+ new TwigTest('twigTestIsNumeric', function (mixed $value): bool {
+ return is_numeric($value);
+ }),
+ new TwigTest('twigTestIsNull', function (mixed $value): bool {
+ return is_null($value);
+ }),
+ new TwigTest('twigTestIsObject', function (mixed $value): bool {
+ return is_object($value);
+ }),
+ new TwigTest('twigTestIsResource', function (mixed $value): bool {
+ return is_resource($value);
+ }),
+ new TwigTest('twigTestIsScalar', function (mixed $value): bool {
+ return is_scalar($value);
+ }),
+ new TwigTest('twigTestIsString', function (mixed $value): bool {
+ return is_string($value);
+ }),
+ new TwigTest('twigTestIsset', function (mixed $var): bool {
+ return isset($var);
+ })
+ ];
+ }
+
+}
+