Skip to content

Commit a15b718

Browse files
committed
doc changes
Signed-off-by: Howriq <horea@rospace.com>
1 parent 41a07ca commit a15b718

File tree

16 files changed

+106
-17
lines changed

16 files changed

+106
-17
lines changed

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
steps:
2424
- name: Checkout
25-
uses: actions/checkout@v4
25+
uses: actions/checkout@v5
2626

2727
- name: Install PHP
2828
uses: shivammathur/setup-php@v2

docs/book/index.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 100 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
## Composer Requirements
44

5-
The first step is to add alongside your current packages the required entries for our Doctrine installation. We would add the following to our `composer.json` file located in our root folder:
5+
The first step is to add alongside your current packages the required entries for our Doctrine installation.
6+
We would add the following to our `composer.json` file located in our root folder:
67

7-
![composer](../images/composer.png)
8+
![composer](images/composer.png)
9+
10+
```text
11+
"dotkernel/dot-cache": "^4.0",
12+
"ramsey/uuid": "^4.5.0",
13+
"ramsey/uuid-doctrine": "^2.1.0",
14+
"roave/psr-container-doctrine": "^5.2.2 || ^6.0.0",
15+
```
816

917
`dotkernel/dot-cache`
1018

@@ -39,7 +47,35 @@ After successfully installing our dependencies we now need to configure our Doct
3947

4048
In the file `config/autoload/local.php` the structure would be updated like this:
4149

42-
![local.php](../images/local.png)
50+
![local.php](images/local.png)
51+
52+
```php
53+
$databases = [
54+
'default' => [
55+
'host' => 'localhost',
56+
'dbname' => 'light',
57+
'user' => 'root',
58+
'password' => '123',
59+
'port' => 3306,
60+
'driver' => 'pdo_mysql',
61+
'charset' => 'utf8mb4',
62+
'collate' => 'utf8mb4_general_ci',
63+
],
64+
// you can add more database connections into this array
65+
];
66+
67+
return [
68+
'databases' => $databases,
69+
'doctrine' => [
70+
'connection' => [
71+
'orm_default' => [
72+
'params' => $databases['default'],
73+
],
74+
],
75+
],
76+
// the rest of your configuration
77+
];
78+
```
4379

4480
### Declare the Doctrine Drivers and Migrations Location
4581

@@ -48,29 +84,82 @@ This package takes all the provided configs from the `config/config.php` file an
4884

4985
Our new `src/App/src/ConfigProvider.php` class would look like this now:
5086

51-
![Config provider factories update](../images/config-provider-1.png)
52-
![Doctrine config function](../images/config-provider-2.png)
87+
![Config provider factories update](images/config-provider-1.png)
88+
![Doctrine config function](images/config-provider-2.png)
5389

5490
We also require a new file `config/cli-config.php`.
5591
It initializes and returns a `DependencyFactory` that Doctrine Migrations uses to run migrations.
5692

57-
![cli-config](../images/cli-config.png)
93+
![cli-config](images/cli-config.png)
94+
95+
```php
96+
<?php
97+
98+
declare(strict_types=1);
99+
100+
use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager;
101+
use Doctrine\Migrations\Configuration\Migration\ConfigurationArray;
102+
use Doctrine\Migrations\DependencyFactory;
103+
use Doctrine\ORM\EntityManager;
104+
105+
$container = require 'config/container.php';
106+
107+
$entityManager = $container->get(EntityManager::class);
108+
$entityManager->getEventManager();
109+
110+
return DependencyFactory::fromEntityManager(
111+
new ConfigurationArray($container->get('config')['doctrine']['migrations']),
112+
new ExistingEntityManager($entityManager)
113+
);
114+
```
58115

59116
## Running doctrine
60117

61118
Now that everything has been configured we only need to do one last thing, to create an executable for the Doctrine CLI.
62-
In our case we will create it as `/bin/doctrine`
119+
In our case we will create a `doctrine` file inside the application's `bin` directory:
120+
121+
![bin/doctrine](images/doctrine.png)
122+
123+
```php
124+
#!/usr/bin/env php
125+
<?php
63126

64-
![bin/doctrine](../images/doctrine.png)
127+
declare(strict_types=1);
65128

66-
(Optional) To keep things tidy we recommend to make an executable for the migrations of Doctrine as well for example `/bin/doctrine-migrations`:
129+
use Doctrine\ORM\EntityManager;
130+
use Doctrine\ORM\Tools\Console\ConsoleRunner;
131+
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
67132

68-
![bin/doctrine-migrations](../images/doctrine-migrations.png)
133+
require_once 'vendor/autoload.php';
134+
135+
$container = require 'config/container.php';
136+
137+
$entityManager = $container->get(EntityManager::class);
138+
$entityManager->getEventManager();
139+
140+
ConsoleRunner::run(new SingleManagerProvider($entityManager));
141+
```
142+
143+
(Optional) To keep things tidy, we recommend making an executable for the migrations of Doctrine as well.
144+
For this, we create `doctrine-migrations` file inside the application's `bin` directory:
145+
146+
![bin/doctrine-migrations](images/doctrine-migrations.png)
147+
148+
```php
149+
#!/usr/bin/env php
150+
<?php
151+
152+
declare(strict_types=1);
153+
154+
namespace Doctrine\Migrations;
155+
156+
require __DIR__ . '/../vendor/doctrine/migrations/bin/doctrine-migrations.php';
157+
```
69158

70159
Now by running the command bellow we should see the Doctrine CLI version alongside its available commands:
71160

72161
```shell
73-
php bin/doctrine
162+
php ./bin/doctrine
74163
```
75164

76165
Example (truncated) output:

docs/book/v1/images/cli-config.png

24.5 KB
Loading

docs/book/v1/images/composer.png

12.5 KB
Loading
6.82 KB
Loading

docs/book/v1/images/doctrine.png

20 KB
Loading

0 commit comments

Comments
 (0)