Skip to content

Commit 2edb480

Browse files
authored
Merge pull request #714 from driehle/feature/custom-type-docs
Updated docs in regard of custom types and type comments
2 parents 43b8e32 + 3438103 commit 2edb480

File tree

3 files changed

+40
-62
lines changed

3 files changed

+40
-62
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- "8.1"
2323
dbal-version:
2424
- "2.13.0"
25-
- "3.1.0"
25+
- "3.3.0"
2626
dependencies:
2727
- "highest"
2828
optional-dependencies:
@@ -34,15 +34,15 @@ jobs:
3434
dependencies: "lowest"
3535
optional-dependencies: false
3636
- php-version: "7.4"
37-
dbal-version: "3.1.0"
37+
dbal-version: "3.3.0"
3838
dependencies: "lowest"
3939
optional-dependencies: false
4040
- php-version: "7.4"
4141
dbal-version: "2.13.0"
4242
dependencies: "lowest"
4343
optional-dependencies: true
4444
- php-version: "7.4"
45-
dbal-version: "3.1.0"
45+
dbal-version: "3.3.0"
4646
dependencies: "lowest"
4747
optional-dependencies: true
4848

docs/en/configuration.rst

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,24 @@ Register a Custom DQL Function
66

77
.. code:: php
88
9-
namespace Db;
10-
119
return [
1210
'doctrine' => [
1311
'configuration' => [
1412
'orm_default' => [
1513
'numeric_functions' => [
16-
'ROUND' => Db\DoctrineExtensions\Query\Mysql\Round::class,
17-
],
18-
],
19-
],
20-
],
21-
];
22-
23-
24-
Register a Type mapping
25-
-----------------------
26-
27-
.. code:: php
28-
29-
return [
30-
'doctrine' => [
31-
'connection' => [
32-
'orm_default' => [
33-
'doctrine_type_mappings' => [
34-
'enum' => 'string',
14+
'ROUND' => \My\DoctrineExtensions\Query\Mysql\Round::class,
3515
],
3616
],
3717
],
3818
],
3919
];
4020
21+
How to add a Custom Type
22+
------------------------
4123

42-
How to add a new type
43-
---------------------
24+
First, implement a new type by extending `Doctrine\DBAL\Types\Type`. An example can be found in
25+
the `ORM cookbook <https://www.doctrine-project.org/projects/doctrine-orm/en/current/cookbook/custom-mapping-types.html#custom-mapping-types>`__
26+
Then, register your type implementation with DBAL as follows:
4427

4528
.. code:: php
4629
@@ -49,48 +32,35 @@ How to add a new type
4932
'configuration' => [
5033
'orm_default' => [
5134
'types' => [
52-
'newtype' => 'Db\DBAL\Types\NewType',
35+
'newtype' => \My\Types\NewType::class,
5336
],
5437
],
5538
],
5639
],
5740
];
5841
59-
.. code:: php
60-
61-
return [
62-
'doctrine' => [
63-
'connection' => [
64-
'orm_default' => [
65-
'doctrine_type_mappings' => [
66-
'mytype' => 'mytype',
67-
],
68-
],
69-
],
70-
],
71-
];
42+
.. note::
7243

44+
If your type uses a database type which is already `mapped by Doctrine <https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#mapping-matrix>`__,
45+
Doctrine will need a comment hint to distinguish your type from other types. In your type class, override
46+
`requiresSQLCommentHint()` to return `true` to let Doctrine add a comment hint.
7347

74-
Doctrine Type Comment
75-
---------------------
76-
77-
Option to set the doctrine type comment (DC2Type:myType) for custom types
48+
Next, you will need to register your custom type with the underlying database platform:
7849

7950
.. code:: php
8051
8152
return [
8253
'doctrine' => [
8354
'connection' => [
8455
'orm_default' => [
85-
'doctrineCommentedTypes' => [
86-
'mytype',
56+
'doctrine_type_mappings' => [
57+
'mytype' => 'mytype',
8758
],
8859
],
8960
],
9061
],
9162
];
9263
93-
9464
Built-in Resolver
9565
-----------------
9666

@@ -103,8 +73,8 @@ How to Define Relationships with Abstract Classes and Interfaces (ResolveTargetE
10373
'entity_resolver' => [
10474
'orm_default' => [
10575
'resolvers' => [
106-
'Acme\\InvoiceModule\\Model\\InvoiceSubjectInterface',
107-
'Acme\\CustomerModule\\Entity\\Customer',
76+
\Acme\InvoiceModule\Model\InvoiceSubjectInterface::class,
77+
\Acme\CustomerModule\Entity\Customer::class,
10878
],
10979
],
11080
],
@@ -140,7 +110,7 @@ See also `this blog article <https://blog.tomhanderson.com/2016/03/zf2-doctrine-
140110
'doctrine' => [
141111
'connection' => [
142112
'orm_crawler' => [
143-
'driverClass' => 'Doctrine\DBAL\Driver\PDO\MySql\Driver',
113+
'driverClass' => \Doctrine\DBAL\Driver\PDO\MySql\Driver::class,
144114
'eventmanager' => 'orm_crawler',
145115
'configuration' => 'orm_crawler',
146116
'params' => [
@@ -172,14 +142,14 @@ See also `this blog article <https://blog.tomhanderson.com/2016/03/zf2-doctrine-
172142
173143
'driver' => [
174144
'orm_crawler_annotation' => [
175-
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
145+
'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
176146
'cache' => 'array',
177147
'paths' => [
178148
__DIR__ . '/../src/Crawler/Entity',
179149
],
180150
],
181151
'orm_crawler_chain' => [
182-
'class' => 'Doctrine\ORM\Mapping\Driver\DriverChain',
152+
'class' => \Doctrine\ORM\Mapping\Driver\DriverChain::class,
183153
'drivers' => [
184154
'Crawler\Entity' => 'orm_crawler_annotation',
185155
],
@@ -221,8 +191,8 @@ The ``DoctrineModule\ServiceFactory\AbstractDoctrineServiceFactory`` will create
221191
You can retrieve them from the service manager via their keys.
222192

223193

224-
How to Use Naming Strategy
225-
--------------------------
194+
How to Use a Naming Strategy
195+
----------------------------
226196

227197
`Official documentation
228198
<https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/namingstrategy.html>`__
@@ -234,20 +204,20 @@ Laminas Configuration
234204
return [
235205
'service_manager' => [
236206
'invokables' => [
237-
'Doctrine\ORM\Mapping\UnderscoreNamingStrategy' => 'Doctrine\ORM\Mapping\UnderscoreNamingStrategy',
207+
\Doctrine\ORM\Mapping\UnderscoreNamingStrategy::class => \Doctrine\ORM\Mapping\UnderscoreNamingStrategy::class,
238208
],
239209
],
240210
'doctrine' => [
241211
'configuration' => [
242212
'orm_default' => [
243-
'naming_strategy' => 'Doctrine\ORM\Mapping\UnderscoreNamingStrategy',
213+
'naming_strategy' => \Doctrine\ORM\Mapping\UnderscoreNamingStrategy::class,
244214
],
245215
],
246216
],
247217
];
248218
249-
How to Use Quote Strategy
250-
-------------------------
219+
How to Use a Quote Strategy
220+
---------------------------
251221

252222
`Official
253223
documentation <https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/basic-mapping.html#quoting-reserved-words>`__
@@ -259,20 +229,20 @@ Laminas Configuration
259229
return [
260230
'service_manager' => [
261231
'invokables' => [
262-
'Doctrine\ORM\Mapping\AnsiQuoteStrategy' => 'Doctrine\ORM\Mapping\AnsiQuoteStrategy',
232+
\Doctrine\ORM\Mapping\AnsiQuoteStrategy::class => \Doctrine\ORM\Mapping\AnsiQuoteStrategy::class,
263233
],
264234
],
265235
'doctrine' => [
266236
'configuration' => [
267237
'orm_default' => [
268-
'quote_strategy' => 'Doctrine\ORM\Mapping\AnsiQuoteStrategy',
238+
'quote_strategy' => \Doctrine\ORM\Mapping\AnsiQuoteStrategy::class,
269239
],
270240
],
271241
],
272242
];
273243
274244
How to Override RunSqlCommand Creation
275-
-------------------------
245+
--------------------------------------
276246

277247
The following Laminas configuration can be used to override the creation of the
278248
``Doctrine\DBAL\Tools\Console\Command\RunSqlCommand`` instance used by this
@@ -288,7 +258,7 @@ module.
288258
],
289259
];
290260
291-
How to exclude tables from a schema diff
261+
How to Exclude Tables from a Schema Diff
292262
----------------------------------------
293263

294264
The "schema_assets_filter" option can be used to exclude certain tables from being created or deleted in a schema update:
@@ -307,3 +277,7 @@ The "schema_assets_filter" option can be used to exclude certain tables from bei
307277
],
308278
];
309279
280+
.. note::
281+
282+
If you want your application config to be cached, you should use a callable in terms of a static
283+
function (like `MyFilterClass::filter`) instead of a closure.

src/Options/DBALConnection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public function getDoctrineTypeMappings(): array
119119
}
120120

121121
/**
122+
* @deprecated 5.1.0 Deprecated in DBAL 3.3, use `Type::requiresSQLCommentTypeHint()` instead.
123+
*
122124
* @param mixed[] $doctrineCommentedTypes
123125
*/
124126
public function setDoctrineCommentedTypes(array $doctrineCommentedTypes): void
@@ -127,6 +129,8 @@ public function setDoctrineCommentedTypes(array $doctrineCommentedTypes): void
127129
}
128130

129131
/**
132+
* @deprecated 5.1.0 Deprecated in DBAL 3.3, use `Type::requiresSQLCommentTypeHint()` instead.
133+
*
130134
* @return mixed[]
131135
*/
132136
public function getDoctrineCommentedTypes(): array

0 commit comments

Comments
 (0)