/
AleksWork
/
diary_plants
Обзор
Документация
Войти
/
AleksWork
/
diary_plants
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/Domain/Service/AttachableResolver.php
30 строк
974 B
AlexeySerov
Make change attachableType for attachment entity
18 мар 2026, 09:57
18 мар 2026, 09:57
b5caa47
Код
Авторство
О чём код?
<?php namespace App\Domain\Service; use Doctrine\ORM\EntityManagerInterface; use App\Domain\Entity\Interfaces\AttachableInterface; use App\Domain\Repository\AttachableResolverInterface; use App\Domain\ValueObject\Enum\Usage\AttachableType as AttachableTypeUsage; use App\Domain\ValueObject\Enum\Attachment\AttachableType as AttachableTypeAttachment; class AttachableResolver implements AttachableResolverInterface { public function __construct( private readonly EntityManagerInterface $entityManager ) { } public function resolve(AttachableTypeAttachment|AttachableTypeUsage $type, int $id): ?AttachableInterface { $class = $type->getClass($type->value); if ($class === null) { throw new \InvalidArgumentException("Unsupported attachable type: {$type->value}"); } $entity = $this->entityManager->find($class, $id); return $entity instanceof AttachableInterface ? $entity : null; } }