mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-05 20:44:19 +01:00
WIP 3-3
This commit is contained in:
34
src/Repository/CandidateRepository.php
Normal file
34
src/Repository/CandidateRepository.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Candidate;
|
||||
use App\Entity\Season;
|
||||
use App\Helpers\Base64;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Safe\Exceptions\UrlException;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Candidate>
|
||||
*/
|
||||
class CandidateRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Candidate::class);
|
||||
}
|
||||
|
||||
public function getCandidateByHash(Season $season, string $hash): ?Candidate
|
||||
{
|
||||
try {
|
||||
$name = Base64::base64_url_decode($hash);
|
||||
} catch (UrlException) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->findOneBy(['season' => $season, 'name' => $name]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user