The Clean Architecture in php



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

class
BillingService
{
protected
$orderRepository
;
protected
$invoiceRepository
;
protected
$invoiceFactory
;
public function
__construct
(
OrderRepositoryInterface
$order
,
InvoiceRepositoryInterface
$invoice
,
InvoiceFactory
$factory
) {
$this
->
orderRepository
=
$order
;
$this
->
invoiceRepository
=
$invoice
;
$this
->
invoiceFactory
=
$factory
;
}


Database Independence
89
public function
generateInvoices
(\DateTime
$invoiceDate
) {
$orders
=
$this
->
ordersRepository
->
getActiveBillingOrders
(
$invoiceDate
);
foreach
(
$orders
as
$order
) {
$invoice
=
$this
->
invoiceFactory
->
create
(
$order
);
$this
->
invoiceRepository
->
save
(
$invoice
);
}
}
}
This service is pretty simple, because it leverages the power of the
OrderRepository
given to it to
retrieve orders, and the
InvoiceFactory
to generate invoice objects. It then simply persists them
to the database using the
InvoiceRepository
. The
BillingService
can now be used anywhere
that invoices need to be generated for whatever means of ordering the system needs implement.
This is abstracted away into the service, so that the code is not repeated all over the place.
Further, this code does not depend on a specific data store whatsoever, instead, asking for an
implementation of both
OrderRepositoryInterface
and
InvoiceRepositoryInterface
. If those
dependencies are satisfied with concrete implementations, the Service works correctly finding
orders to invoice and generating those invoices.
This code is powerful, but dead simple. It’s coupled to nothing but the rest of our Domain Model
and Domain Services layer. It is 100% decoupled from any specific database implementation.

Download 2,26 Mb.

Do'stlaringiz bilan baham:
1   ...   119   120   121   122   123   124   125   126   ...   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