The Clean Architecture in php


class CustomerRepository



Download 2,26 Mb.
Pdf ko'rish
bet125/179
Sana24.06.2021
Hajmi2,26 Mb.
#100337
1   ...   121   122   123   124   125   126   127   128   ...   179
Bog'liq
The-Clean-Architecture-in-PHP-Kristopher-Wilson

class
CustomerRepository
implements
CustomerRepositoryInterface {
protected
$entityManager
;
protected
$entityClass
=
'MyVendor\Domain\Entity\Customer'
;
public function
__construct
(EntityManager
$entityManager
) {
$this
->
entityManager
=
$entityManager
;
}
public function
getAll
() {
return
$this
->
entityManager
->
getRepository
(
$this
->
entityClass
)
->
getAll
();
}
public function
getById
(
$id
) {
return
$this
->
entityManager
->
find
(
$this
->
entityClass
,
$id
);
}
}
This is a really simple implementation of a repository using Doctrine ORM. Of course, to use
Doctrine, we also have various mapping files and configurations we need to setup to get things
to work, but this is our basic repository. We’re also missing the definition of a couple methods
above, but have simply omitted them for brevity. Were we actually trying to run this code, we’d
get an error that we didn’t implement all methods of the interface.
It implements our
CustomerRepositoryInterface
, such that anything requesting an instance of
this interface would be fully satisfied by using this concrete class.
Of course, this functionality looks pretty generic and unspecific to our
CustomerRepository
. We
could easily break this out into an abstract class so that we can prevent duplicate functionality
being littered about all of our repositories:

Download 2,26 Mb.

Do'stlaringiz bilan baham:
1   ...   121   122   123   124   125   126   127   128   ...   179




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish