Make Repository EntityManagerAware.
This commit is contained in:
parent
d81d068027
commit
c8305d5bc9
|
@ -4,8 +4,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Doctrine;
|
||||
|
||||
use App\Container\EntityManagerAwareTrait;
|
||||
use App\Exception\NotFoundException;
|
||||
use Closure;
|
||||
use DI\Attribute\Inject;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
/**
|
||||
|
@ -13,24 +15,19 @@ use Doctrine\Persistence\ObjectRepository;
|
|||
*/
|
||||
class Repository
|
||||
{
|
||||
use EntityManagerAwareTrait;
|
||||
|
||||
/** @var class-string<TEntity> */
|
||||
protected string $entityClass;
|
||||
|
||||
/** @var ObjectRepository<TEntity> */
|
||||
protected ObjectRepository $repository;
|
||||
|
||||
public function __construct(
|
||||
protected ReloadableEntityManagerInterface $em
|
||||
) {
|
||||
if (!isset($this->entityClass)) {
|
||||
/** @var class-string<TEntity> $defaultClass */
|
||||
$defaultClass = str_replace(['Repository', '\\\\'], ['', '\\'], static::class);
|
||||
$this->entityClass = $defaultClass;
|
||||
}
|
||||
|
||||
if (!isset($this->repository)) {
|
||||
$this->repository = $em->getRepository($this->entityClass);
|
||||
}
|
||||
#[Inject]
|
||||
public function setEntityManager(ReloadableEntityManagerInterface $em): void
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->repository = $em->getRepository($this->entityClass);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,8 @@ use Carbon\CarbonInterface;
|
|||
*/
|
||||
final class AnalyticsRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = Analytics::class;
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
|
|
|
@ -11,4 +11,5 @@ use App\Entity\ApiKey;
|
|||
*/
|
||||
final class ApiKeyRepository extends AbstractSplitTokenRepository
|
||||
{
|
||||
protected string $entityClass = ApiKey::class;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ use App\Entity\StationMediaCustomField;
|
|||
*/
|
||||
final class CustomFieldRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = CustomField::class;
|
||||
|
||||
/**
|
||||
* @return CustomField[]
|
||||
*/
|
||||
|
|
|
@ -15,6 +15,7 @@ use App\Service\IpGeolocation;
|
|||
use App\Utilities\File;
|
||||
use Carbon\CarbonImmutable;
|
||||
use DateTimeInterface;
|
||||
use DI\Attribute\Inject;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use League\Csv\Writer;
|
||||
use NowPlaying\Result\Client;
|
||||
|
@ -29,16 +30,22 @@ final class ListenerRepository extends Repository
|
|||
use LoggerAwareTrait;
|
||||
use TruncateStrings;
|
||||
|
||||
protected string $entityClass = Listener::class;
|
||||
|
||||
private string $tableName;
|
||||
|
||||
private Connection $conn;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
private readonly DeviceDetector $deviceDetector,
|
||||
private readonly IpGeolocation $ipGeolocation
|
||||
) {
|
||||
parent::__construct($em);
|
||||
}
|
||||
|
||||
#[Inject]
|
||||
public function setEntityManager(ReloadableEntityManagerInterface $em): void
|
||||
{
|
||||
parent::setEntityManager($em);
|
||||
|
||||
$this->tableName = $this->em->getClassMetadata(Listener::class)->getTableName();
|
||||
$this->conn = $this->em->getConnection();
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity\Podcast;
|
||||
use App\Entity\PodcastEpisode;
|
||||
|
@ -24,12 +23,12 @@ use League\Flysystem\UnableToRetrieveMetadata;
|
|||
*/
|
||||
final class PodcastEpisodeRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = PodcastEpisode::class;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $entityManager,
|
||||
private readonly MetadataManager $metadataManager,
|
||||
private readonly StorageLocationRepository $storageLocationRepo,
|
||||
) {
|
||||
parent::__construct($entityManager);
|
||||
}
|
||||
|
||||
public function fetchEpisodeForStation(Station $station, string $episodeId): ?PodcastEpisode
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity\Podcast;
|
||||
use App\Entity\Station;
|
||||
|
@ -20,12 +19,12 @@ use League\Flysystem\UnableToRetrieveMetadata;
|
|||
*/
|
||||
final class PodcastRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = Podcast::class;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $entityManager,
|
||||
private readonly PodcastEpisodeRepository $podcastEpisodeRepo,
|
||||
private readonly StorageLocationRepository $storageLocationRepo
|
||||
) {
|
||||
parent::__construct($entityManager);
|
||||
}
|
||||
|
||||
public function fetchPodcastForStation(Station $station, string $podcastId): ?Podcast
|
||||
|
|
|
@ -14,6 +14,8 @@ use App\Enums\GlobalPermissions;
|
|||
*/
|
||||
final class RolePermissionRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = RolePermission::class;
|
||||
|
||||
/**
|
||||
* @param Role $role
|
||||
*
|
||||
|
|
|
@ -12,4 +12,5 @@ use App\Entity\Role;
|
|||
*/
|
||||
final class RoleRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = Role::class;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity\Settings;
|
||||
use App\Exception\ValidationException;
|
||||
|
@ -20,11 +19,9 @@ final class SettingsRepository extends Repository
|
|||
protected string $entityClass = Settings::class;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
private readonly Serializer $serializer,
|
||||
private readonly ValidatorInterface $validator
|
||||
) {
|
||||
parent::__construct($em);
|
||||
}
|
||||
|
||||
public function readSettings(): Settings
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Entity\Interfaces\SongInterface;
|
||||
use App\Entity\SongHistory;
|
||||
use App\Entity\Station;
|
||||
|
@ -16,12 +15,12 @@ use RuntimeException;
|
|||
*/
|
||||
final class SongHistoryRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = SongHistory::class;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
private readonly ListenerRepository $listenerRepository,
|
||||
private readonly StationQueueRepository $stationQueueRepository
|
||||
) {
|
||||
parent::__construct($em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,6 +12,8 @@ use App\Entity\StationHlsStream;
|
|||
*/
|
||||
final class StationHlsStreamRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = StationHlsStream::class;
|
||||
|
||||
/**
|
||||
* @param Station $station
|
||||
*
|
||||
|
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Container\LoggerAwareTrait;
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity\Song;
|
||||
use App\Entity\Station;
|
||||
|
@ -34,15 +33,15 @@ final class StationMediaRepository extends Repository
|
|||
{
|
||||
use LoggerAwareTrait;
|
||||
|
||||
protected string $entityClass = StationMedia::class;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
private readonly MetadataManager $metadataManager,
|
||||
private readonly RemoteAlbumArt $remoteAlbumArt,
|
||||
private readonly CustomFieldRepository $customFieldRepo,
|
||||
private readonly StationPlaylistMediaRepository $spmRepo,
|
||||
private readonly StorageLocationRepository $storageLocationRepo,
|
||||
) {
|
||||
parent::__construct($em);
|
||||
}
|
||||
|
||||
public function findForStation(int|string $id, Station $station): ?StationMedia
|
||||
|
|
|
@ -15,6 +15,8 @@ use App\Service\Flow\UploadedFile;
|
|||
*/
|
||||
final class StationMountRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = StationMount::class;
|
||||
|
||||
public function setIntro(
|
||||
StationMount $mount,
|
||||
UploadedFile $file,
|
||||
|
|
|
@ -14,6 +14,8 @@ use App\Entity\StationPlaylistFolder;
|
|||
*/
|
||||
final class StationPlaylistFolderRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = StationPlaylistFolder::class;
|
||||
|
||||
/**
|
||||
* @param Station $station
|
||||
* @param StationPlaylist[] $playlists
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity\Api\StationPlaylistQueue;
|
||||
use App\Entity\Enums\PlaylistOrders;
|
||||
|
@ -25,11 +24,11 @@ use RuntimeException;
|
|||
*/
|
||||
final class StationPlaylistMediaRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = StationPlaylistMedia::class;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
private readonly StationQueueRepository $queueRepo
|
||||
) {
|
||||
parent::__construct($em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,6 +13,8 @@ use App\Entity\StationPlaylist;
|
|||
*/
|
||||
final class StationPlaylistRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = StationPlaylist::class;
|
||||
|
||||
/**
|
||||
* @return StationPlaylist[]
|
||||
*/
|
||||
|
|
|
@ -19,6 +19,8 @@ use Doctrine\ORM\QueryBuilder;
|
|||
*/
|
||||
final class StationQueueRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = StationQueue::class;
|
||||
|
||||
public function clearForMediaAndPlaylist(
|
||||
StationMedia $media,
|
||||
StationPlaylist $playlist
|
||||
|
|
|
@ -12,6 +12,8 @@ use App\Entity\StationRemote;
|
|||
*/
|
||||
final class StationRemoteRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = StationRemote::class;
|
||||
|
||||
/**
|
||||
* @param Station $station
|
||||
*
|
||||
|
|
|
@ -26,6 +26,8 @@ final class StationRepository extends Repository
|
|||
use EnvironmentAwareTrait;
|
||||
use SettingsAwareTrait;
|
||||
|
||||
protected string $entityClass = Station::class;
|
||||
|
||||
/**
|
||||
* @param string $identifier A numeric or string identifier for a station.
|
||||
*/
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Entity\Api\StationPlaylistQueue;
|
||||
use App\Entity\Station;
|
||||
use App\Entity\StationMedia;
|
||||
|
@ -22,14 +21,14 @@ use Exception as PhpException;
|
|||
*/
|
||||
final class StationRequestRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = StationRequest::class;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
private readonly StationMediaRepository $mediaRepo,
|
||||
private readonly DeviceDetector $deviceDetector,
|
||||
private readonly BlocklistParser $blocklistParser,
|
||||
private readonly AutoDJ\DuplicatePrevention $duplicatePrevention,
|
||||
) {
|
||||
parent::__construct($em);
|
||||
}
|
||||
|
||||
public function getPendingRequest(int|string $id, Station $station): ?StationRequest
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity\ApiGenerator\ScheduleApiGenerator;
|
||||
use App\Entity\Station;
|
||||
|
@ -20,12 +19,12 @@ use Carbon\CarbonInterface;
|
|||
*/
|
||||
final class StationScheduleRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = StationSchedule::class;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
private readonly Scheduler $scheduler,
|
||||
private readonly ScheduleApiGenerator $scheduleApiGenerator
|
||||
) {
|
||||
parent::__construct($em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,6 +15,8 @@ use Carbon\CarbonImmutable;
|
|||
*/
|
||||
final class StationStreamerBroadcastRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = StationStreamerBroadcast::class;
|
||||
|
||||
public function getLatestBroadcast(Station $station): ?StationStreamerBroadcast
|
||||
{
|
||||
$currentStreamer = $station->getCurrentStreamer();
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Entity\Station;
|
||||
use App\Entity\StationStreamer;
|
||||
use App\Entity\StationStreamerBroadcast;
|
||||
|
@ -17,12 +16,12 @@ use App\Radio\AutoDJ\Scheduler;
|
|||
*/
|
||||
final class StationStreamerRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = StationStreamer::class;
|
||||
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
private readonly Scheduler $scheduler,
|
||||
private readonly StationStreamerBroadcastRepository $broadcastRepo
|
||||
) {
|
||||
parent::__construct($em);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,4 +11,5 @@ use App\Entity\StationWebhook;
|
|||
*/
|
||||
final class StationWebhookRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
protected string $entityClass = StationWebhook::class;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ final class StorageLocationRepository extends Repository
|
|||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
protected string $entityClass = StorageLocation::class;
|
||||
|
||||
public function findByType(
|
||||
string|StorageLocationTypes $type,
|
||||
int $id
|
||||
|
|
|
@ -14,6 +14,8 @@ use Generator;
|
|||
*/
|
||||
final class UnprocessableMediaRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = UnprocessableMedia::class;
|
||||
|
||||
public function findByPath(
|
||||
string $path,
|
||||
StorageLocation $storageLocation
|
||||
|
|
|
@ -13,6 +13,8 @@ use App\Security\SplitToken;
|
|||
*/
|
||||
final class UserLoginTokenRepository extends AbstractSplitTokenRepository
|
||||
{
|
||||
protected string $entityClass = UserLoginToken::class;
|
||||
|
||||
public function createToken(User $user): SplitToken
|
||||
{
|
||||
$token = SplitToken::generate();
|
||||
|
|
|
@ -12,6 +12,8 @@ use App\Entity\User;
|
|||
*/
|
||||
final class UserRepository extends Repository
|
||||
{
|
||||
protected string $entityClass = User::class;
|
||||
|
||||
public function findByEmail(string $email): ?User
|
||||
{
|
||||
return $this->repository->findOneby(['email' => $email]);
|
||||
|
|
Loading…
Reference in New Issue