Skip to content

Commit 2dce2d0

Browse files
authored
[GH-9277] remove deprecated PHPDriver (#9308)
* Remove deprecated PHPDriver mapping driver, use StaticPHPDriver instead. * Update docs * Housekeeping * Update UPGRADE.md
1 parent 80bca72 commit 2dce2d0

File tree

37 files changed

+78
-1398
lines changed

37 files changed

+78
-1398
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Upgrade to 3.0
22

3+
## BC Break: Remove `Doctrine\ORM\Mapping\Driver\PHPDriver`
4+
5+
Use `StaticPHPDriver` instead when you want to programmatically configure
6+
entity metadata.
7+
38
## BC BREAK: Remove `Doctrine\ORM\EntityManagerInterface#transactional()`
49

510
This method has been replaced by `Doctrine\ORM\EntityManagerInterface#wrapInTransaction()`.

docs/en/reference/php-mapping.rst

Lines changed: 10 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,20 @@
11
PHP Mapping
22
===========
33

4-
Doctrine ORM also allows you to provide the ORM metadata in the form
5-
of plain PHP code using the ``ClassMetadata`` API. You can write
6-
the code in PHP files or inside of a static function named
7-
``loadMetadata($class)`` on the entity class itself.
8-
9-
PHP Files
10-
---------
11-
12-
If you wish to write your mapping information inside PHP files that
13-
are named after the entity and included to populate the metadata
14-
for an entity you can do so by using the ``PHPDriver``:
15-
16-
.. code-block:: php
17-
18-
<?php
19-
$driver = new PHPDriver('/path/to/php/mapping/files');
20-
$em->getConfiguration()->setMetadataDriverImpl($driver);
21-
22-
Now imagine we had an entity named ``Entities\User`` and we wanted
23-
to write a mapping file for it using the above configured
24-
``PHPDriver`` instance:
25-
26-
.. code-block:: php
27-
28-
<?php
29-
namespace Entities;
30-
31-
class User
32-
{
33-
private $id;
34-
private $username;
35-
}
36-
37-
To write the mapping information you just need to create a file
38-
named ``Entities.User.php`` inside of the
39-
``/path/to/php/mapping/files`` folder:
40-
41-
.. code-block:: php
42-
43-
<?php
44-
// /path/to/php/mapping/files/Entities.User.php
45-
46-
$metadata->mapField(array(
47-
'id' => true,
48-
'fieldName' => 'id',
49-
'type' => 'integer'
50-
));
51-
52-
$metadata->mapField(array(
53-
'fieldName' => 'username',
54-
'type' => 'string',
55-
'options' => array(
56-
'fixed' => true,
57-
'comment' => "User's login name"
58-
)
59-
));
60-
61-
$metadata->mapField(array(
62-
'fieldName' => 'login_count',
63-
'type' => 'integer',
64-
'nullable' => false,
65-
'options' => array(
66-
'unsigned' => true,
67-
'default' => 0
68-
)
69-
));
70-
71-
Now we can easily retrieve the populated ``ClassMetadata`` instance
72-
where the ``PHPDriver`` includes the file and the
73-
``ClassMetadataFactory`` caches it for later retrieval:
74-
75-
.. code-block:: php
76-
77-
<?php
78-
$class = $em->getClassMetadata('Entities\User');
79-
// or
80-
$class = $em->getMetadataFactory()->getMetadataFor('Entities\User');
4+
Doctrine ORM also allows you to provide the ORM metadata in the form of plain
5+
PHP code using the ``ClassMetadata`` API. You can write the code in inside of a
6+
static function named ``loadMetadata($class)`` on the entity class itself.
817

828
Static Function
839
---------------
8410

85-
In addition to the PHP files you can also specify your mapping
86-
information inside of a static function defined on the entity class
87-
itself. This is useful for cases where you want to keep your entity
88-
and mapping information together but don't want to use annotations.
89-
For this you just need to use the ``StaticPHPDriver``:
11+
In addition to other drivers using configuration languages you can also
12+
programatically specify your mapping information inside of a static function
13+
defined on the entity class itself.
14+
15+
This is useful for cases where you want to keep your entity and mapping
16+
information together but don't want to use annotations. For this you just need
17+
to use the ``StaticPHPDriver``:
9018

9119
.. code-block:: php
9220

lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/Doctrine/Tests/Models/Cache/City.php

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,68 @@ public function getAttractions(): Collection
138138

139139
public static function loadMetadata(ClassMetadataInfo $metadata): void
140140
{
141-
include __DIR__ . '/../../ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php';
141+
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
142+
$metadata->setPrimaryTable(['name' => 'cache_city']);
143+
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_IDENTITY);
144+
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
145+
146+
$metadata->enableCache(
147+
[
148+
'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY,
149+
]
150+
);
151+
152+
$metadata->mapField(
153+
[
154+
'fieldName' => 'id',
155+
'type' => 'integer',
156+
'id' => true,
157+
]
158+
);
159+
160+
$metadata->mapField(
161+
[
162+
'fieldName' => 'name',
163+
'type' => 'string',
164+
]
165+
);
166+
167+
$metadata->mapOneToOne(
168+
[
169+
'fieldName' => 'state',
170+
'targetEntity' => State::class,
171+
'inversedBy' => 'cities',
172+
'joinColumns' =>
173+
[
174+
[
175+
'name' => 'state_id',
176+
'referencedColumnName' => 'id',
177+
],
178+
],
179+
]
180+
);
181+
$metadata->enableAssociationCache('state', [
182+
'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY,
183+
]);
184+
185+
$metadata->mapManyToMany(
186+
[
187+
'fieldName' => 'travels',
188+
'targetEntity' => Travel::class,
189+
'mappedBy' => 'visitedCities',
190+
]
191+
);
192+
193+
$metadata->mapOneToMany(
194+
[
195+
'fieldName' => 'attractions',
196+
'targetEntity' => Attraction::class,
197+
'mappedBy' => 'city',
198+
'orderBy' => ['name' => 'ASC'],
199+
]
200+
);
201+
$metadata->enableAssociationCache('attractions', [
202+
'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY,
203+
]);
142204
}
143205
}

tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)