The Clean Architecture in php



Download 2,26 Mb.
Pdf ko'rish
bet175/179
Sana24.06.2021
Hajmi2,26 Mb.
#100337
1   ...   171   172   173   174   175   176   177   178   179
Bog'liq
The-Clean-Architecture-in-PHP-Kristopher-Wilson

Configuring Doctrine
Next up, we’re going to configure Doctrine. By default, Laravel uses
Eloquent ORM⁶³
. We’ll opt
to keep using Doctrine for now to limit how much code we’ll need to rewrite.
To use Doctrine, we’ll need to install a third party provider to make the two projects talk. In the
course of writing this book, I reviewed several of these “bridge” libraries. Unfortunately, all of
⁶³
http://laravel.com/docs/eloquent


Switching to Laravel
214
them either only worked for Laravel 4, depended on broken or non existent versions or commits
of Doctrine, or only supported XML or Annotation based mapping files.
So I quickly wrote a very minimal library to integrate the two projects. We’ll use this in our
examples, but please don’t use it in production. Bad things may very well happen.
To hopefully prevent public usage, this library was not published on Packagist, so we’ll have to
manually add a repository to the
composer.json
file:
"repositories"
:
[
{
"type"
:
"vcs"
,
"url"
:
"https://github.com/mrkrstphr/laravel-indoctrinated.git"
}
],
"require"
:
{
"laravel/framework"
:
"5.0.*"
,
"mrkrstphr/laravel-indoctrinated"
:
"dev-master"
},
Run
composer update
to install this new repository, which will bring along with it
doctrine/orm
and its dependencies.
Once that’s installed, we’ll need to add the new provider to the array of providers located at
config/app.php
:
return
[
'providers'
=>
[
// ...
'Mrkrstphr\LaravelIndoctrinated\DoctrineOrmServiceProvider'
],
// ...
];
Next, we’ll run a command to publish this provider, which generates a sample config file for us:
php artisan vendor:publish
\
--provider
"Mrkrstphr\LaravelIndoctrinated\DoctrineOrmServiceProvider"
Now let’s modify our config file located at
config/doctrine.php
:


Switching to Laravel
215
return
[
// database connection information is managed in Laravel's
// config/database.php file
'mappings'
=>
[
'type'
=>
'yaml'
,
'paths'
=>
[__DIR__
.
'/../core/Persistence/Doctrine/Mapping'
]
],
];
As the config file says, our database connection information will be managed by Laravel. Let’s
change the
config/database.php
file as follows:
return
[
'default'
=>
'sqlite'
,
'connections'
=>
[
'sqlite'
=>
[
'driver'
=>
'sqlite'
,
'database'
=>
storage_path()
.
'/database.db'
,
]
]
];
We now have Laravel configured to talk to Doctrine and setup to use our
database.db
sqlite
database.
This would make a good place to commit your code to source control.
If you’re just reading, but want to see the code in action, you can checkout the tag
14-laravel-doctrine:
git clone https://github.com/mrkrstphr/cleanphp-example.git
git checkout 14-laravel-doctrine

Download 2,26 Mb.

Do'stlaringiz bilan baham:
1   ...   171   172   173   174   175   176   177   178   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