Skip to content

Commit 0025878

Browse files
committed
Merge branch '2.11.x' into 3.0.x
* 2.11.x: Use EntityManagerInterface in type declarations (#9325) Add errors caused by the lexer update to the baselines (#9360) Generated/Virtual Columns: Insertable / Updateable (#9118) Remove the composer/package-versions-deprecated package Relax assertion to include null as possible outcome (#9355)
2 parents 9624129 + ee59119 commit 0025878

File tree

76 files changed

+1006
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1006
-238
lines changed

UPGRADE.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ Use `toIterable()` instead.
124124

125125
# Upgrade to 2.11
126126

127+
## Rename `AbstractIdGenerator::generate()` to `generateId()`
128+
129+
Implementations of `AbstractIdGenerator` have to override the method
130+
`generateId()` without calling the parent implementation. Not doing so is
131+
deprecated. Calling `generate()` on any `AbstractIdGenerator` implementation
132+
is deprecated.
133+
127134
## PSR-6-based second level cache
128135

129136
The second level cache has been reworked to consume a PSR-6 cache. Using a
@@ -352,8 +359,7 @@ These methods have been deprecated:
352359
## Deprecated `Doctrine\ORM\Version`
353360

354361
The `Doctrine\ORM\Version` class is now deprecated and will be removed in Doctrine ORM 3.0:
355-
please refrain from checking the ORM version at runtime or use
356-
[ocramius/package-versions](https://github.com/Ocramius/PackageVersions/).
362+
please refrain from checking the ORM version at runtime or use Composer's [runtime API](https://getcomposer.org/doc/07-runtime.md#knowing-whether-package-x-is-installed-in-version-y).
357363

358364
## Deprecated `EntityManager#merge()` method
359365

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
},
2222
"require": {
2323
"php": "^8.0",
24+
"composer-runtime-api": "^2",
2425
"ext-ctype": "*",
2526
"ext-pdo": "*",
26-
"composer/package-versions-deprecated": "^1.8",
2727
"doctrine/cache": "^1.12.1 || ^2.1.1",
2828
"doctrine/collections": "^1.5",
2929
"doctrine/common": "^3.0.3",

docs/en/reference/annotations-reference.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ Optional attributes:
123123

124124
- **nullable**: Determines if NULL values allowed for this column. If not specified, default value is false.
125125

126+
- **insertable**: Boolean value to determine if the column should be
127+
included when inserting a new row into the underlying entities table.
128+
If not specified, default value is true.
129+
130+
- **updatable**: Boolean value to determine if the column should be
131+
included when updating the row of the underlying entities table.
132+
If not specified, default value is true.
133+
134+
- **generated**: An enum with the possible values ALWAYS, INSERT, NEVER. Is
135+
used after an INSERT or UPDATE statement to determine if the database
136+
generated this value and it needs to be fetched using a SELECT statement.
137+
126138
- **options**: Array of additional options:
127139

128140
- ``default``: The default value to set for the column if no value
@@ -193,6 +205,13 @@ Examples:
193205
*/
194206
protected $loginCount;
195207
208+
/**
209+
* Generated column
210+
* @Column(type="string", name="user_fullname", insertable=false, updatable=false)
211+
* MySQL example: full_name char(41) GENERATED ALWAYS AS (concat(firstname,' ',lastname)),
212+
*/
213+
protected $fullname;
214+
196215
.. _annref_column_result:
197216

198217
@ColumnResult

docs/en/reference/attributes-reference.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ Optional parameters:
178178
- **nullable**: Determines if NULL values allowed for this column.
179179
If not specified, default value is ``false``.
180180

181+
- **insertable**: Boolean value to determine if the column should be
182+
included when inserting a new row into the underlying entities table.
183+
If not specified, default value is true.
184+
185+
- **updatable**: Boolean value to determine if the column should be
186+
included when updating the row of the underlying entities table.
187+
If not specified, default value is true.
188+
189+
- **generated**: An enum with the possible values ALWAYS, INSERT, NEVER. Is
190+
used after an INSERT or UPDATE statement to determine if the database
191+
generated this value and it needs to be fetched using a SELECT statement.
192+
181193
- **options**: Array of additional options:
182194

183195
- ``default``: The default value to set for the column if no value
@@ -248,6 +260,15 @@ Examples:
248260
)]
249261
protected $loginCount;
250262
263+
// MySQL example: full_name char(41) GENERATED ALWAYS AS (concat(firstname,' ',lastname)),
264+
#[Column(
265+
type: "string",
266+
name: "user_fullname",
267+
insertable: false,
268+
updatable: false
269+
)]
270+
protected $fullname;
271+
251272
.. _attrref_cache:
252273

253274
#[Cache]

docs/en/reference/basic-mapping.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ list:
172172
unique key.
173173
- ``nullable``: (optional, default FALSE) Whether the database
174174
column is nullable.
175+
- ``insertable``: (optional, default TRUE) Whether the database
176+
column should be inserted.
177+
- ``updatable``: (optional, default TRUE) Whether the database
178+
column should be updated.
175179
- ``enumType``: (optional, requires PHP 8.1 and ORM 2.11) The PHP enum type
176180
name to convert the database value into.
177181
- ``precision``: (optional, default 0) The precision for a decimal

docs/en/reference/xml-mapping.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ Optional attributes:
256256
table? Defaults to false.
257257
- nullable - Should this field allow NULL as a value? Defaults to
258258
false.
259+
- insertable - Should this field be inserted? Defaults to true.
260+
- updatable - Should this field be updated? Defaults to true.
261+
- generated - Enum of the values ALWAYS, INSERT, NEVER that determines if
262+
generated value must be fetched from database after INSERT or UPDATE.
263+
Defaults to "NEVER".
259264
- version - Should this field be used for optimistic locking? Only
260265
works on fields with type integer or datetime.
261266
- scale - Scale of a decimal type.

doctrine-mapping.xsd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@
288288
</xs:restriction>
289289
</xs:simpleType>
290290

291+
<xs:simpleType name="generated-type">
292+
<xs:restriction base="xs:token">
293+
<xs:enumeration value="NEVER"/>
294+
<xs:enumeration value="INSERT"/>
295+
<xs:enumeration value="ALWAYS"/>
296+
</xs:restriction>
297+
</xs:simpleType>
298+
291299
<xs:complexType name="field">
292300
<xs:choice minOccurs="0" maxOccurs="unbounded">
293301
<xs:element name="options" type="orm:options" minOccurs="0" />
@@ -299,6 +307,9 @@
299307
<xs:attribute name="length" type="xs:NMTOKEN" />
300308
<xs:attribute name="unique" type="xs:boolean" default="false" />
301309
<xs:attribute name="nullable" type="xs:boolean" default="false" />
310+
<xs:attribute name="insertable" type="xs:boolean" default="true" />
311+
<xs:attribute name="updatable" type="xs:boolean" default="true" />
312+
<xs:attribute name="generated" type="orm:generated-type" default="NEVER" />
302313
<xs:attribute name="enum-type" type="xs:string" />
303314
<xs:attribute name="version" type="xs:boolean" />
304315
<xs:attribute name="column-definition" type="xs:string" />
@@ -623,6 +634,8 @@
623634
<xs:attribute name="length" type="xs:NMTOKEN" />
624635
<xs:attribute name="unique" type="xs:boolean" default="false" />
625636
<xs:attribute name="nullable" type="xs:boolean" default="false" />
637+
<xs:attribute name="insertable" type="xs:boolean" default="true" />
638+
<xs:attribute name="updateable" type="xs:boolean" default="true" />
626639
<xs:attribute name="version" type="xs:boolean" />
627640
<xs:attribute name="column-definition" type="xs:string" />
628641
<xs:attribute name="precision" type="xs:integer" use="optional" />

lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $e
5555
$data = $this->uow->getOriginalEntityData($entity);
5656
$data = array_merge($data, $metadata->getIdentifierValues($entity)); // why update has no identifier values ?
5757
58-
if ($metadata->isVersioned) {
59-
$data[$metadata->versionField] = $metadata->getFieldValue($entity, $metadata->versionField);
58+
if ($metadata->requiresFetchAfterChange) {
59+
if ($metadata->isVersioned) {
60+
$data[$metadata->versionField] = $metadata->getFieldValue($entity, $metadata->versionField);
61+
}
62+
63+
foreach ($metadata->fieldMappings as $name => $fieldMapping) {
64+
if (isset($fieldMapping['generated'])) {
65+
$data[$name] = $metadata->getFieldValue($entity, $name);
66+
}
67+
}
6068
}
6169

6270
foreach ($metadata->associationMappings as $name => $assoc) {

lib/Doctrine/ORM/EntityRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class EntityRepository implements ObjectRepository, Selectable
3939
/** @var string */
4040
protected $_entityName;
4141

42-
/** @var EntityManager */
42+
/** @var EntityManagerInterface */
4343
protected $_em;
4444

4545
/** @var ClassMetadata */
@@ -282,7 +282,7 @@ public function getClassName()
282282
}
283283

284284
/**
285-
* @return EntityManager
285+
* @return EntityManagerInterface
286286
*/
287287
protected function getEntityManager()
288288
{

lib/Doctrine/ORM/Event/LifecycleEventArgs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Doctrine\ORM\Event;
66

7-
use Doctrine\ORM\EntityManager;
7+
use Doctrine\ORM\EntityManagerInterface;
88
use Doctrine\Persistence\Event\LifecycleEventArgs as BaseLifecycleEventArgs;
99

1010
/**
@@ -28,7 +28,7 @@ public function getEntity()
2828
/**
2929
* Retrieves associated EntityManager.
3030
*
31-
* @return EntityManager
31+
* @return EntityManagerInterface
3232
*/
3333
public function getEntityManager()
3434
{

0 commit comments

Comments
 (0)