vendor/boldr/shop-bundle/src/Presenter/Category/CategoryPresenter.php line 34

Open in your IDE?
  1. <?php
  2. namespace Boldr\Shop\ShopBundle\Presenter\Category;
  3. use Boldr\Shop\ShopBundle\Entity\Category;
  4. class CategoryPresenter
  5. {
  6.     private iterable $categoryViewProcessors;
  7.     private array $categoryViews = [];
  8.     public function __construct(iterable $categoryViewProcessors)
  9.     {
  10.         $this->categoryViewProcessors $categoryViewProcessors;
  11.     }
  12.     public function createCategoryView(Category $categorystring $locale): CategoryView
  13.     {
  14.         $cacheKey $category->getId().'_'.$locale;
  15.         if (isset($this->categoryViews[$cacheKey]))
  16.             return $this->categoryViews[$cacheKey];
  17.         $categoryTranslation $category->getTranslations()->get($locale);
  18.         $categoryView = new CategoryView(
  19.             $category->getId(),
  20.             $categoryTranslation->getName()
  21.         );
  22.         $view array_reduce(
  23.             iterator_to_array($this->categoryViewProcessors),
  24.             static fn($categoryView$categoryViewProcessor) => $categoryViewProcessor->processCategoryView($categoryView$category$locale),
  25.             $categoryView
  26.         );
  27.         $this->categoryViews[$cacheKey] = $view;
  28.         return $view;
  29.     }
  30. }