mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-10 06:27:24 +01:00
Added findOneByIdOrSlug method
This commit is contained in:
parent
73d2583846
commit
054a136f14
@ -14,6 +14,24 @@ final class SourceRepository extends EntityRepository
|
|||||||
*/
|
*/
|
||||||
public function findOneBySlug(string $slug): ?SourceInterface
|
public function findOneBySlug(string $slug): ?SourceInterface
|
||||||
{
|
{
|
||||||
return $this->findOneBy(['slug' => $slug]);
|
return $this->findOneBy([
|
||||||
|
'slug' => $slug,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a source by id or if not defined, by slug.
|
||||||
|
*
|
||||||
|
* @param SourceInterface $requestedSource
|
||||||
|
*
|
||||||
|
* @return SourceInterface|null
|
||||||
|
*/
|
||||||
|
public function findOneByIdOrSlug(SourceInterface $requestedSource): ?SourceInterface
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->find($requestedSource->getId());
|
||||||
|
} catch (\Error $error) {
|
||||||
|
return $this->findOneBySlug($requestedSource->getSlug());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user