vendor/shopware/core/Content/Product/Aggregate/ProductMedia/ProductMediaCollection.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Product\Aggregate\ProductMedia;
  3. use Shopware\Core\Content\Media\MediaCollection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  5. /**
  6.  * @extends EntityCollection<ProductMediaEntity>
  7.  */
  8. class ProductMediaCollection extends EntityCollection
  9. {
  10.     /**
  11.      * @return list<string>
  12.      */
  13.     public function getProductIds(): array
  14.     {
  15.         return $this->fmap(function (ProductMediaEntity $productMedia) {
  16.             return $productMedia->getProductId();
  17.         });
  18.     }
  19.     public function filterByProductId(string $id): self
  20.     {
  21.         return $this->filter(function (ProductMediaEntity $productMedia) use ($id) {
  22.             return $productMedia->getProductId() === $id;
  23.         });
  24.     }
  25.     /**
  26.      * @return list<string>
  27.      */
  28.     public function getMediaIds(): array
  29.     {
  30.         return $this->fmap(function (ProductMediaEntity $productMedia) {
  31.             return $productMedia->getMediaId();
  32.         });
  33.     }
  34.     public function filterByMediaId(string $id): self
  35.     {
  36.         return $this->filter(function (ProductMediaEntity $productMedia) use ($id) {
  37.             return $productMedia->getMediaId() === $id;
  38.         });
  39.     }
  40.     public function getMedia(): MediaCollection
  41.     {
  42.         return new MediaCollection(
  43.             $this->fmap(function (ProductMediaEntity $productMedia) {
  44.                 return $productMedia->getMedia();
  45.             })
  46.         );
  47.     }
  48.     public function getApiAlias(): string
  49.     {
  50.         return 'product_media_collection';
  51.     }
  52.     protected function getExpectedClass(): string
  53.     {
  54.         return ProductMediaEntity::class;
  55.     }
  56. }