SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
WHATISTHEDIFFERENCEBETWEENWHATISTHEDIFFERENCEBETWEEN
AAGOODGOODANDAANDABADBADREPOSITORY?REPOSITORY?
1
HI,IAMHI,IAMARNAUD!ARNAUD!
2
BOUCHONNOISCORPBOUCHONNOISCORP
3
WHATISAWHATISAREPOSITORYREPOSITORY??
«A repository behaves like an collection of unique domain
object without taking care about the storage»
4
PUBLICPUBLICAPIAPI
namespace BouchonnoisCorpDomainWrite;
interface Repository
{
/**
* @throws LogicException
*/
public function add(Object $object): void;
/**
* @throws UnknownObject | LogicException
*/
public function get(Identifier $identifier): Object;
/**
* @throws LogicException
*/
public function remove(Identifier $identifier): void;
/**
* @throws LogicException
*/
public function nextIdentity(): Identifier;
}
5
LET'SMODELALET'SMODELAGALINETTEGALINETTE!!
Dédé, Business Expert @BouchonnoisCorp
6
namespace BouchonnoisCorpDomainWrite;
/**final*/ class Galinette
{
// constructor ...
public static function born(
Identifier $identifier,
Birthday $birthday,
Gender $gender
): Galinette {
return new self($identifier, $birthday, new Name(''), $gender);
}
public function name(Name $name): void
{
$this->name = $name;
}
public function goToHeaven(): void
{
$this->goToHeavenAt = new DateTimeImmutable('NOW');
}
}
7
THEBADTHEBADREPOSITORYREPOSITORY
8
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
THESEARENOTTHESEARENOTREPOSITORIESREPOSITORIES!!
These are more SQL query repositories
10
THEGOODTHEGOODREPOSITORYREPOSITORY
11
LET'SLET'SDESIGNDESIGNIT!IT!
Gérard, CTO @BouchonnoisCorp
12
REPOSITORYREPOSITORYDEPENDENCIESDEPENDENCIES
namespace BouchonnoisCorpInfrastructureStorageDoctrine;
use BouchonnoisCorpDomainWriteGalinetteRepository;
final class GalinetteRepository implements GalinetteRepository
{
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
// ...
}
13
GETTHEGETTHENEXTIDENTITYNEXTIDENTITY
namespace BouchonnoisCorpInfrastructureStorageDoctrine;
final class GalinetteRepository implements GalinetteRepository
{
// ...
public function nextIdentity(): Identifier
{
try {
return new Identifier(Uuid::uuid4()->toString());
} catch (Exception $e) {
throw new LogicException('It is not possible to build the next identity');
}
}
}
14
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
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
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
AREPOSITORYMAYHAVEEXTRAAREPOSITORYMAYHAVEEXTRA
FINDERFINDERANDANDCOUNTCOUNTMETHODSMETHODS
18
HOWTOMANAGEMYHOWTOMANAGEMYSQLQUERIESSQLQUERIES??
19
WHATISAWHATISAQUERYFUNCTIONQUERYFUNCTION??
«A query function is a class which represents a SQL query.»
20
namespace BouchonnoisCorpInfrastructureStorageDoctrineQuery;
final class ReleaseOfGalinettes
{
private $connection;
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
public function findGalinettes(): array
{
$query = 'SELECT g.* FROM galinette
INNER JOIN g.censored_table_name ...'
$statement = $this->connection->query($query);
$galinettes = [];
while ($galinette = $statement->fetch()) {
$galinettes[] = new ReleasedGalinette(
$galinette['identifier'],
$galinette['name'],
$galinette['birthday']
);
}
return $galinettes;
}
}
21
namespace BouchonnoisCorpDomainRead;
final class ReleasedGalinette
{
private $identifier;
private $name;
private $birthday;
public function __construct(
string $identifier,
string $name,
string $birthday
) {
$this->identifier = $identifier;
$this->name = $name;
$this->birthday = $birthday;
}
public function normalize(): array
{
return [
'id' => $this->identifier,
'name' => $this->name,
'birthday' => $this->birthday,
];
}
}
22
TOCONCLUDE!TOCONCLUDE!
23
CODECODEANDANDSLIDESSLIDESAREAVAILABLEONAREAVAILABLEONGITLABGITLAB!!
https://gitlab.com/arnolanglade/bad-or-good-repository
24
THANKYOU!QUESTIONS?THANKYOU!QUESTIONS?
arnolanglade
https://joind.in/talk/afbbd
25

Contenu connexe

Tendances

Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
brian d foy
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
Thomas Weinert
 

Tendances (20)

Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
SfCon: Test Driven Development
SfCon: Test Driven DevelopmentSfCon: Test Driven Development
SfCon: Test Driven Development
 
The road to continuous deployment (PHPCon Poland 2016)
The road to continuous deployment (PHPCon Poland 2016)The road to continuous deployment (PHPCon Poland 2016)
The road to continuous deployment (PHPCon Poland 2016)
 
SPL, not a bridge too far
SPL, not a bridge too farSPL, not a bridge too far
SPL, not a bridge too far
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Oops in php
Oops in phpOops in php
Oops in php
 
Ioc container | Hannes Van De Vreken | CODEiD
Ioc container | Hannes Van De Vreken | CODEiDIoc container | Hannes Van De Vreken | CODEiD
Ioc container | Hannes Van De Vreken | CODEiD
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War Stories
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object Calisthenics
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
 
Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)
 
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
 

Similaire à What is the difference between a good and a bad repository? (Forum PHP 2018)

SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
Wildan Maulana
 

Similaire à What is the difference between a good and a bad repository? (Forum PHP 2018) (20)

SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionDrupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency Injection
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Les exceptions, oui, mais pas n'importe comment
Les exceptions, oui, mais pas n'importe commentLes exceptions, oui, mais pas n'importe comment
Les exceptions, oui, mais pas n'importe comment
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Laravel でやってみるクリーンアーキテクチャ #phpconfuk
Laravel でやってみるクリーンアーキテクチャ #phpconfukLaravel でやってみるクリーンアーキテクチャ #phpconfuk
Laravel でやってみるクリーンアーキテクチャ #phpconfuk
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
Functional php
Functional phpFunctional php
Functional php
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
 
Anonymous classes
Anonymous classesAnonymous classes
Anonymous classes
 

Plus de Arnaud Langlade

Plus de Arnaud Langlade (7)

Code me a HR
Code me a HRCode me a HR
Code me a HR
 
Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)
 
Php trollons mais trollons bien (Bdx.io 2015)
Php trollons mais trollons bien (Bdx.io 2015)Php trollons mais trollons bien (Bdx.io 2015)
Php trollons mais trollons bien (Bdx.io 2015)
 
Programmation STUPID vs SOLID (PHP Meetup)
Programmation STUPID vs SOLID (PHP Meetup)Programmation STUPID vs SOLID (PHP Meetup)
Programmation STUPID vs SOLID (PHP Meetup)
 
Php spec en 5 minutes
Php spec en 5 minutesPhp spec en 5 minutes
Php spec en 5 minutes
 
Sylius en 5 minutes
Sylius en 5 minutesSylius en 5 minutes
Sylius en 5 minutes
 
Développer avec le sylius resourcebundle (Symfony live Paris 2015)
Développer avec le sylius resourcebundle (Symfony live Paris 2015) Développer avec le sylius resourcebundle (Symfony live Paris 2015)
Développer avec le sylius resourcebundle (Symfony live Paris 2015)
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

What is the difference between a good and a bad repository? (Forum PHP 2018)