vendor/shopware/core/Content/Cms/Aggregate/CmsSlot/CmsSlotCollection.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Cms\Aggregate\CmsSlot;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  4. /**
  5.  * @extends EntityCollection<CmsSlotEntity>
  6.  */
  7. class CmsSlotCollection extends EntityCollection
  8. {
  9.     /**
  10.      * @var CmsSlotEntity[]|null indexed by slot name
  11.      */
  12.     private $slotCache;
  13.     /**
  14.      * @param string        $key
  15.      * @param CmsSlotEntity $entity
  16.      */
  17.     public function set($key$entity): void
  18.     {
  19.         parent::set($key$entity);
  20.         $this->slotCache[$entity->getSlot()] = $entity;
  21.     }
  22.     /**
  23.      * @param CmsSlotEntity $entity
  24.      */
  25.     public function add($entity): void
  26.     {
  27.         parent::add($entity);
  28.         $this->slotCache[$entity->getSlot()] = $entity;
  29.     }
  30.     public function getSlot(string $slot): ?CmsSlotEntity
  31.     {
  32.         $this->createSlotHashMap();
  33.         return $this->slotCache[$slot] ?? null;
  34.     }
  35.     public function getApiAlias(): string
  36.     {
  37.         return 'cms_page_slot_collection';
  38.     }
  39.     protected function getExpectedClass(): string
  40.     {
  41.         return CmsSlotEntity::class;
  42.     }
  43.     private function createSlotHashMap(): void
  44.     {
  45.         if ($this->slotCache !== null) {
  46.             return;
  47.         }
  48.         foreach ($this->getIterator() as $element) {
  49.             $this->slotCache[$element->getSlot()] = $element;
  50.         }
  51.     }
  52. }