We won't talk about Akeneo nor Sylius today, we will speak about the Bouchonnois Corp, a French corporation of hunters. At the cutting edge of the technology, the company owns many applications and one of them is used to manage their galinette farming. We will focus on a small part of this application to speak about the pattern repository.
9. namespace BouchonnoisCorpDomainWrite;
interface GalinetteRepository
{
public function find(int $id): Galinette;
public function findGalinetteArray(): array;
public function findGalinetteForARelease(): Galinette[];
public function findGalinetteIdentifierForAReleaseAsString(): string[];
public function findGalinetteNameByIdentifier(int $id): string;
public function getQueryBuilder(): QueryBuilder;
// etc ...
}
9
15. ADDADDAGALINETTEAGALINETTE
namespace BouchonnoisCorpInfrastructureStorageDoctrine;
final class GalinetteRepository implements GalinetteRepository
{
// ...
public function add(Galinette $galinette)
{
try {
$this->entityManager->persist($galinette);
$this->entityManager->flush($galinette);
} catch (ORMInvalidArgumentException | ORMException $e) {
throw new LogicException('It is not possible to add this galinette');
}
}
// ...
}
15
16. RETRIEVERETRIEVEAGALINETTEAGALINETTE
namespace BouchonnoisCorpInfrastructureStorageDoctrine;
final class GalinetteRepository implements GalinetteRepository
{
// ...
public function get(Identifier $identifier): Galinette
{
try {
$galinette = $this->entityManager->find(Galinette::class, $identifier);
} catch (ORMInvalidArgumentException | ORMException $e) {
throw new LogicException('It is not possible to retrieve this galinette');
} finally {
if (null === $galinette) {
throw new ExceptionUnknownGalinette(
(string) $identifier,
Galinette::class
);
}
return $galinette;
}
}
// ...
}
16
17. REMOVEREMOVEAGALINETTE?AGALINETTE?
namespace BouchonnoisCorpInfrastructureStorageDoctrine;
final class ObjectRepository
{
// ...
public function remove(Identifier $identifier)
{
try {
$galinette = $this->entityManager->getReference(
Object::class,
(string) $identifier
);
$this->entityManager->remove($galinette);
$this->entityManager->flush($galinette);
} catch (ORMInvalidArgumentException | ORMException $e) {
throw new LogicException('It is not possible to remove this object');
}
}
// ...
}
17