Skip to content

Commit f3f2457

Browse files
committed
Changes for chapter 1
Signed-off-by: Howriq <[email protected]>
1 parent ac95ffa commit f3f2457

File tree

5 files changed

+128
-3
lines changed

5 files changed

+128
-3
lines changed

bin/doctrine-migrations

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
namespace Doctrine\Migrations;
7+
8+
require __DIR__ . '/../vendor/doctrine/migrations/bin/doctrine-migrations.php';

bin/doctrine.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
use Doctrine\ORM\EntityManager;
7+
use Doctrine\ORM\Tools\Console\ConsoleRunner;
8+
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
9+
10+
require_once 'vendor/autoload.php';
11+
12+
$container = require 'config/container.php';
13+
14+
$entityManager = $container->get(EntityManager::class);
15+
$entityManager->getEventManager();
16+
17+
ConsoleRunner::run(new SingleManagerProvider($entityManager));

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
"laminas/laminas-config-aggregator": "^1.17.0",
3333
"mezzio/mezzio": "^3.24.0",
3434
"mezzio/mezzio-fastroute": "^3.13.0",
35-
"mezzio/mezzio-twigrenderer": "^2.17.0"
35+
"mezzio/mezzio-twigrenderer": "^2.17.0",
36+
"dotkernel/dot-cache": "^4.0",
37+
"ramsey/uuid": "^4.5.0",
38+
"ramsey/uuid-doctrine": "^2.1.0",
39+
"roave/psr-container-doctrine": "^5.2.2"
3640
},
3741
"require-dev": {
3842
"filp/whoops": "^2.17.0",
@@ -43,7 +47,8 @@
4347
"phpunit/phpunit": "^10.5.45",
4448
"roave/security-advisories": "dev-master",
4549
"symfony/var-dumper": "^7.2.3",
46-
"vincentlanglet/twig-cs-fixer": "^3.5.1"
50+
"vincentlanglet/twig-cs-fixer": "^3.5.1",
51+
"phpstan/phpstan-doctrine": "^2.0.3"
4752
},
4853
"autoload": {
4954
"psr-4": {

config/cli-config.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager;
6+
use Doctrine\Migrations\Configuration\Migration\ConfigurationArray;
7+
use Doctrine\Migrations\DependencyFactory;
8+
use Doctrine\ORM\EntityManager;
9+
10+
$container = require 'config/container.php';
11+
12+
$entityManager = $container->get(EntityManager::class);
13+
$entityManager->getEventManager();
14+
15+
return DependencyFactory::fromEntityManager(
16+
new ConfigurationArray($container->get('config')['doctrine']['migrations']),
17+
new ExistingEntityManager($entityManager)
18+
);

src/App/src/ConfigProvider.php

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44

55
namespace Light\App;
66

7+
use Doctrine\ORM\EntityManager;
8+
use Doctrine\ORM\EntityManagerInterface;
9+
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
10+
use Dot\Cache\Adapter\ArrayAdapter;
11+
use Dot\Cache\Adapter\FilesystemAdapter;
712
use Light\App\Factory\GetIndexViewHandlerFactory;
813
use Light\App\Handler\GetIndexViewHandler;
914
use Mezzio\Application;
15+
use Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType;
16+
use Ramsey\Uuid\Doctrine\UuidBinaryType;
17+
use Ramsey\Uuid\Doctrine\UuidType;
18+
use Roave\PsrContainerDoctrine\EntityManagerFactory;
19+
20+
use function getcwd;
1021

1122
class ConfigProvider
1223
{
@@ -20,6 +31,7 @@ public function __invoke(): array
2031
{
2132
return [
2233
'dependencies' => $this->getDependencies(),
34+
'doctrine' => $this->getDoctrineConfig(),
2335
'templates' => $this->getTemplates(),
2436
];
2537
}
@@ -39,7 +51,12 @@ public function getDependencies(): array
3951
],
4052
],
4153
'factories' => [
42-
GetIndexViewHandler::class => GetIndexViewHandlerFactory::class,
54+
'doctrine.entity_manager.orm_default' => EntityManagerFactory::class,
55+
GetIndexViewHandler::class => GetIndexViewHandlerFactory::class,
56+
],
57+
'aliases' => [
58+
EntityManager::class => 'doctrine.entity_manager.orm_default',
59+
EntityManagerInterface::class => 'doctrine.entity_manager.orm_default',
4360
],
4461
];
4562
}
@@ -65,4 +82,64 @@ public function getTemplates(): array
6582
],
6683
];
6784
}
85+
86+
private function getDoctrineConfig(): array
87+
{
88+
return [
89+
'cache' => [
90+
'array' => [
91+
'class' => ArrayAdapter::class,
92+
],
93+
'filesystem' => [
94+
'class' => FilesystemAdapter::class,
95+
'directory' => getcwd() . '/data/cache',
96+
'namespace' => 'doctrine',
97+
],
98+
],
99+
'configuration' => [
100+
'orm_default' => [
101+
'result_cache' => 'filesystem',
102+
'metadata_cache' => 'filesystem',
103+
'query_cache' => 'filesystem',
104+
'hydration_cache' => 'array',
105+
'typed_field_mapper' => null,
106+
'second_level_cache' => [
107+
'enabled' => true,
108+
'default_lifetime' => 3600,
109+
'default_lock_lifetime' => 60,
110+
'file_lock_region_directory' => '',
111+
'regions' => [],
112+
],
113+
],
114+
],
115+
'connection' => [
116+
'orm_default' => [
117+
'doctrine_mapping_types' => [
118+
UuidBinaryType::NAME => 'binary',
119+
UuidBinaryOrderedTimeType::NAME => 'binary',
120+
],
121+
],
122+
],
123+
'driver' => [
124+
// The default metadata driver aggregates all other drivers into a single one.
125+
// Override `orm_default` only if you know what you're doing.
126+
'orm_default' => [
127+
'class' => MappingDriverChain::class,
128+
],
129+
],
130+
'migrations' => [
131+
// Modify this line based on where you would like to have you migrations
132+
'migrations_paths' => [
133+
'Migrations' => 'src/Migrations',
134+
],
135+
'all_or_nothing' => true,
136+
'check_database_platform' => true,
137+
],
138+
'types' => [
139+
UuidType::NAME => UuidType::class,
140+
UuidBinaryType::NAME => UuidBinaryType::class,
141+
UuidBinaryOrderedTimeType::NAME => UuidBinaryOrderedTimeType::class,
142+
],
143+
];
144+
}
68145
}

0 commit comments

Comments
 (0)