Files
michaelschiemer/src/Domain/Media/ImageSlotRepository.php
Michael Schiemer e30753ba0e fix: resolve RedisCache array offset error and improve discovery diagnostics
- Fix RedisCache driver to handle MGET failures gracefully with fallback
- Add comprehensive discovery context comparison debug tools
- Identify root cause: WEB context discovery missing 166 items vs CLI
- WEB context missing RequestFactory class entirely (52 vs 69 commands)
- Improved exception handling with detailed binding diagnostics
2025-09-12 20:05:18 +02:00

83 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Domain\Media;
use App\Framework\Database\EntityManager;
final readonly class ImageSlotRepository
{
public function __construct(
private EntityManager $entityManager
) {
}
public function getSlots(): array
{
return $this->entityManager->findAll(ImageSlot::class);
}
public function findBySlotName(string $slotName): ImageSlot
{
return $this->entityManager->findOneBy(ImageSlot::class, ['slot_name' => $slotName]);
}
public function findById(string $id): ImageSlot
{
return $this->entityManager->find(ImageSlot::class, $id);
}
public function save(ImageSlot $imageSlot): object
{
return $this->entityManager->save($imageSlot);
}
/**
* @return array<int, ImageSlotView>
*/
public function findAllWithImages(): array
{
$slots = $this->entityManager->findAll(ImageSlot::class);
return array_map(function (ImageSlot $slot) {
$image = null;
if ($slot->imageId) {
$image = $this->entityManager->find(Image::class, $slot->imageId);
}
return ImageSlotView::fromSlot($slot, $image);
}, $slots);
}
public function findByIdWithImage(string $id): ImageSlotView
{
$slot = $this->entityManager->find(ImageSlot::class, $id);
if (! $slot) {
throw new \RuntimeException("ImageSlot with ID {$id} not found");
}
$image = null;
if ($slot->imageId) {
$image = $this->entityManager->find(Image::class, $slot->imageId);
}
return ImageSlotView::fromSlot($slot, $image);
}
public function updateImageId(string $slotId, string $imageId): void
{
$slot = $this->findById($slotId);
#$slot->imageId = $imageId;
$slot = new ImageSlot(
$slot->id,
$slot->slotName,
$imageId
);
$this->entityManager->save($slot);
}
}