167167
168168
169169
170- < li class ="breadcrumb-item "> book </ li >
170+ < li class ="breadcrumb-item "> Tutorial </ li >
171171
172172
173173
@@ -202,10 +202,16 @@ <h5 class="subnavigation__title">Table of Contents</h5>
202202
203203
204204 < li class ="subnavigation__list-item ">
205- < span class ="subnavigation__headline "> book </ span >
205+ < span class ="subnavigation__headline "> Tutorial </ span >
206206 < ul class ="subnavigation__list ">
207207
208208
209+ < li class ="subnavigation__list-item ">
210+ < a href ="../introduction/ " class ="subnavigation__link "> Introduction</ a >
211+ </ li >
212+
213+
214+
209215< li class ="subnavigation__list-item subnavigation__list-item--active ">
210216 < a href ="./ " class ="subnavigation__link "> Chapter 1</ a >
211217</ li >
@@ -260,21 +266,21 @@ <h6 class="toc__headline">On this page</h6>
260266
261267
262268
263- <!-- <h2 class="chapter__headline text-black-50">book </h2>-->
269+ <!-- <h2 class="chapter__headline text-black-50">Tutorial </h2>-->
264270
265271
266272 < h1 id ="installing-doctrine "> Installing Doctrine</ h1 >
267273< h2 id ="composer-requirements "> Composer Requirements</ h2 >
268274< p > The first step is to add alongside your current packages the required entries for our Doctrine installation.
269275We would add the following to our < code > composer.json</ code > file located in our root folder:</ p >
270- < p > < img alt ="composer " src ="../images/composer.png " class ="img-responsive "/> </ p >
276+ < p > < img alt ="composer.json " src ="../images/composer.png " class ="img-responsive "/> </ p >
271277< pre class ="highlight "> < code class ="language-text "> "dotkernel/dot-cache": "^4.0",
272278"ramsey/uuid": "^4.5.0",
273279"ramsey/uuid-doctrine": "^2.1.0",
274280"roave/psr-container-doctrine": "^5.2.2 || ^6.0.0",</ code > </ pre >
275281< p > < code > dotkernel/dot-cache</ code > </ p >
276- < p > Provides caching support for DotKernel applications.
277- It offers a PSR-6 and PSR-16 compatible caching system that integrates smoothly with DotKernel 's service container.</ p >
282+ < p > Provides caching support for Dotkernel applications.
283+ It offers a PSR-6 and PSR-16 compatible caching system that integrates smoothly with Dotkernel 's service container.</ p >
278284< p > < code > ramsey/uuid</ code > </ p >
279285< p > A widely used PHP library for generating and working with UUIDs (Universally Unique Identifiers).
280286It supports multiple UUID versions.</ p >
@@ -283,12 +289,12 @@ <h2 id="composer-requirements">Composer Requirements</h2>
283289It allows Doctrine to store and retrieve UUIDs as proper value objects instead of plain strings, improving type safety.</ p >
284290< p > < code > roave/psr-container-doctrine</ code > </ p >
285291< p > Provides a set of factory classes that integrate Doctrine ORM with any PSR-11 container.
286- It simplifies wiring Doctrine EntityManager, DBAL, configuration, and related services in frameworks like DotKernel .</ p >
292+ It simplifies wiring Doctrine EntityManager, DBAL, configuration, and related services in frameworks like Dotkernel .</ p >
287293< p > < code > phpstan/phpstan-doctrine (dev requirement)</ code > </ p >
288294< p > An extension for PHPStan that improves static analysis for Doctrine.
289295It understands entity metadata, repositories, and common Doctrine patterns, helping catch errors during development.</ p >
290296< h2 id ="setting-up-doctrine "> Setting Up Doctrine</ h2 >
291- < p > After successfully installing our dependencies we now need to configure our Doctrine instance.</ p >
297+ < p > After successfully installing our dependencies, we now need to configure our Doctrine instance.</ p >
292298< h3 id ="declare-your-database "> Declare your database</ h3 >
293299< p > In the file < code > config/autoload/local.php</ code > the structure would be updated like this:</ p >
294300< p > < img alt ="local.php " src ="../images/local.png " class ="img-responsive "/> </ p >
@@ -317,12 +323,12 @@ <h3 id="declare-your-database">Declare your database</h3>
317323 ],
318324 // the rest of your configuration
319325];</ code > </ pre >
320- < h3 id ="declare-the-doctrine-drivers-and-migrations-location "> Declare the Doctrine Drivers and Migrations Location </ h3 >
326+ < h3 id ="declare-the-doctrine-drivers "> Declare the Doctrine Drivers</ h3 >
321327< p > With the very nice utility of the package < code > laminas/laminas-config-aggregator</ code > we can declare our doctrine settings in the < code > src/App/src/ConfigProvider.php</ code > file.
322328This package takes all the provided configs from the < code > config/config.php</ code > file and merges them into one.</ p >
323329< p > Our new < code > src/App/src/ConfigProvider.php</ code > class would look like this now:</ p >
324- < p > < img alt ="Config provider factories update " src ="../images/config-provider-1.png " / >
325- < img alt ="Doctrine config function " src ="../images/config-provider-2.png " /> </ p >
330+ < p > < img alt ="config- provider-1 " src ="../images/config-provider-1.png " class =" img-responsive " /> </ p >
331+ < p > < img alt ="config-provider-2 " src ="../images/config-provider-2.png " class =" img-responsive " /> </ p >
326332< pre class ="highlight "> < code class ="language-php "> public function __invoke(): array
327333{
328334 return [
@@ -366,12 +372,12 @@ <h3 id="declare-the-doctrine-drivers-and-migrations-location">Declare the Doctri
366372 ],
367373 'configuration' => [
368374 'orm_default' => [
369- 'result_cache' => 'filesystem',
370- 'metadata_cache' => 'filesystem',
371- 'query_cache' => 'filesystem',
372- 'hydration_cache' => 'array',
373- 'typed_field_mapper' => null,
374- 'second_level_cache' => [
375+ 'result_cache' => 'filesystem',
376+ 'metadata_cache' => 'filesystem',
377+ 'query_cache' => 'filesystem',
378+ 'hydration_cache' => 'array',
379+ 'typed_field_mapper' => null,
380+ 'second_level_cache' => [
375381 'enabled' => true,
376382 'default_lifetime' => 3600,
377383 'default_lock_lifetime' => 60,
@@ -387,44 +393,15 @@ <h3 id="declare-the-doctrine-drivers-and-migrations-location">Declare the Doctri
387393 'class' => MappingDriverChain::class,
388394 ],
389395 ],
390- 'migrations' => [
391- // Modify this line based on where you would like to have you migrations
392- 'migrations_paths' => [
393- 'Migrations' => 'src/Migrations',
394- ],
395- 'all_or_nothing' => true,
396- 'check_database_platform' => true,
397- ],
398396 'types' => [
399397 UuidType::NAME => UuidType::class,
400398 ],
401399 ];
402400}</ code > </ pre >
403- < p > We also require a new file < code > config/cli-config.php</ code > .
404- It initializes and returns a < code > DependencyFactory</ code > that Doctrine Migrations uses to run migrations.</ p >
405- < p > < img alt ="cli-config " src ="../images/cli-config.png " class ="img-responsive "/> </ p >
406- < pre class ="highlight "> < code class ="language-php "> <?php
407-
408- declare(strict_types=1);
409-
410- use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager;
411- use Doctrine\Migrations\Configuration\Migration\ConfigurationArray;
412- use Doctrine\Migrations\DependencyFactory;
413- use Doctrine\ORM\EntityManager;
414-
415- $container = require 'config/container.php';
416-
417- $entityManager = $container->get(EntityManager::class);
418- $entityManager->getEventManager();
419-
420- return DependencyFactory::fromEntityManager(
421- new ConfigurationArray($container->get('config')['doctrine']['migrations']),
422- new ExistingEntityManager($entityManager)
423- );</ code > </ pre >
424401< h2 id ="running-doctrine "> Running doctrine</ h2 >
425402< p > Now that everything has been configured we only need to do one last thing, to create an executable for the Doctrine CLI.
426403In our case we will create a < code > doctrine</ code > file inside the application's < code > bin</ code > directory:</ p >
427- < p > < img alt ="bin/ doctrine " src ="../images/doctrine.png " class ="img-responsive "/> </ p >
404+ < p > < img alt ="doctrine " src ="../images/doctrine.png " class ="img-responsive "/> </ p >
428405< pre class ="highlight "> < code class ="language-php "> #!/usr/bin/env php
429406<?php
430407
@@ -442,17 +419,6 @@ <h2 id="running-doctrine">Running doctrine</h2>
442419$entityManager->getEventManager();
443420
444421ConsoleRunner::run(new SingleManagerProvider($entityManager));</ code > </ pre >
445- < p > (Optional) To keep things tidy, we recommend making an executable for the migrations of Doctrine as well.
446- For this, we create < code > doctrine-migrations</ code > file inside the application's < code > bin</ code > directory:</ p >
447- < p > < img alt ="bin/doctrine-migrations " src ="../images/doctrine-migrations.png " class ="img-responsive "/> </ p >
448- < pre class ="highlight "> < code class ="language-php "> #!/usr/bin/env php
449- <?php
450-
451- declare(strict_types=1);
452-
453- namespace Doctrine\Migrations;
454-
455- require __DIR__ . '/../vendor/doctrine/migrations/bin/doctrine-migrations.php';</ code > </ pre >
456422< p > Now by running the command bellow we should see the Doctrine CLI version alongside its available commands:</ p >
457423< pre class ="highlight "> < code class ="language-shell "> php ./bin/doctrine</ code > </ pre >
458424< p > Example (truncated) output:</ p >
@@ -475,9 +441,9 @@ <h2 id="running-doctrine">Running doctrine</h2>
475441
476442 < li class ="col text-nowrap text-md-start ">
477443
478- < a rel ="prev " class ="page-nav__link page-nav__link--prev " href ="../.. ">
444+ < a rel ="prev " class ="page-nav__link page-nav__link--prev " href ="../introduction/ ">
479445 < i class ="bi bi-chevron-left "> </ i >
480- Home
446+ Introduction
481447 </ a >
482448
483449 </ li >
0 commit comments