Translated using Weblate (Portuguese)
[phpmyadmin.git] / src / Twig / AssetExtension.php
blob132a5ac61095c27e8d0f2c632b31ac3e822c1378
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Twig;
7 use PhpMyAdmin\Container\ContainerBuilder;
8 use PhpMyAdmin\Theme\ThemeManager;
9 use Twig\Extension\AbstractExtension;
10 use Twig\TwigFunction;
12 final class AssetExtension extends AbstractExtension
14 private ThemeManager|null $themeManager = null;
16 /** @return TwigFunction[] */
17 public function getFunctions(): array
19 return [new TwigFunction('image', $this->getImagePath(...))];
22 public function getImagePath(string|null $filename = null, string|null $fallback = null): string
24 if ($this->themeManager === null) {
25 $themeManager = ContainerBuilder::getContainer()->get(ThemeManager::class);
26 if (! $themeManager instanceof ThemeManager) {
27 return '';
30 $this->themeManager = $themeManager;
33 return $this->themeManager->theme->getImgPath($filename, $fallback);