vendor/sylius/theme-bundle/src/Twig/Locator/HierarchicalTemplateLocator.php line 33

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ThemeBundle\Twig\Locator;
  12. use Sylius\Bundle\ThemeBundle\HierarchyProvider\ThemeHierarchyProviderInterface;
  13. use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
  14. final class HierarchicalTemplateLocator implements TemplateLocatorInterface
  15. {
  16.     private TemplateLocatorInterface $templateLocator;
  17.     private ThemeHierarchyProviderInterface $themeHierarchyProvider;
  18.     public function __construct(
  19.         TemplateLocatorInterface $templateLocator,
  20.         ThemeHierarchyProviderInterface $themeHierarchyProvider,
  21.     ) {
  22.         $this->templateLocator $templateLocator;
  23.         $this->themeHierarchyProvider $themeHierarchyProvider;
  24.     }
  25.     public function locate(string $templateThemeInterface $theme): string
  26.     {
  27.         $providedThemes $this->themeHierarchyProvider->getThemeHierarchy($theme);
  28.         foreach ($providedThemes as $providedTheme) {
  29.             try {
  30.                 return $this->templateLocator->locate($template$providedTheme);
  31.             } catch (TemplateNotFoundException $exception) {
  32.                 // Ignore if resource cannot be found in given theme.
  33.             }
  34.         }
  35.         throw new TemplateNotFoundException($template$providedThemes);
  36.     }
  37.     public function supports(string $template): bool
  38.     {
  39.         return $this->templateLocator->supports($template);
  40.     }
  41. }