vendor/sylius/theme-bundle/src/Twig/Locator/CompositeTemplateLocator.php line 37

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\Model\ThemeInterface;
  13. final class CompositeTemplateLocator implements TemplateLocatorInterface
  14. {
  15.     /**
  16.      * @psalm-var iterable<TemplateLocatorInterface>
  17.      *
  18.      * @var iterable|TemplateLocatorInterface[]
  19.      */
  20.     private iterable $themedTemplateLocators;
  21.     /**
  22.      * @psalm-param iterable<TemplateLocatorInterface> $themedTemplateLocators
  23.      *
  24.      * @param iterable|TemplateLocatorInterface[] $themedTemplateLocators
  25.      */
  26.     public function __construct(iterable $themedTemplateLocators)
  27.     {
  28.         $this->themedTemplateLocators $themedTemplateLocators;
  29.     }
  30.     public function locate(string $templateThemeInterface $theme): string
  31.     {
  32.         foreach ($this->themedTemplateLocators as $themedTemplateLocator) {
  33.             if (!$themedTemplateLocator->supports($template)) {
  34.                 continue;
  35.             }
  36.             try {
  37.                 return $themedTemplateLocator->locate($template$theme);
  38.             } catch (TemplateNotFoundException $exception) {
  39.                 // Do nothing.
  40.             }
  41.         }
  42.         throw new TemplateNotFoundException($template, [$theme]);
  43.     }
  44.     public function supports(string $template): bool
  45.     {
  46.         foreach ($this->themedTemplateLocators as $themedTemplateLocator) {
  47.             if ($themedTemplateLocator->supports($template)) {
  48.                 return true;
  49.             }
  50.         }
  51.         return false;
  52.     }
  53. }