You are browsing a version that is no longer maintained. |
Configuration
How to add a Custom Type
First, implement a new type by extending Doctrine\DBAL\Types\Type
. An example can be found in
the ORM cookbook
Then, register your type implementation with DBAL as follows:
If your type uses a database type which is already mapped by Doctrine,
Doctrine will need a comment hint to distinguish your type from other types. In your type class, override
|
Next, you will need to register your custom type with the underlying database platform:
Using DBAL Middlewares
This feature is only available when using DBAL 3.x and has no effect on DBAL 2.x! |
Laminas configuration
1 return [
'service_manager' => [
'invokables' => [
\My\Middlewares\CustomMiddleware::class => \My\Middlewares\CustomMiddleware::class,
\My\Middlewares\AnotherCustomMiddleware::class => \My\Middlewares\AnotherCustomMiddleware::class,
],
],
'doctrine' => [
'configuration' => [
'test_default' => [
'middlewares' => [
\My\Middlewares\CustomMiddleware::class,
\My\Middlewares\AnotherCustomMiddleware::class,
],
],
],
],
];
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Built-in Resolver
How to Define Relationships with Abstract Classes and Interfaces (ResolveTargetEntityListener)
How to Use Two Connections
In this example we create an 'orm_crawler' ORM connection. See also this blog article.
1 return [
'doctrine' => [
'connection' => [
'orm_crawler' => [
'driverClass' => \Doctrine\DBAL\Driver\PDO\MySQL\Driver::class,
'eventmanager' => 'orm_crawler',
'configuration' => 'orm_crawler',
'params' => [
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => 'root',
'dbname' => 'crawler',
'driverOptions' => [
1002 => 'SET NAMES utf8',
],
],
],
],
'configuration' => [
'orm_crawler' => [
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'hydration_cache' => 'array',
'driver' => 'orm_crawler_chain',
'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineORMModule/Proxy',
'proxy_namespace' => 'DoctrineORMModule\Proxy',
'filters' => [],
],
],
'driver' => [
'orm_crawler_annotation' => [
'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
'cache' => 'array',
'paths' => [
__DIR__ . '/../src/Crawler/Entity',
],
],
'orm_crawler_chain' => [
'class' => \Doctrine\ORM\Mapping\Driver\DriverChain::class,
'drivers' => [
'Crawler\Entity' => 'orm_crawler_annotation',
],
],
],
'entitymanager' => [
'orm_crawler' => [
'connection' => 'orm_crawler',
'configuration' => 'orm_crawler',
],
],
'eventmanager' => [
'orm_crawler' => [],
],
'sql_logger_collector' => [
'orm_crawler' => [],
],
'entity_resolver' => [
'orm_crawler' => [],
],
],
];
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
The DoctrineModule\ServiceFactory\AbstractDoctrineServiceFactory
will create the following objects as needed:
- doctrine.connection.orm_crawler
- doctrine.configuration.orm_crawler
- doctrine.entitymanager.orm_crawler
- doctrine.driver.orm_crawler
- doctrine.eventmanager.orm_crawler
- doctrine.entity_resolver.orm_crawler
- doctrine.sql_logger_collector.orm_crawler
You can retrieve them from the service manager via their keys.
How to Use a Naming Strategy
Laminas Configuration
1 return [
'service_manager' => [
'invokables' => [
\Doctrine\ORM\Mapping\UnderscoreNamingStrategy::class => \Doctrine\ORM\Mapping\UnderscoreNamingStrategy::class,
],
],
'doctrine' => [
'configuration' => [
'orm_default' => [
'naming_strategy' => \Doctrine\ORM\Mapping\UnderscoreNamingStrategy::class,
],
],
],
];
2
3
4
5
6
7
8
9
10
11
12
13
14
How to Use a Quote Strategy
Laminas Configuration
1 return [
'service_manager' => [
'invokables' => [
\Doctrine\ORM\Mapping\AnsiQuoteStrategy::class => \Doctrine\ORM\Mapping\AnsiQuoteStrategy::class,
],
],
'doctrine' => [
'configuration' => [
'orm_default' => [
'quote_strategy' => \Doctrine\ORM\Mapping\AnsiQuoteStrategy::class,
],
],
],
];
2
3
4
5
6
7
8
9
10
11
12
13
14
How to Override RunSqlCommand Creation
The following Laminas configuration can be used to override the creation of the
Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
instance used by this
module.
How to Exclude Tables from a Schema Diff
The "schema_assets_filter" option can be used to exclude certain tables from being created or deleted in a schema update:
If you want your application config to be cached, you should use a callable in terms of a static
function (like |