mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 15:02:22 +01:00
Compare commits
204 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92e2f6db83 | ||
|
|
aa624f64c1 | ||
|
|
e1675eb371 | ||
|
|
cc2b6385a1 | ||
|
|
a64bed9bbb | ||
|
|
3272e1c0af | ||
|
|
69da22d517 | ||
|
|
06109f360f | ||
|
|
06a9ef1127 | ||
|
|
5d21bb158b | ||
|
|
c74df3fab3 | ||
|
|
f2c902ee03 | ||
|
|
4e5e3c5e50 | ||
|
|
da697f218f | ||
|
|
4f47a80deb | ||
|
|
ab89517093 | ||
|
|
48a51d8470 | ||
|
|
ab11244f08 | ||
|
|
a1c2be140d | ||
|
|
4664373bd0 | ||
|
|
5ab6b74f14 | ||
|
|
71550106d4 | ||
|
|
36011f0d0f | ||
|
|
c97d775370 | ||
|
|
97b29bb063 | ||
|
|
e9f0345a97 | ||
|
|
b7fff508a4 | ||
|
|
c6fa14ed52 | ||
|
|
05c8c5f114 | ||
|
|
1dbdb0e895 | ||
|
|
0feb09d0d6 | ||
|
|
fe5f8bbaa1 | ||
|
|
ecf3cec376 | ||
|
|
0a714db4d9 | ||
|
|
471fda8d0b | ||
|
|
dfe32c2f74 | ||
|
|
c51ba3ce6b | ||
|
|
fe025e8d23 | ||
|
|
0a43e4af8f | ||
|
|
7111cc09f3 | ||
|
|
777504b9c4 | ||
|
|
9d9985076a | ||
|
|
35d301b052 | ||
|
|
083b241c81 | ||
|
|
ae2957cf7e | ||
|
|
e172b3bf9c | ||
|
|
c9c6e8da2e | ||
|
|
b9989555fd | ||
|
|
80a79f6d2d | ||
|
|
1f1891d3e2 | ||
|
|
c9fc4d90e5 | ||
|
|
17d28b5c4c | ||
|
|
a2d510c6f4 | ||
|
|
0e3cff0c6a | ||
|
|
5c50ed925a | ||
|
|
5a1e560f87 | ||
|
|
78e8887759 | ||
|
|
9a3f5579f1 | ||
|
|
5eb298b99b | ||
|
|
5eb0255f47 | ||
|
|
28575f58af | ||
|
|
457d2d2841 | ||
|
|
12c721f528 | ||
|
|
9a9c3e8aba | ||
|
|
2a4ebca90e | ||
|
|
5d01c66c84 | ||
|
|
a2516b67dc | ||
|
|
46a020108d | ||
|
|
3d4e9b3ecf | ||
|
|
d1ee40e7d5 | ||
|
|
65d2720764 | ||
|
|
3e18a58de6 | ||
|
|
a9f9202c00 | ||
|
|
d8cb71fe4a | ||
|
|
d659591b6c | ||
|
|
e2430ac9a7 | ||
|
|
b286d6cd2c | ||
|
|
0b373f6c27 | ||
|
|
443cf92242 | ||
|
|
36b9064dbe | ||
|
|
eb3b984132 | ||
|
|
cc29ae0d36 | ||
|
|
bd4a053d29 | ||
|
|
52fbfb3785 | ||
|
|
c259371e5f | ||
|
|
dcdd58b642 | ||
|
|
7b9c53854f | ||
|
|
cdc5fe11dd | ||
|
|
69ece00564 | ||
|
|
04395f98f9 | ||
|
|
4baa7bd252 | ||
|
|
c55f10e501 | ||
|
|
f3fb79658e | ||
|
|
10a32cb824 | ||
|
|
c679d1b007 | ||
|
|
1e15b22dcb | ||
|
|
0c10010f9f | ||
|
|
d88371331d | ||
|
|
b260ec8a00 | ||
|
|
44057b4683 | ||
|
|
013df03795 | ||
|
|
2d2a34407c | ||
|
|
be8da83aca | ||
|
|
f5ab687226 | ||
|
|
742eead849 | ||
|
|
1072ea6db4 | ||
|
|
baf2c60cc4 | ||
|
|
8e620cad40 | ||
|
|
f98e871913 | ||
|
|
4b0c11978e | ||
|
|
daf0f82884 | ||
|
|
0ef5610a6c | ||
|
|
e29d0e977d | ||
|
|
3303cd3b5d | ||
|
|
afcf91e839 | ||
|
|
c61a9b3b6d | ||
|
|
bd0509a064 | ||
|
|
d540f73778 | ||
|
|
201d751a26 | ||
|
|
6308b2fd86 | ||
|
|
8f99e84438 | ||
|
|
e36b7755e9 | ||
|
|
7b4d869b31 | ||
|
|
708bd84fe2 | ||
|
|
3aed6912a3 | ||
|
|
8873109b4f | ||
|
|
36bef3f959 | ||
|
|
980ccc58dc | ||
|
|
62ca4624a9 | ||
|
|
1aed318b7b | ||
|
|
8ce7b310c5 | ||
|
|
5077ae41e5 | ||
|
|
8e1a27b8cc | ||
|
|
e7db1b005f | ||
|
|
72ce662e45 | ||
|
|
673cf0d4d8 | ||
|
|
1cae0534a0 | ||
|
|
6fb3083f63 | ||
|
|
68c17ca1bd | ||
|
|
82cf29407c | ||
|
|
158605bf24 | ||
|
|
2c2ef65817 | ||
|
|
f8fdeaf41e | ||
|
|
1c33a86983 | ||
|
|
310fe1cccb | ||
|
|
a67f677747 | ||
|
|
ae74be5e9d | ||
|
|
c9557c588b | ||
|
|
19912de927 | ||
|
|
737cca5b78 | ||
|
|
4163efd2f2 | ||
|
|
d7ac6123ad | ||
|
|
aff82af7de | ||
|
|
9e999ea1ff | ||
|
|
6755bb0c7b | ||
|
|
bd260d1be8 | ||
|
|
aa141bf001 | ||
|
|
cd1a52c7e4 | ||
|
|
cf39e00553 | ||
|
|
27b47841be | ||
|
|
c2a49327a7 | ||
|
|
9bd7242376 | ||
|
|
fff085b63f | ||
|
|
5ad5b11ae1 | ||
|
|
c12fd2cb94 | ||
|
|
44d5d4a779 | ||
|
|
5a599233c9 | ||
|
|
596da353c2 | ||
|
|
0d2cb6acd1 | ||
|
|
327418a4b7 | ||
|
|
68c87740aa | ||
|
|
55dc02c39f | ||
|
|
9f2b367081 | ||
|
|
a9873c86bb | ||
|
|
8ebd98ee92 | ||
|
|
4feaa470af | ||
|
|
5a220078e9 | ||
|
|
a15543a2ce | ||
|
|
238fb74028 | ||
|
|
6ff2b130d3 | ||
|
|
8c9bfca255 | ||
|
|
c2a2386df9 | ||
|
|
2f98e11562 | ||
|
|
073809cf5c | ||
|
|
e82690d256 | ||
|
|
23c31aec51 | ||
|
|
622ba2dcc7 | ||
|
|
0c1cf853fc | ||
|
|
79d1f07fa2 | ||
|
|
eba01f8d0e | ||
|
|
bd292481bd | ||
|
|
fcc53b260f | ||
|
|
7d61a1e73f | ||
|
|
b3cffe2d12 | ||
|
|
052c7d7698 | ||
|
|
c2713adebc | ||
|
|
51a984be3d | ||
|
|
6007154484 | ||
|
|
22ce0aff37 | ||
|
|
37051d57ce | ||
|
|
4563f2f9a7 | ||
|
|
91201c094a | ||
|
|
14866461c5 | ||
|
|
a4a15ad243 |
@@ -11,17 +11,23 @@
|
||||
"slug": "latest",
|
||||
"upcoming": true
|
||||
},
|
||||
{
|
||||
"name": "3.5",
|
||||
"branchName": "3.5.x",
|
||||
"slug": "3.5",
|
||||
"upcoming": true
|
||||
},
|
||||
{
|
||||
"name": "3.4",
|
||||
"branchName": "3.4.x",
|
||||
"slug": "3.4",
|
||||
"upcoming": true
|
||||
"current": true
|
||||
},
|
||||
{
|
||||
"name": "3.3",
|
||||
"branchName": "3.3.x",
|
||||
"slug": "3.3",
|
||||
"current": true
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "3.2",
|
||||
|
||||
2
.github/workflows/coding-standards.yml
vendored
2
.github/workflows/coding-standards.yml
vendored
@@ -24,4 +24,4 @@ on:
|
||||
|
||||
jobs:
|
||||
coding-standards:
|
||||
uses: "doctrine/.github/.github/workflows/coding-standards.yml@7.1.0"
|
||||
uses: "doctrine/.github/.github/workflows/coding-standards.yml@7.3.0"
|
||||
|
||||
16
.github/workflows/continuous-integration.yml
vendored
16
.github/workflows/continuous-integration.yml
vendored
@@ -9,7 +9,6 @@ on:
|
||||
- ci/**
|
||||
- composer.*
|
||||
- src/**
|
||||
- phpunit.xml.dist
|
||||
- tests/**
|
||||
push:
|
||||
branches:
|
||||
@@ -19,7 +18,6 @@ on:
|
||||
- ci/**
|
||||
- composer.*
|
||||
- src/**
|
||||
- phpunit.xml.dist
|
||||
- tests/**
|
||||
|
||||
env:
|
||||
@@ -45,17 +43,27 @@ jobs:
|
||||
- "pdo_sqlite"
|
||||
deps:
|
||||
- "highest"
|
||||
native_lazy:
|
||||
- "0"
|
||||
include:
|
||||
- php-version: "8.2"
|
||||
dbal-version: "4@dev"
|
||||
extension: "pdo_sqlite"
|
||||
native_lazy: "0"
|
||||
- php-version: "8.2"
|
||||
dbal-version: "4@dev"
|
||||
extension: "sqlite3"
|
||||
native_lazy: "0"
|
||||
- php-version: "8.1"
|
||||
dbal-version: "default"
|
||||
deps: "lowest"
|
||||
extension: "pdo_sqlite"
|
||||
native_lazy: "0"
|
||||
- php-version: "8.4"
|
||||
dbal-version: "default"
|
||||
deps: "highest"
|
||||
extension: "pdo_sqlite"
|
||||
native_lazy: "1"
|
||||
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
@@ -85,16 +93,18 @@ jobs:
|
||||
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage-no-cache.xml"
|
||||
env:
|
||||
ENABLE_SECOND_LEVEL_CACHE: 0
|
||||
ENABLE_NATIVE_LAZY_OBJECTS: ${{ matrix.native_lazy }}
|
||||
|
||||
- name: "Run PHPUnit with Second Level Cache"
|
||||
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-cache.xml"
|
||||
env:
|
||||
ENABLE_SECOND_LEVEL_CACHE: 1
|
||||
ENABLE_NATIVE_LAZY_OBJECTS: ${{ matrix.native_lazy }}
|
||||
|
||||
- name: "Upload coverage file"
|
||||
uses: "actions/upload-artifact@v4"
|
||||
with:
|
||||
name: "phpunit-${{ matrix.extension }}-${{ matrix.php-version }}-${{ matrix.dbal-version }}-${{ matrix.deps }}-coverage"
|
||||
name: "phpunit-${{ matrix.extension }}-${{ matrix.php-version }}-${{ matrix.dbal-version }}-${{ matrix.deps }}-${{ matrix.native_lazy }}-coverage"
|
||||
path: "coverage*.xml"
|
||||
|
||||
|
||||
|
||||
2
.github/workflows/documentation.yml
vendored
2
.github/workflows/documentation.yml
vendored
@@ -17,4 +17,4 @@ on:
|
||||
jobs:
|
||||
documentation:
|
||||
name: "Documentation"
|
||||
uses: "doctrine/.github/.github/workflows/documentation.yml@7.1.0"
|
||||
uses: "doctrine/.github/.github/workflows/documentation.yml@7.3.0"
|
||||
|
||||
@@ -7,7 +7,7 @@ on:
|
||||
|
||||
jobs:
|
||||
release:
|
||||
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@7.1.0"
|
||||
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@7.3.0"
|
||||
secrets:
|
||||
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
|
||||
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
|
||||
|
||||
14
README.md
14
README.md
@@ -1,7 +1,7 @@
|
||||
| [4.0.x][4.0] | [3.4.x][3.4] | [3.3.x][3.3] | [2.21.x][2.21] | [2.20.x][2.20] |
|
||||
| [4.0.x][4.0] | [3.5.x][3.5] | [3.4.x][3.4] | [2.21.x][2.21] | [2.20.x][2.20] |
|
||||
|:------------------------------------------------------:|:------------------------------------------------------:|:------------------------------------------------------:|:--------------------------------------------------------:|:--------------------------------------------------------:|
|
||||
| [![Build status][4.0 image]][4.0] | [![Build status][3.4 image]][3.4] | [![Build status][3.3 image]][3.3] | [![Build status][2.21 image]][2.21] | [![Build status][2.20 image]][2.20] |
|
||||
| [![Coverage Status][4.0 coverage image]][4.0 coverage] | [![Coverage Status][3.4 coverage image]][3.4 coverage] | [![Coverage Status][3.3 coverage image]][3.3 coverage] | [![Coverage Status][2.21 coverage image]][2.21 coverage] | [![Coverage Status][2.20 coverage image]][2.20 coverage] |
|
||||
| [![Build status][4.0 image]][4.0] | [![Build status][3.5 image]][3.5] | [![Build status][3.4 image]][3.4] | [![Build status][2.21 image]][2.21] | [![Build status][2.20 image]][2.20] |
|
||||
| [![Coverage Status][4.0 coverage image]][4.0 coverage] | [![Coverage Status][3.5 coverage image]][3.5 coverage] | [![Coverage Status][3.4 coverage image]][3.4 coverage] | [![Coverage Status][2.21 coverage image]][2.21 coverage] | [![Coverage Status][2.20 coverage image]][2.20 coverage] |
|
||||
|
||||
Doctrine ORM is an object-relational mapper for PHP 8.1+ that provides transparent persistence
|
||||
for PHP objects. It sits on top of a powerful database abstraction layer (DBAL). One of its key features
|
||||
@@ -20,14 +20,14 @@ without requiring unnecessary code duplication.
|
||||
[4.0]: https://github.com/doctrine/orm/tree/4.0.x
|
||||
[4.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/4.0.x/graph/badge.svg
|
||||
[4.0 coverage]: https://codecov.io/gh/doctrine/orm/branch/4.0.x
|
||||
[3.5 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.5.x
|
||||
[3.5]: https://github.com/doctrine/orm/tree/3.5.x
|
||||
[3.5 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.5.x/graph/badge.svg
|
||||
[3.5 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.5.x
|
||||
[3.4 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.4.x
|
||||
[3.4]: https://github.com/doctrine/orm/tree/3.4.x
|
||||
[3.4 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.4.x/graph/badge.svg
|
||||
[3.4 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.4.x
|
||||
[3.3 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.3.x
|
||||
[3.3]: https://github.com/doctrine/orm/tree/3.3.x
|
||||
[3.3 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.3.x/graph/badge.svg
|
||||
[3.3 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.3.x
|
||||
[2.21 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.21.x
|
||||
[2.21]: https://github.com/doctrine/orm/tree/2.21.x
|
||||
[2.21 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.21.x/graph/badge.svg
|
||||
|
||||
52
UPGRADE.md
52
UPGRADE.md
@@ -1,8 +1,28 @@
|
||||
# Upgrade to 3.4.1
|
||||
|
||||
## BC BREAK: You can no longer use the `.*` notation to get all fields of an entity in a DTO
|
||||
|
||||
This feature was introduced in 3.4.0, and introduces several issues, so we
|
||||
decide to remove it before it is used too widely.
|
||||
|
||||
# Upgrade to 3.4
|
||||
|
||||
## Discriminator Map class duplicates
|
||||
|
||||
Using the same class several times in a discriminator map is deprecated.
|
||||
In 4.0, this will be an error.
|
||||
|
||||
## `Doctrine\ORM\Mapping\ClassMetadata::$reflFields` deprecated
|
||||
|
||||
To better support property hooks and lazy proxies in the future, `$reflFields` had to
|
||||
be deprecated because we cannot use the PHP internal reflection API directly anymore.
|
||||
|
||||
The property was changed from an array to an object of type `LegacyReflectionFields`
|
||||
that implements `ArrayAccess`.
|
||||
|
||||
Use the new `Doctrine\ORM\Mapping\PropertyAccessors\PropertyAccessor` API and access
|
||||
through `Doctrine\ORM\Mapping\ClassMetadata::$propertyAccessors` instead.
|
||||
|
||||
# Upgrade to 3.3
|
||||
|
||||
## Deprecate `DatabaseDriver`
|
||||
@@ -13,7 +33,7 @@ The class `Doctrine\ORM\Mapping\Driver\DatabaseDriver` is deprecated without rep
|
||||
|
||||
Output walkers should implement the new `\Doctrine\ORM\Query\OutputWalker` interface and create
|
||||
`Doctrine\ORM\Query\Exec\SqlFinalizer` instances instead of `Doctrine\ORM\Query\Exec\AbstractSqlExecutor`s.
|
||||
The output walker must not base its workings on the query `firstResult`/`maxResult` values, so that the
|
||||
The output walker must not base its workings on the query `firstResult`/`maxResult` values, so that the
|
||||
`SqlFinalizer` can be kept in the query cache and used regardless of the actual `firstResult`/`maxResult` values.
|
||||
Any operation dependent on `firstResult`/`maxResult` should take place within the `SqlFinalizer::createExecutor()`
|
||||
method. Details can be found at https://github.com/doctrine/orm/pull/11188.
|
||||
@@ -124,6 +144,36 @@ WARNING: This was relaxed in ORM 3.2 when partial was re-allowed for array-hydra
|
||||
`Doctrine\ORM\Query::HINT_FORCE_PARTIAL_LOAD` are removed.
|
||||
- `Doctrine\ORM\EntityManager*::getPartialReference()` is removed.
|
||||
|
||||
## BC BREAK: Enforce ArrayCollection Type on `\Doctrine\ORM\QueryBuilder::setParameters(ArrayCollection $parameters)`
|
||||
|
||||
The argument $parameters can no longer be a key=>value array. Only ArrayCollection types are allowed.
|
||||
|
||||
### Before
|
||||
|
||||
```php
|
||||
$qb = $em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('User', 'u')
|
||||
->where('u.id = :user_id1 OR u.id = :user_id2')
|
||||
->setParameters(array(
|
||||
'user_id1' => 1,
|
||||
'user_id2' => 2
|
||||
));
|
||||
```
|
||||
|
||||
### After
|
||||
|
||||
```php
|
||||
$qb = $em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('User', 'u')
|
||||
->where('u.id = :user_id1 OR u.id = :user_id2')
|
||||
->setParameters(new ArrayCollection(array(
|
||||
new Parameter('user_id1', 1),
|
||||
new Parameter('user_id2', 2)
|
||||
)));
|
||||
```
|
||||
|
||||
## BC BREAK: `Doctrine\ORM\Persister\Entity\EntityPersister::executeInserts()` return type changed to `void`
|
||||
|
||||
Implementors should adapt to the new signature, and should call
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||
displayDetailsOnTestsThatTriggerNotices="true"
|
||||
displayDetailsOnTestsThatTriggerWarnings="true"
|
||||
failOnNotice="true"
|
||||
failOnWarning="true"
|
||||
failOnRisky="true"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
>
|
||||
@@ -19,6 +24,7 @@
|
||||
|
||||
<!-- necessary change for some CLI/console output test assertions -->
|
||||
<env name="COLUMNS" value="120"/>
|
||||
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
@@ -27,7 +33,7 @@
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source>
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<include>
|
||||
<directory suffix=".php">../../../src</directory>
|
||||
</include>
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||
displayDetailsOnTestsThatTriggerNotices="true"
|
||||
displayDetailsOnTestsThatTriggerWarnings="true"
|
||||
failOnNotice="true"
|
||||
failOnWarning="true"
|
||||
failOnRisky="true"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
>
|
||||
@@ -19,6 +24,7 @@
|
||||
|
||||
<!-- necessary change for some CLI/console output test assertions -->
|
||||
<env name="COLUMNS" value="120"/>
|
||||
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
@@ -27,7 +33,7 @@
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source>
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<include>
|
||||
<directory suffix=".php">../../../src</directory>
|
||||
</include>
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||
displayDetailsOnTestsThatTriggerNotices="true"
|
||||
displayDetailsOnTestsThatTriggerWarnings="true"
|
||||
failOnNotice="true"
|
||||
failOnWarning="true"
|
||||
failOnRisky="true"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
>
|
||||
@@ -16,6 +21,7 @@
|
||||
|
||||
<!-- necessary change for some CLI/console output test assertions -->
|
||||
<env name="COLUMNS" value="120"/>
|
||||
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
@@ -24,7 +30,7 @@
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source>
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<include>
|
||||
<directory suffix=".php">../../../src</directory>
|
||||
</include>
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||
displayDetailsOnTestsThatTriggerNotices="true"
|
||||
displayDetailsOnTestsThatTriggerWarnings="true"
|
||||
failOnNotice="true"
|
||||
failOnWarning="true"
|
||||
failOnRisky="true"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
>
|
||||
@@ -14,6 +19,7 @@
|
||||
|
||||
<!-- necessary change for some CLI/console output test assertions -->
|
||||
<env name="COLUMNS" value="120"/>
|
||||
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
@@ -22,7 +28,7 @@
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source>
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<include>
|
||||
<directory suffix=".php">../../../src</directory>
|
||||
</include>
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||
displayDetailsOnTestsThatTriggerNotices="true"
|
||||
displayDetailsOnTestsThatTriggerWarnings="true"
|
||||
failOnNotice="true"
|
||||
failOnWarning="true"
|
||||
failOnRisky="true"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
>
|
||||
@@ -16,6 +21,7 @@
|
||||
|
||||
<!-- necessary change for some CLI/console output test assertions -->
|
||||
<env name="COLUMNS" value="120"/>
|
||||
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
@@ -24,7 +30,7 @@
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source>
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<include>
|
||||
<directory suffix=".php">../../../src</directory>
|
||||
</include>
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||
displayDetailsOnTestsThatTriggerNotices="true"
|
||||
displayDetailsOnTestsThatTriggerWarnings="true"
|
||||
failOnNotice="true"
|
||||
failOnWarning="true"
|
||||
failOnRisky="true"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
>
|
||||
@@ -14,6 +19,7 @@
|
||||
|
||||
<!-- necessary change for some CLI/console output test assertions -->
|
||||
<env name="COLUMNS" value="120"/>
|
||||
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
@@ -22,7 +28,7 @@
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source>
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<include>
|
||||
<directory suffix=".php">../../../src</directory>
|
||||
</include>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"symfony/var-exporter": "^6.3.9 || ^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "^12.0",
|
||||
"doctrine/coding-standard": "^13.0",
|
||||
"phpbench/phpbench": "^1.0",
|
||||
"phpdocumentor/guides-cli": "^1.4",
|
||||
"phpstan/extension-installer": "^1.4",
|
||||
@@ -45,7 +45,7 @@
|
||||
"phpstan/phpstan-deprecation-rules": "^2",
|
||||
"phpunit/phpunit": "^10.4.0",
|
||||
"psr/log": "^1 || ^2 || ^3",
|
||||
"squizlabs/php_codesniffer": "3.7.2",
|
||||
"squizlabs/php_codesniffer": "3.12.0",
|
||||
"symfony/cache": "^5.4 || ^6.2 || ^7.0"
|
||||
},
|
||||
"suggest": {
|
||||
|
||||
3
docs/.gitignore
vendored
Normal file
3
docs/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
composer.lock
|
||||
vendor/
|
||||
build/
|
||||
24
docs/Makefile
Normal file
24
docs/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
# Makefile for Doctrine ORM documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
DOCOPTS =
|
||||
BUILD = vendor/bin/guides
|
||||
BUILDDIR = build
|
||||
|
||||
# Internal variables.
|
||||
ALLGUIDESOPTS = $(DOCOPTS) en/
|
||||
|
||||
.PHONY: help clean html
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
|
||||
clean:
|
||||
-rm -rf ./$(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(BUILD) $(ALLGUIDESOPTS) --output=$(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
@@ -1,18 +1,22 @@
|
||||
# Doctrine ORM Documentation
|
||||
|
||||
The documentation is written in [ReStructured Text](https://docutils.sourceforge.io/rst.html).
|
||||
|
||||
## How to Generate:
|
||||
Using Ubuntu 14.04 LTS:
|
||||
|
||||
1. Run ./bin/install-dependencies.sh
|
||||
2. Run ./bin/generate-docs.sh
|
||||
In the `docs/` folder, run
|
||||
|
||||
It will generate the documentation into the build directory of the checkout.
|
||||
composer update
|
||||
|
||||
Then compile the documentation with:
|
||||
|
||||
## Theme issues
|
||||
make html
|
||||
|
||||
If you get a "Theme error", check if the `en/_theme` subdirectory is empty,
|
||||
in which case you will need to run:
|
||||
This will generate the documentation into the `build` subdirectory.
|
||||
|
||||
1. git submodule init
|
||||
2. git submodule update
|
||||
To browse the documentation, you need to run a webserver:
|
||||
|
||||
cd build/html
|
||||
php -S localhost:8000
|
||||
|
||||
Now the documentation is available at [http://localhost:8000](http://localhost:8000).
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
EXECPATH=`dirname $0`
|
||||
cd $EXECPATH
|
||||
cd ..
|
||||
|
||||
rm build -Rf
|
||||
sphinx-build en build
|
||||
|
||||
sphinx-build -b latex en build/pdf
|
||||
rubber --into build/pdf --pdf build/pdf/Doctrine2ORM.tex
|
||||
@@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
sudo apt-get update && sudo apt-get install -y python2.7 python-sphinx python-pygments
|
||||
10
docs/composer.json
Normal file
10
docs/composer.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "doctrine/orm-docs",
|
||||
"description": "Documentation for the Object-Relational Mapper\"",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"phpdocumentor/guides-cli": "1.7.1",
|
||||
"phpdocumentor/filesystem": "1.7.1"
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
-rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Doctrine2ORM.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Doctrine2ORM.qhc"
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
|
||||
"run these through (pdf)latex."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
44
docs/en/cookbook/generated-columns.rst
Normal file
44
docs/en/cookbook/generated-columns.rst
Normal file
@@ -0,0 +1,44 @@
|
||||
Generated Columns
|
||||
=================
|
||||
|
||||
Generated columns, sometimes also called virtual columns, are populated by
|
||||
the database engine itself. They are a tool for performance optimization, to
|
||||
avoid calculating a value on each query.
|
||||
|
||||
You can define generated columns on entities and have Doctrine map the values
|
||||
to your entity.
|
||||
|
||||
Declaring a generated column
|
||||
----------------------------
|
||||
|
||||
There is no explicit mapping instruction for generated columns. Instead, you
|
||||
specify that the column should not be written to, and define a custom column
|
||||
definition.
|
||||
|
||||
.. literalinclude:: generated-columns/Person.php
|
||||
:language: php
|
||||
|
||||
* ``insertable``, ``updatable``: Setting these to false tells Doctrine to never
|
||||
write this column - writing to a generated column would result in an error
|
||||
from the database.
|
||||
* ``columnDefinition``: We specify the full DDL to create the column. To allow
|
||||
to use database specific features, this attribute does not use Doctrine Query
|
||||
Language but native SQL. Note that you need to reference columns by their
|
||||
database name (either explicitly set in the mapping or per the current
|
||||
:doc:`naming strategy <../reference/namingstrategy>`).
|
||||
Be aware that specifying a column definition makes the ``SchemaTool``
|
||||
completely ignore all other configuration for this column. See also
|
||||
:ref:`#[Column] <attrref_column>`
|
||||
* ``generated``: Specifying that this column is always generated tells Doctrine
|
||||
to update the field on the entity with the value from the database after
|
||||
every write operation.
|
||||
|
||||
Advanced example: Extracting a value from a JSON structure
|
||||
----------------------------------------------------------
|
||||
|
||||
Lets assume we have an entity that stores a blogpost as structured JSON.
|
||||
To avoid extracting all titles on the fly when listing the posts, we create a
|
||||
generated column with the field.
|
||||
|
||||
.. literalinclude:: generated-columns/Article.php
|
||||
:language: php
|
||||
33
docs/en/cookbook/generated-columns/Article.php
Normal file
33
docs/en/cookbook/generated-columns/Article.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity]
|
||||
class Article
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private int $id;
|
||||
|
||||
/**
|
||||
* When working with Postgres, it is recommended to use the jsonb
|
||||
* format for better performance.
|
||||
*/
|
||||
#[ORM\Column(options: ['jsonb' => true])]
|
||||
private array $content;
|
||||
|
||||
/**
|
||||
* Because we specify NOT NULL, inserting will fail if the content does
|
||||
* not have a string in the title field.
|
||||
*/
|
||||
#[ORM\Column(
|
||||
insertable: false,
|
||||
updatable: false,
|
||||
columnDefinition: "VARCHAR(255) generated always as (content->>'title') stored NOT NULL",
|
||||
generated: 'ALWAYS',
|
||||
)]
|
||||
private string $title;
|
||||
}
|
||||
24
docs/en/cookbook/generated-columns/Person.php
Normal file
24
docs/en/cookbook/generated-columns/Person.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity]
|
||||
class Person
|
||||
{
|
||||
#[ORM\Column(type: 'string')]
|
||||
private string $firstName;
|
||||
|
||||
#[ORM\Column(type: 'string', name: 'name')]
|
||||
private string $lastName;
|
||||
|
||||
#[ORM\Column(
|
||||
type: 'string',
|
||||
insertable: false,
|
||||
updatable: false,
|
||||
columnDefinition: "VARCHAR(255) GENERATED ALWAYS AS (concat(firstName, ' ', name) stored NOT NULL",
|
||||
generated: 'ALWAYS',
|
||||
)]
|
||||
private string $fullName;
|
||||
}
|
||||
@@ -102,6 +102,7 @@ Cookbook
|
||||
|
||||
* **Patterns**:
|
||||
:doc:`Aggregate Fields <cookbook/aggregate-fields>` \|
|
||||
:doc:`Generated/Virtual Columns <cookbook/generated-columns>` \|
|
||||
:doc:`Decorator Pattern <cookbook/decorator-pattern>` \|
|
||||
:doc:`Strategy Pattern <cookbook/strategy-cookbook-introduction>`
|
||||
|
||||
@@ -121,4 +122,5 @@ Cookbook
|
||||
|
||||
* **Custom Datatypes**
|
||||
:doc:`MySQL Enums <cookbook/mysql-enums>`
|
||||
:doc:`Custom Mapping Types <cookbook/custom-mapping-types>`
|
||||
:doc:`Advanced Field Value Conversion <cookbook/advanced-field-value-conversion-using-custom-mapping-types>`
|
||||
|
||||
@@ -19,7 +19,7 @@ steps of configuration.
|
||||
|
||||
// ...
|
||||
|
||||
if ($applicationMode == "development") {
|
||||
if ($applicationMode === "development") {
|
||||
$queryCache = new ArrayAdapter();
|
||||
$metadataCache = new ArrayAdapter();
|
||||
} else {
|
||||
@@ -32,13 +32,18 @@ steps of configuration.
|
||||
$driverImpl = new AttributeDriver(['/path/to/lib/MyProject/Entities'], true);
|
||||
$config->setMetadataDriverImpl($driverImpl);
|
||||
$config->setQueryCache($queryCache);
|
||||
$config->setProxyDir('/path/to/myproject/lib/MyProject/Proxies');
|
||||
$config->setProxyNamespace('MyProject\Proxies');
|
||||
|
||||
if ($applicationMode == "development") {
|
||||
$config->setAutoGenerateProxyClasses(true);
|
||||
if (PHP_VERSION_ID > 80400) {
|
||||
$config->enableNativeLazyObjects(true);
|
||||
} else {
|
||||
$config->setAutoGenerateProxyClasses(false);
|
||||
$config->setProxyDir('/path/to/myproject/lib/MyProject/Proxies');
|
||||
$config->setProxyNamespace('MyProject\Proxies');
|
||||
|
||||
if ($applicationMode === "development") {
|
||||
$config->setAutoGenerateProxyClasses(true);
|
||||
} else {
|
||||
$config->setAutoGenerateProxyClasses(false);
|
||||
}
|
||||
}
|
||||
|
||||
$connection = DriverManager::getConnection([
|
||||
@@ -71,8 +76,25 @@ Configuration Options
|
||||
The following sections describe all the configuration options
|
||||
available on a ``Doctrine\ORM\Configuration`` instance.
|
||||
|
||||
Proxy Directory (***REQUIRED***)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Native Lazy Objects (**OPTIONAL**)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
With PHP 8.4 we recommend that you use native lazy objects instead of
|
||||
the code generation approach using the ``symfony/var-exporter`` Ghost trait.
|
||||
|
||||
With Doctrine 4, the minimal requirement will become PHP 8.4 and native lazy objects
|
||||
will become the only approach to lazy loading.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
$config->enableNativeLazyObjects(true);
|
||||
|
||||
Proxy Directory
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Required except if you use native lazy objects with PHP 8.4.
|
||||
This setting will be removed in the future.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
@@ -85,8 +107,11 @@ classes. For a detailed explanation on proxy classes and how they
|
||||
are used in Doctrine, refer to the "Proxy Objects" section further
|
||||
down.
|
||||
|
||||
Proxy Namespace (***REQUIRED***)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Proxy Namespace
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Required except if you use native lazy objects with PHP 8.4.
|
||||
This setting will be removed in the future.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
@@ -98,8 +123,8 @@ Gets or sets the namespace to use for generated proxy classes. For
|
||||
a detailed explanation on proxy classes and how they are used in
|
||||
Doctrine, refer to the "Proxy Objects" section further down.
|
||||
|
||||
Metadata Driver (***REQUIRED***)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Metadata Driver (**REQUIRED**)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
@@ -139,8 +164,8 @@ accept either a single directory as a string or an array of
|
||||
directories. With this feature a single driver can support multiple
|
||||
directories of Entities.
|
||||
|
||||
Metadata Cache (***RECOMMENDED***)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Metadata Cache (**RECOMMENDED**)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
@@ -161,8 +186,8 @@ For development you should use an array cache like
|
||||
``Symfony\Component\Cache\Adapter\ArrayAdapter``
|
||||
which only caches data on a per-request basis.
|
||||
|
||||
Query Cache (***RECOMMENDED***)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Query Cache (**RECOMMENDED**)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
@@ -184,8 +209,8 @@ For development you should use an array cache like
|
||||
``Symfony\Component\Cache\Adapter\ArrayAdapter``
|
||||
which only caches data on a per-request basis.
|
||||
|
||||
SQL Logger (***Optional***)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
SQL Logger (**Optional**)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
@@ -197,8 +222,11 @@ Gets or sets the logger to use for logging all SQL statements
|
||||
executed by Doctrine. The logger class must implement the
|
||||
deprecated ``Doctrine\DBAL\Logging\SQLLogger`` interface.
|
||||
|
||||
Auto-generating Proxy Classes (***OPTIONAL***)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Auto-generating Proxy Classes (**OPTIONAL**)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This setting is not required if you use native lazy objects with PHP 8.4
|
||||
and will be removed in the future.
|
||||
|
||||
Proxy classes can either be generated manually through the Doctrine
|
||||
Console or automatically at runtime by Doctrine. The configuration
|
||||
@@ -441,7 +469,7 @@ correctly if sub-namespaces use different metadata driver
|
||||
implementations.
|
||||
|
||||
|
||||
Default Repository (***OPTIONAL***)
|
||||
Default Repository (**OPTIONAL**)
|
||||
-----------------------------------
|
||||
|
||||
Specifies the FQCN of a subclass of the EntityRepository.
|
||||
@@ -456,7 +484,7 @@ That will be available for all entities without a custom repository class.
|
||||
The default value is ``Doctrine\ORM\EntityRepository``.
|
||||
Any repository class must be a subclass of EntityRepository otherwise you got an ORMException
|
||||
|
||||
Ignoring entities (***OPTIONAL***)
|
||||
Ignoring entities (**OPTIONAL**)
|
||||
-----------------------------------
|
||||
|
||||
Specifies the Entity FQCNs to ignore.
|
||||
|
||||
@@ -903,8 +903,7 @@ defaults to "id", just as in one-to-one or many-to-one mappings.
|
||||
|
||||
Additionally, when using typed properties with Doctrine 2.9 or newer
|
||||
you can skip ``targetEntity`` in ``ManyToOne`` and ``OneToOne``
|
||||
associations as they will be set based on type. Also ``nullable``
|
||||
attribute on ``JoinColumn`` will be inherited from PHP type. So that:
|
||||
associations as they will be set based on type. So that:
|
||||
|
||||
.. configuration-block::
|
||||
|
||||
@@ -931,7 +930,7 @@ Is essentially the same as following:
|
||||
<?php
|
||||
/** One Product has One Shipment. */
|
||||
#[OneToOne(targetEntity: Shipment::class)]
|
||||
#[JoinColumn(name: 'shipment_id', referencedColumnName: 'id', nullable: false)]
|
||||
#[JoinColumn(name: 'shipment_id', referencedColumnName: 'id')]
|
||||
private Shipment $shipment;
|
||||
|
||||
.. code-block:: annotation
|
||||
@@ -940,7 +939,7 @@ Is essentially the same as following:
|
||||
/**
|
||||
* One Product has One Shipment.
|
||||
* @OneToOne(targetEntity="Shipment")
|
||||
* @JoinColumn(name="shipment_id", referencedColumnName="id", nullable=false)
|
||||
* @JoinColumn(name="shipment_id", referencedColumnName="id")
|
||||
*/
|
||||
private Shipment $shipment;
|
||||
|
||||
@@ -949,7 +948,7 @@ Is essentially the same as following:
|
||||
<doctrine-mapping>
|
||||
<entity class="Product">
|
||||
<one-to-one field="shipment" target-entity="Shipment">
|
||||
<join-column name="shipment_id" referenced-column-name="id" nulable=false />
|
||||
<join-column name="shipment_id" referenced-column-name="id" nullable=false />
|
||||
</one-to-one>
|
||||
</entity>
|
||||
</doctrine-mapping>
|
||||
|
||||
@@ -214,12 +214,15 @@ Optional parameters:
|
||||
- ``check``: Adds a check constraint type to the column (might not
|
||||
be supported by all vendors).
|
||||
|
||||
- **columnDefinition**: DDL SQL snippet that starts after the column
|
||||
- **columnDefinition**: Specify the DDL SQL snippet that starts after the column
|
||||
name and specifies the complete (non-portable!) column definition.
|
||||
This attribute allows to make use of advanced RMDBS features.
|
||||
However you should make careful use of this feature and the
|
||||
consequences. ``SchemaTool`` will not detect changes on the column correctly
|
||||
anymore if you use ``columnDefinition``.
|
||||
However, as this needs to be specified in the DDL native to the database,
|
||||
the resulting schema changes are no longer portable. If you specify a
|
||||
``columnDefinition``, the ``SchemaTool`` ignores all other attributes
|
||||
that are normally used to build the definition DDL. Changes to the
|
||||
``columnDefinition`` are not detected, you will need to manually create a
|
||||
migration to apply changes.
|
||||
|
||||
Additionally you should remember that the ``type``
|
||||
attribute still handles the conversion between PHP and Database
|
||||
@@ -262,10 +265,11 @@ Examples:
|
||||
)]
|
||||
protected $loginCount;
|
||||
|
||||
// MySQL example: full_name char(41) GENERATED ALWAYS AS (concat(firstname,' ',lastname)),
|
||||
// columnDefinition is raw SQL, not DQL. This example works for MySQL:
|
||||
#[Column(
|
||||
type: "string",
|
||||
name: "user_fullname",
|
||||
columnDefinition: "VARCHAR(255) GENERATED ALWAYS AS (concat(firstname,' ',lastname))",
|
||||
insertable: false,
|
||||
updatable: false
|
||||
)]
|
||||
@@ -366,7 +370,7 @@ Optional parameters:
|
||||
|
||||
- **type**: By default this is string.
|
||||
- **length**: By default this is 255.
|
||||
- **columnDefinition**: By default this is null the definition according to the type will be used. This option allows to override it.
|
||||
- **columnDefinition**: Allows to override how the column is generated. See the "columnDefinition" attribute on :ref:`#[Column] <attrref_column>`
|
||||
- **enumType**: By default this is `null`. Allows to map discriminatorColumn value to PHP enum
|
||||
- **options**: See "options" attribute on :ref:`#[Column] <attrref_column>`.
|
||||
|
||||
@@ -672,13 +676,16 @@ Optional parameters:
|
||||
- **unique**: Determines whether this relation is exclusive between the
|
||||
affected entities and should be enforced as such on the database
|
||||
constraint level. Defaults to false.
|
||||
- **deferrable**: Determines whether this relation constraint can be deferred. Defaults to false.
|
||||
- **nullable**: Determine whether the related entity is required, or if
|
||||
null is an allowed state for the relation. Defaults to true.
|
||||
- **onDelete**: Cascade Action (Database-level)
|
||||
- **columnDefinition**: DDL SQL snippet that starts after the column
|
||||
name and specifies the complete (non-portable!) column definition.
|
||||
This attribute enables the use of advanced RMDBS features. Using
|
||||
this attribute on ``#[JoinColumn]`` is necessary if you need slightly
|
||||
This attribute enables the use of advanced RMDBS features. Note that you
|
||||
need to reference columns by their database name (either explicitly set in
|
||||
the mapping or per the current :doc:`naming strategy <namingstrategy>`).
|
||||
Using this attribute on ``#[JoinColumn]`` is necessary if you need
|
||||
different column definitions for joining columns, for example
|
||||
regarding NULL/NOT NULL defaults. However by default a
|
||||
"columnDefinition" attribute on :ref:`#[Column] <attrref_column>` also sets
|
||||
@@ -1133,7 +1140,7 @@ Marker attribute that defines a specified column as version attribute used in
|
||||
an :ref:`optimistic locking <transactions-and-concurrency_optimistic-locking>`
|
||||
scenario. It only works on :ref:`#[Column] <attrref_column>` attributes that have
|
||||
the type ``integer`` or ``datetime``. Setting ``#[Version]`` on a property with
|
||||
:ref:`#[Id <attrref_id>` is not supported.
|
||||
:ref:`#[Id] <attrref_id>` is not supported.
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
@@ -214,6 +214,8 @@ These are the "automatic" mapping rules:
|
||||
| Any other type | ``Types::STRING`` |
|
||||
+-----------------------+-------------------------------+
|
||||
|
||||
.. versionadded:: 2.11
|
||||
|
||||
As of version 2.11 Doctrine can also automatically map typed properties using a
|
||||
PHP 8.1 enum to set the right ``type`` and ``enumType``.
|
||||
|
||||
@@ -224,6 +226,70 @@ and a custom ``Doctrine\ORM\Mapping\TypedFieldMapper`` implementation.
|
||||
|
||||
:doc:`Read more about TypedFieldMapper <typedfieldmapper>`.
|
||||
|
||||
Property Hooks
|
||||
--------------
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
Doctrine supports mapping hooked properties as long as they have a backed property
|
||||
and are not virtual.
|
||||
|
||||
|
||||
.. configuration-block::
|
||||
|
||||
.. code-block:: attribute
|
||||
|
||||
<?php
|
||||
use Doctrine\ORM\Mapping\Column;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
||||
#[Entity]
|
||||
class Message
|
||||
{
|
||||
#[Column(type: Types::INTEGER)]
|
||||
private $id;
|
||||
#[Column(type: Types::STRING)]
|
||||
public string $language = 'de' {
|
||||
// Override the "read" action with arbitrary logic.
|
||||
get => strtoupper($this->language);
|
||||
|
||||
// Override the "write" action with arbitrary logic.
|
||||
set {
|
||||
$this->language = strtolower($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.. code-block:: xml
|
||||
|
||||
<doctrine-mapping>
|
||||
<entity name="Message">
|
||||
<field name="id" type="integer" />
|
||||
<field name="language" />
|
||||
</entity>
|
||||
</doctrine-mapping>
|
||||
|
||||
If you attempt to map a virtual property with ``#[Column]`` an exception will be thrown.
|
||||
|
||||
Some caveats apply to the use of property hooks, as they behave differently when accessing the property through
|
||||
the entity or directly through DQL/EntityRepository. Because the property hook can modify the value of the property in a way
|
||||
that value and raw value are different, you have to use the raw value representation when querying for the property.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
$queryBuilder = $entityManager->createQueryBuilder();
|
||||
$queryBuilder->select('m')
|
||||
->from(Message::class, 'm')
|
||||
->where('m.language = :language')
|
||||
->setParameter('language', 'de'); // Use lower case here for raw value representation
|
||||
|
||||
$query = $queryBuilder->getQuery();
|
||||
$result = $query->getResult();
|
||||
|
||||
$messageRepository = $entityManager->getRepository(Message::class);
|
||||
$deMessages = $messageRepository->findBy(['language' => 'de']); // Use lower case here for raw value representation
|
||||
|
||||
.. _reference-mapping-types:
|
||||
|
||||
Doctrine Mapping Types
|
||||
|
||||
@@ -588,7 +588,7 @@ And then use the ``NEW`` DQL keyword :
|
||||
$query = $em->createQuery('SELECT NEW CustomerDTO(c.name, e.email, a.city, SUM(o.value)) FROM Customer c JOIN c.email e JOIN c.address a JOIN c.orders o GROUP BY c');
|
||||
$users = $query->getResult(); // array of CustomerDTO
|
||||
|
||||
You can also nest several DTO :
|
||||
You can also nest several DTO :
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
@@ -674,6 +674,16 @@ The ``NAMED`` keyword must precede all DTO you want to instantiate :
|
||||
If two arguments have the same name, a ``DuplicateFieldException`` is thrown.
|
||||
If a field cannot be matched with a property name, a ``NoMatchingPropertyException`` is thrown. This typically happens when using functions without aliasing them.
|
||||
|
||||
You can hydrate an entity nested in a DTO :
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
$query = $em->createQuery('SELECT NEW CustomerDTO(c.name, a AS address) FROM Customer c JOIN c.address a');
|
||||
$users = $query->getResult(); // array of CustomerDTO
|
||||
|
||||
// CustomerDTO => {name : 'DOE', email: null, address : {city: 'New York', zip: '10011', address: 'Abbey Road'}
|
||||
|
||||
Using INDEX BY
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
@@ -1697,12 +1707,13 @@ Select Expressions
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
SelectExpression ::= (IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression | NewObjectExpression) [["AS"] ["HIDDEN"] AliasResultVariable]
|
||||
SimpleSelectExpression ::= (StateFieldPathExpression | IdentificationVariable | FunctionDeclaration | AggregateExpression | "(" Subselect ")" | ScalarExpression) [["AS"] AliasResultVariable]
|
||||
PartialObjectExpression ::= "PARTIAL" IdentificationVariable "." PartialFieldSet
|
||||
PartialFieldSet ::= "{" SimpleStateField {"," SimpleStateField}* "}"
|
||||
NewObjectExpression ::= "NEW" AbstractSchemaName "(" NewObjectArg {"," NewObjectArg}* ")"
|
||||
NewObjectArg ::= (ScalarExpression | "(" Subselect ")" | NewObjectExpression) ["AS" AliasResultVariable]
|
||||
SelectExpression ::= (IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression | NewObjectExpression) [["AS"] ["HIDDEN"] AliasResultVariable]
|
||||
SimpleSelectExpression ::= (StateFieldPathExpression | IdentificationVariable | FunctionDeclaration | AggregateExpression | "(" Subselect ")" | ScalarExpression) [["AS"] AliasResultVariable]
|
||||
PartialObjectExpression ::= "PARTIAL" IdentificationVariable "." PartialFieldSet
|
||||
PartialFieldSet ::= "{" SimpleStateField {"," SimpleStateField}* "}"
|
||||
NewObjectExpression ::= "NEW" AbstractSchemaName "(" NewObjectArg {"," NewObjectArg}* ")"
|
||||
NewObjectArg ::= (ScalarExpression | "(" Subselect ")" | NewObjectExpression | EntityAsDtoArgumentExpression) ["AS" AliasResultVariable]
|
||||
EntityAsDtoArgumentExpression ::= IdentificationVariable
|
||||
|
||||
Conditional Expressions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -265,7 +265,7 @@ specific to a particular entity class's lifecycle.
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
<entity name="User">
|
||||
|
||||
@@ -16,7 +16,7 @@ is common to multiple entity classes.
|
||||
Mapped superclasses, just as regular, non-mapped classes, can
|
||||
appear in the middle of an otherwise mapped inheritance hierarchy
|
||||
(through Single Table Inheritance or Class Table Inheritance). They
|
||||
are not query-able, and need not have an ``#[Id]`` property.
|
||||
are not query-able, and do not require an ``#[Id]`` property.
|
||||
|
||||
No database table will be created for a mapped superclass itself,
|
||||
only for entity classes inheriting from it. That implies that a
|
||||
|
||||
@@ -299,7 +299,7 @@ level cache region.
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
<entity name="Country">
|
||||
@@ -351,7 +351,7 @@ It caches the primary keys of association and cache each element will be cached
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
<entity name="State">
|
||||
|
||||
@@ -736,6 +736,35 @@ methods:
|
||||
|
||||
.. note::
|
||||
|
||||
There is a limitation on the compatibility of Criteria comparisons.
|
||||
You have to use scalar values only as the value in a comparison or
|
||||
the behaviour between different backends is not the same.
|
||||
Depending on whether the collection has already been loaded from the
|
||||
database or not, criteria matching may happen at the database/SQL level
|
||||
or on objects in memory. This may lead to different results and come
|
||||
surprising, for example when a code change in one place leads to a collection
|
||||
becoming initialized and, as a side effect, returning a different result
|
||||
or even breaking a ``matching()`` call somewhere else. Also, collection
|
||||
initialization state in practical use cases may differ from the one covered
|
||||
in unit tests.
|
||||
|
||||
Database level comparisons are based on scalar representations of the values
|
||||
stored in entity properties. The field names passed to expressions correspond
|
||||
to property names. Comparison and sorting may be affected by
|
||||
database-specific behavior. For example, MySQL enum types sort by index position,
|
||||
not lexicographically by value.
|
||||
|
||||
In-memory handling is based on the ``Selectable`` API of `Doctrine Collections <https://www.doctrine-project.org/projects/doctrine-collections/en/stable/index.html#matching>`.
|
||||
In this case, field names passed to expressions are being used to derive accessor
|
||||
method names. Strict type comparisons are used for equal and not-equal checks,
|
||||
and generally PHP language rules are being used for other comparison operators
|
||||
or sorting.
|
||||
|
||||
As a general guidance, for consistent results use the Criteria API with scalar
|
||||
values only. Note that ``DateTime`` and ``DateTimeImmutable`` are two predominant
|
||||
examples of value objects that are *not* scalars.
|
||||
|
||||
Refrain from using special database-level column types or custom Doctrine Types
|
||||
that may lead to database-specific comparison or sorting rules being applied, or
|
||||
to database-level values being different from object field values.
|
||||
|
||||
Provide accessor methods for all entity fields used in criteria expressions,
|
||||
and implement those methods in a way that their return value is the
|
||||
same as the database-level value.
|
||||
|
||||
@@ -166,7 +166,7 @@ your code. See the following code:
|
||||
|
||||
Traversing the object graph for parts that are lazy-loaded will
|
||||
easily trigger lots of SQL queries and will perform badly if used
|
||||
to heavily. Make sure to use DQL to fetch-join all the parts of the
|
||||
too heavily. Make sure to use DQL to fetch-join all the parts of the
|
||||
object-graph that you need as efficiently as possible.
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ setup for the latest code in trunk.
|
||||
.. code-block:: xml
|
||||
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
@@ -46,7 +46,7 @@ In order to work, this requires certain conventions:
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
$driver->setFileExtension('.xml');
|
||||
$driver->getLocator()->setFileExtension('.xml');
|
||||
|
||||
It is recommended to put all XML mapping documents in a single
|
||||
folder but you can spread the documents over several folders if you
|
||||
@@ -104,7 +104,7 @@ of several common elements:
|
||||
// Doctrine.Tests.ORM.Mapping.User.dcm.xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
@@ -770,7 +770,7 @@ entity relationship. You can define this in XML with the "association-key" attri
|
||||
.. code-block:: xml
|
||||
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
cookbook/decorator-pattern
|
||||
cookbook/dql-custom-walkers
|
||||
cookbook/dql-user-defined-functions
|
||||
cookbook/generated-columns
|
||||
cookbook/implementing-arrayaccess-for-domain-objects
|
||||
cookbook/resolve-target-entity-listener
|
||||
cookbook/sql-table-prefixes
|
||||
|
||||
@@ -54,7 +54,7 @@ and year of production as primary keys:
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
@@ -85,11 +85,12 @@ And for querying you can use arrays to both DQL and EntityRepositories:
|
||||
namespace VehicleCatalogue\Model;
|
||||
|
||||
// $em is the EntityManager
|
||||
$audi = $em->find("VehicleCatalogue\Model\Car", array("name" => "Audi A8", "year" => 2010));
|
||||
$audi = $em->find("VehicleCatalogue\Model\Car", ["name" => "Audi A8", "year" => 2010]);
|
||||
|
||||
$dql = "SELECT c FROM VehicleCatalogue\Model\Car c WHERE c.id = ?1";
|
||||
$dql = "SELECT c FROM VehicleCatalogue\Model\Car c WHERE c.name = ?1 AND c.year = ?2";
|
||||
$audi = $em->createQuery($dql)
|
||||
->setParameter(1, ["name" => "Audi A8", "year" => 2010])
|
||||
->setParameter(1, "Audi A8")
|
||||
->setParameter(2, 2010)
|
||||
->getSingleResult();
|
||||
|
||||
You can also use this entity in associations. Doctrine will then generate two foreign keys one for ``name``
|
||||
@@ -174,7 +175,7 @@ We keep up the example of an Article with arbitrary attributes, the mapping look
|
||||
.. code-block:: xml
|
||||
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
@@ -249,7 +250,7 @@ of products purchased and maybe even the current price.
|
||||
|
||||
public function __construct(
|
||||
#[ManyToOne(targetEntity: Customer::class)]
|
||||
private Customer $customer,
|
||||
private Customer $customer
|
||||
) {
|
||||
$this->items = new ArrayCollection();
|
||||
$this->created = new DateTime("now");
|
||||
@@ -294,6 +295,7 @@ of products purchased and maybe even the current price.
|
||||
$this->order = $order;
|
||||
$this->product = $product;
|
||||
$this->offeredPrice = $product->getCurrentPrice();
|
||||
$this->amount = $amount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ switch to extra lazy as shown in these examples:
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
|
||||
@@ -514,7 +514,7 @@ methods, but you only need to choose one.
|
||||
|
||||
<!-- config/xml/Product.dcm.xml -->
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
@@ -1023,7 +1023,7 @@ the ``Product`` before:
|
||||
|
||||
<!-- config/xml/Bug.dcm.xml -->
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
@@ -1103,7 +1103,7 @@ Finally, we'll add metadata mappings for the ``User`` entity.
|
||||
|
||||
<!-- config/xml/User.dcm.xml -->
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
@@ -1586,7 +1586,7 @@ we have to adjust the metadata slightly.
|
||||
.. code-block:: xml
|
||||
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ here are the code and mappings for it:
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
|
||||
@@ -583,7 +583,7 @@ parameters:
|
||||
path: src/EntityManager.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\EntityManager\:\:getReference\(\) should return \(T of object\)\|null but returns Doctrine\\ORM\\Proxy\\InternalProxy\.$#'
|
||||
message: '#^Method Doctrine\\ORM\\EntityManager\:\:getReference\(\) should return \(T of object\)\|null but returns object\.$#'
|
||||
identifier: return.type
|
||||
count: 1
|
||||
path: src/EntityManager.php
|
||||
@@ -984,12 +984,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Mapping/ClassMetadata.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$class of method Doctrine\\Persistence\\Mapping\\ReflectionService\:\:getAccessibleProperty\(\) expects class\-string, string given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Mapping/ClassMetadata.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$mapping of method Doctrine\\ORM\\Mapping\\ClassMetadata\<T of object\>\:\:validateAndCompleteTypedAssociationMapping\(\) expects array\{type\: 1\|2\|4\|8, fieldName\: string, targetEntity\?\: class\-string\}, non\-empty\-array\<string, mixed\> given\.$#'
|
||||
identifier: argument.type
|
||||
@@ -1032,18 +1026,6 @@ parameters:
|
||||
count: 2
|
||||
path: src/Mapping/ClassMetadata.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$class of method Doctrine\\ORM\\Mapping\\ClassMetadata\<T of object\>\:\:getAccessibleProperty\(\) expects class\-string, string given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Mapping/ClassMetadata.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#3 \$embeddedClass of class Doctrine\\ORM\\Mapping\\ReflectionEmbeddedProperty constructor expects class\-string, string given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Mapping/ClassMetadata.php
|
||||
|
||||
-
|
||||
message: '#^Property Doctrine\\ORM\\Mapping\\ClassMetadata\:\:\$customRepositoryClassName with generic class Doctrine\\ORM\\EntityRepository does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
@@ -1350,12 +1332,72 @@ parameters:
|
||||
count: 1
|
||||
path: src/Mapping/Driver/AttributeDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencedColumnNames\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencedTableName\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencingColumnNames\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\Index\:\:getIndexedColumns\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\Table\:\:getPrimaryKeyConstraint\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to method getColumnName\(\) on an unknown class Doctrine\\DBAL\\Schema\\Index\\IndexedColumn\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to method getColumnNames\(\) on an unknown class Doctrine\\DBAL\\Schema\\PrimaryKeyConstraint\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Call to method toString\(\) on an unknown class Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\.$#'
|
||||
identifier: class.notFound
|
||||
count: 5
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Cannot call method getName\(\) on Doctrine\\DBAL\\Schema\\Column\|false\.$#'
|
||||
identifier: method.nonObject
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Class Doctrine\\DBAL\\Schema\\Index\\IndexType not found\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Class Doctrine\\DBAL\\Schema\\PrimaryKeyConstraint not found\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Instanceof between Doctrine\\ORM\\Mapping\\ClassMetadata\<T of object\> and Doctrine\\ORM\\Mapping\\ClassMetadata will always evaluate to true\.$#'
|
||||
identifier: instanceof.alwaysTrue
|
||||
@@ -1392,12 +1434,30 @@ parameters:
|
||||
count: 2
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$array of function sort contains unresolvable type\.$#'
|
||||
identifier: argument.unresolvableType
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$columnName of method Doctrine\\ORM\\Mapping\\Driver\\DatabaseDriver\:\:getFieldNameForColumn\(\) expects string, string\|false given\.$#'
|
||||
identifier: argument.type
|
||||
count: 4
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \$indexedColumn of anonymous function has invalid type Doctrine\\DBAL\\Schema\\Index\\IndexedColumn\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \$name of anonymous function has invalid type Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\.$#'
|
||||
identifier: class.notFound
|
||||
count: 5
|
||||
path: src/Mapping/Driver/DatabaseDriver.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Mapping\\Driver\\SimplifiedXmlDriver\:\:__construct\(\) has parameter \$fileExtension with no type specified\.$#'
|
||||
identifier: missingType.parameter
|
||||
@@ -1500,12 +1560,36 @@ parameters:
|
||||
count: 1
|
||||
path: src/Mapping/JoinTableMapping.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Mapping\\LegacyReflectionFields\:\:__construct\(\) has parameter \$classMetadata with generic class Doctrine\\ORM\\Mapping\\ClassMetadata but does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
count: 1
|
||||
path: src/Mapping/LegacyReflectionFields.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$class of method Doctrine\\Persistence\\Mapping\\ReflectionService\:\:getAccessibleProperty\(\) expects class\-string, string given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Mapping/LegacyReflectionFields.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Mapping\\MappedSuperclass\:\:__construct\(\) has parameter \$repositoryClass with generic class Doctrine\\ORM\\EntityRepository but does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
count: 1
|
||||
path: src/Mapping/MappedSuperclass.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Mapping\\PropertyAccessors\\EnumPropertyAccessor\:\:toEnum\(\) should return array\<BackedEnum\>\|BackedEnum but returns array\<BackedEnum\|int\|string\>\.$#'
|
||||
identifier: return.type
|
||||
count: 1
|
||||
path: src/Mapping/PropertyAccessors/EnumPropertyAccessor.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$callback of function array_map expects \(callable\(BackedEnum\|int\|string\)\: mixed\)\|null, array\{class\-string\<BackedEnum\>, ''from''\} given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Mapping/PropertyAccessors/EnumPropertyAccessor.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Mapping\\QuoteStrategy\:\:getColumnAlias\(\) has parameter \$class with generic class Doctrine\\ORM\\Mapping\\ClassMetadata but does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
@@ -2316,12 +2400,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Proxy/ProxyFactory.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Proxy\\ProxyFactory\:\:getProxy\(\) return type with generic interface Doctrine\\ORM\\Proxy\\InternalProxy does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
count: 1
|
||||
path: src/Proxy/ProxyFactory.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Proxy\\ProxyFactory\:\:loadProxyClass\(\) has parameter \$class with generic interface Doctrine\\Persistence\\Mapping\\ClassMetadata but does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
@@ -2790,12 +2868,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Query/SqlWalker.php
|
||||
|
||||
-
|
||||
message: '#^Property Doctrine\\ORM\\Query\\SqlWalker\:\:\$selectedClasses \(array\<string, array\{class\: Doctrine\\ORM\\Mapping\\ClassMetadata, dqlAlias\: string, resultAlias\: string\|null\}\>\) does not accept non\-empty\-array\<int\|string, array\{class\: Doctrine\\ORM\\Mapping\\ClassMetadata, dqlAlias\: mixed, resultAlias\: string\|null\}\>\.$#'
|
||||
identifier: assign.propertyType
|
||||
count: 1
|
||||
path: src/Query/SqlWalker.php
|
||||
|
||||
-
|
||||
message: '#^Property Doctrine\\ORM\\Query\\SqlWalker\:\:\$selectedClasses with generic class Doctrine\\ORM\\Mapping\\ClassMetadata does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
@@ -3048,12 +3120,72 @@ parameters:
|
||||
count: 3
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencedColumnNames\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencedTableName\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint\:\:getReferencingColumnNames\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\Index\:\:getIndexedColumns\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\DBAL\\Schema\\Table\:\:dropForeignKey\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to function is_numeric\(\) with int\<0, max\> will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to method getColumnName\(\) on an unknown class Doctrine\\DBAL\\Schema\\Index\\IndexedColumn\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to method getColumnNames\(\) on an unknown class Doctrine\\DBAL\\Schema\\PrimaryKeyConstraint\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Call to method toString\(\) on an unknown class Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\.$#'
|
||||
identifier: class.notFound
|
||||
count: 3
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Class Doctrine\\DBAL\\Schema\\PrimaryKeyConstraint not found\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\DBAL\\Schema\\AbstractSchemaManager\<Doctrine\\DBAL\\Platforms\\AbstractPlatform\>\:\:createComparator\(\) invoked with 1 parameter, 0 required\.$#'
|
||||
identifier: arguments.count
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\ORM\\Tools\\SchemaTool\:\:addDiscriminatorColumnDefinition\(\) has parameter \$class with generic class Doctrine\\ORM\\Mapping\\ClassMetadata but does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
@@ -3156,6 +3288,18 @@ parameters:
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \$indexedColumn of anonymous function has invalid type Doctrine\\DBAL\\Schema\\Index\\IndexedColumn\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \$name of anonymous function has invalid type Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName\.$#'
|
||||
identifier: class.notFound
|
||||
count: 3
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '#^Property Doctrine\\ORM\\Tools\\SchemaTool\:\:\$schemaManager with generic class Doctrine\\DBAL\\Schema\\AbstractSchemaManager does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
|
||||
@@ -22,6 +22,18 @@ parameters:
|
||||
message: '~.*getTrimExpression.*expects int.*~'
|
||||
path: src/Query/AST/Functions/TrimFunction.php
|
||||
|
||||
-
|
||||
message: '~^Call to static method unquoted\(\) on an unknown class Doctrine\\DBAL\\Schema\\Name\\Identifier\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '~^Instantiated class Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName not found\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '~^Call to an undefined method Doctrine\\DBAL\\Schema\\Table::addPrimaryKeyConstraint\(\)\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
- '~^Class Doctrine\\DBAL\\Platforms\\SQLitePlatform not found\.$~'
|
||||
|
||||
# To be removed in 4.0
|
||||
|
||||
14
phpstan.neon
14
phpstan.neon
@@ -20,6 +20,18 @@ parameters:
|
||||
message: '~^Method Doctrine\\ORM\\Persisters\\Entity\\BasicEntityPersister\:\:getArrayBindingType\(\) never returns .* so it can be removed from the return type\.$~'
|
||||
path: src/Persisters/Entity/BasicEntityPersister.php
|
||||
|
||||
-
|
||||
message: '~^Call to static method unquoted\(\) on an unknown class Doctrine\\DBAL\\Schema\\Name\\Identifier\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '~^Instantiated class Doctrine\\DBAL\\Schema\\Name\\UnqualifiedName not found\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
-
|
||||
message: '~^Call to an undefined method Doctrine\\DBAL\\Schema\\Table::addPrimaryKeyConstraint\(\)\.$~'
|
||||
path: src/Tools/SchemaTool.php
|
||||
|
||||
# Compatibility with DBAL 3
|
||||
# See https://github.com/doctrine/dbal/pull/3480
|
||||
-
|
||||
@@ -33,7 +45,7 @@ parameters:
|
||||
path: src/UnitOfWork.php
|
||||
|
||||
-
|
||||
message: '~^Parameter #1 \$command of method Symfony\\Component\\Console\\Application::add\(\) expects Symfony\\Component\\Console\\Command\\Command, Doctrine\\DBAL\\Tools\\Console\\Command\\ReservedWordsCommand given\.$~'
|
||||
message: '~^Parameter #2 \$command of static method Doctrine\\ORM\\Tools\\Console\\ConsoleRunner::addCommandToApplication\(\) expects Symfony\\Component\\Console\\Command\\Command, Doctrine\\DBAL\\Tools\\Console\\Command\\ReservedWordsCommand given\.$~'
|
||||
path: src/Tools/Console/ConsoleRunner.php
|
||||
|
||||
-
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||
displayDetailsOnTestsThatTriggerNotices="true"
|
||||
displayDetailsOnTestsThatTriggerWarnings="true"
|
||||
failOnNotice="true"
|
||||
@@ -67,5 +69,12 @@
|
||||
<var name="privileged_db_port" value="3306"/>
|
||||
-->
|
||||
<env name="COLUMNS" value="120"/>
|
||||
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
|
||||
</php>
|
||||
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<include>
|
||||
<directory>src</directory>
|
||||
</include>
|
||||
</source>
|
||||
</phpunit>
|
||||
|
||||
@@ -286,7 +286,7 @@ abstract class AbstractQuery
|
||||
$key = Parameter::normalizeName($key);
|
||||
|
||||
$filteredParameters = $this->parameters->filter(
|
||||
static fn (Parameter $parameter): bool => $parameter->getName() === $key
|
||||
static fn (Parameter $parameter): bool => $parameter->getName() === $key,
|
||||
);
|
||||
|
||||
return ! $filteredParameters->isEmpty() ? $filteredParameters->first() : null;
|
||||
|
||||
@@ -29,11 +29,14 @@ class CollectionCacheKey extends CacheKey
|
||||
public readonly string $entityClass,
|
||||
public readonly string $association,
|
||||
array $ownerIdentifier,
|
||||
string $filterHash = '',
|
||||
) {
|
||||
ksort($ownerIdentifier);
|
||||
|
||||
$this->ownerIdentifier = $ownerIdentifier;
|
||||
|
||||
parent::__construct(str_replace('\\', '.', strtolower($entityClass)) . '_' . implode(' ', $ownerIdentifier) . '__' . $association);
|
||||
$filterHash = $filterHash === '' ? '' : '_' . $filterHash;
|
||||
|
||||
parent::__construct(str_replace('\\', '.', strtolower($entityClass)) . '_' . implode(' ', $ownerIdentifier) . '__' . $association . $filterHash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
||||
use Doctrine\ORM\PersistentCollection;
|
||||
use Doctrine\ORM\Persisters\Collection\CollectionPersister;
|
||||
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
|
||||
use Doctrine\ORM\Query\FilterCollection;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
|
||||
use function array_values;
|
||||
@@ -35,6 +36,7 @@ abstract class AbstractCollectionPersister implements CachedCollectionPersister
|
||||
protected array $queuedCache = [];
|
||||
|
||||
protected string $regionName;
|
||||
protected FilterCollection $filters;
|
||||
protected CollectionHydrator $hydrator;
|
||||
protected CacheLogger|null $cacheLogger;
|
||||
|
||||
@@ -48,6 +50,10 @@ abstract class AbstractCollectionPersister implements CachedCollectionPersister
|
||||
$cacheConfig = $configuration->getSecondLevelCacheConfiguration();
|
||||
$cacheFactory = $cacheConfig->getCacheFactory();
|
||||
|
||||
$this->region = $region;
|
||||
$this->persister = $persister;
|
||||
$this->association = $association;
|
||||
$this->filters = $em->getFilters();
|
||||
$this->regionName = $region->getName();
|
||||
$this->uow = $em->getUnitOfWork();
|
||||
$this->metadataFactory = $em->getMetadataFactory();
|
||||
@@ -135,7 +141,7 @@ abstract class AbstractCollectionPersister implements CachedCollectionPersister
|
||||
public function count(PersistentCollection $collection): int
|
||||
{
|
||||
$ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId);
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId, $this->filters->getHash());
|
||||
$entry = $this->region->get($key);
|
||||
|
||||
if ($entry !== null) {
|
||||
|
||||
@@ -36,7 +36,7 @@ class NonStrictReadWriteCachedCollectionPersister extends AbstractCollectionPers
|
||||
public function delete(PersistentCollection $collection): void
|
||||
{
|
||||
$ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId);
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId, $this->filters->getHash());
|
||||
|
||||
$this->persister->delete($collection);
|
||||
|
||||
@@ -53,7 +53,7 @@ class NonStrictReadWriteCachedCollectionPersister extends AbstractCollectionPers
|
||||
}
|
||||
|
||||
$ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId);
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId, $this->filters->getHash());
|
||||
|
||||
// Invalidate non initialized collections OR ordered collection
|
||||
if ($isDirty && ! $isInitialized || $this->association->isOrdered()) {
|
||||
|
||||
@@ -61,7 +61,7 @@ class ReadWriteCachedCollectionPersister extends AbstractCollectionPersister
|
||||
public function delete(PersistentCollection $collection): void
|
||||
{
|
||||
$ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId);
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId, $this->filters->getHash());
|
||||
$lock = $this->region->lock($key);
|
||||
|
||||
$this->persister->delete($collection);
|
||||
@@ -88,7 +88,7 @@ class ReadWriteCachedCollectionPersister extends AbstractCollectionPersister
|
||||
$this->persister->update($collection);
|
||||
|
||||
$ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId);
|
||||
$key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association->fieldName, $ownerId, $this->filters->getHash());
|
||||
$lock = $this->region->lock($key);
|
||||
|
||||
if ($lock === null) {
|
||||
|
||||
@@ -24,10 +24,12 @@ use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
||||
use Doctrine\ORM\PersistentCollection;
|
||||
use Doctrine\ORM\Persisters\Entity\EntityPersister;
|
||||
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
|
||||
use Doctrine\ORM\Query\FilterCollection;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
|
||||
use function array_merge;
|
||||
use function func_get_args;
|
||||
use function serialize;
|
||||
use function sha1;
|
||||
|
||||
@@ -43,6 +45,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
|
||||
protected TimestampCacheKey $timestampKey;
|
||||
protected EntityHydrator $hydrator;
|
||||
protected Cache $cache;
|
||||
protected FilterCollection $filters;
|
||||
protected CacheLogger|null $cacheLogger = null;
|
||||
protected string $regionName;
|
||||
|
||||
@@ -64,6 +67,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
|
||||
$cacheFactory = $cacheConfig->getCacheFactory();
|
||||
|
||||
$this->cache = $em->getCache();
|
||||
$this->filters = $em->getFilters();
|
||||
$this->regionName = $region->getName();
|
||||
$this->uow = $em->getUnitOfWork();
|
||||
$this->metadataFactory = $em->getMetadataFactory();
|
||||
@@ -215,7 +219,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
|
||||
? $this->persister->expandCriteriaParameters($criteria)
|
||||
: $this->persister->expandParameters($criteria);
|
||||
|
||||
return sha1($query . serialize($params) . serialize($orderBy) . $limit . $offset);
|
||||
return sha1($query . serialize($params) . serialize($orderBy) . $limit . $offset . $this->filters->getHash());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -472,7 +476,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
|
||||
}
|
||||
|
||||
$ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
|
||||
$key = $this->buildCollectionCacheKey($assoc, $ownerId);
|
||||
$key = $this->buildCollectionCacheKey($assoc, $ownerId, $this->filters->getHash());
|
||||
$list = $persister->loadCollectionCache($collection, $key);
|
||||
|
||||
if ($list !== null) {
|
||||
@@ -503,7 +507,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
|
||||
}
|
||||
|
||||
$ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
|
||||
$key = $this->buildCollectionCacheKey($assoc, $ownerId);
|
||||
$key = $this->buildCollectionCacheKey($assoc, $ownerId, $this->filters->getHash());
|
||||
$list = $persister->loadCollectionCache($collection, $key);
|
||||
|
||||
if ($list !== null) {
|
||||
@@ -546,12 +550,15 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $ownerId */
|
||||
protected function buildCollectionCacheKey(AssociationMapping $association, array $ownerId): CollectionCacheKey
|
||||
protected function buildCollectionCacheKey(AssociationMapping $association, array $ownerId, /* string $filterHash */): CollectionCacheKey
|
||||
{
|
||||
$filterHash = (string) (func_get_args()[2] ?? ''); // todo: move to argument in next major release
|
||||
|
||||
return new CollectionCacheKey(
|
||||
$this->metadataFactory->getMetadataFor($association->sourceEntity)->rootEntityName,
|
||||
$association->fieldName,
|
||||
$ownerId,
|
||||
$filterHash,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ use function class_exists;
|
||||
use function is_a;
|
||||
use function strtolower;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* Configuration container for all configuration options of Doctrine.
|
||||
* It combines all configuration options from DBAL & ORM.
|
||||
@@ -593,6 +595,20 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
$this->attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses;
|
||||
}
|
||||
|
||||
public function isNativeLazyObjectsEnabled(): bool
|
||||
{
|
||||
return $this->attributes['nativeLazyObjects'] ?? false;
|
||||
}
|
||||
|
||||
public function enableNativeLazyObjects(bool $nativeLazyObjects): void
|
||||
{
|
||||
if (PHP_VERSION_ID < 80400) {
|
||||
throw new LogicException('Lazy loading proxies require PHP 8.4 or higher.');
|
||||
}
|
||||
|
||||
$this->attributes['nativeLazyObjects'] = $nativeLazyObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* To be deprecated in 3.1.0
|
||||
*
|
||||
|
||||
@@ -18,12 +18,15 @@ use Generator;
|
||||
use LogicException;
|
||||
use ReflectionClass;
|
||||
|
||||
use function array_key_exists;
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function count;
|
||||
use function end;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function ksort;
|
||||
|
||||
/**
|
||||
* Base class for all hydrators. A hydrator is a class that provides some form
|
||||
@@ -263,6 +266,17 @@ abstract class AbstractHydrator
|
||||
{
|
||||
$rowData = ['data' => [], 'newObjects' => []];
|
||||
|
||||
foreach ($this->rsm->newObjectMappings as $mapping) {
|
||||
if (! array_key_exists($mapping['objIndex'], $this->rsm->newObject)) {
|
||||
$this->rsm->newObject[$mapping['objIndex']] = $mapping['className'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->rsm->newObject as $objIndex => $newObject) {
|
||||
$rowData['newObjects'][$objIndex]['class'] = new ReflectionClass($newObject);
|
||||
$rowData['newObjects'][$objIndex]['args'] = [];
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$cacheKeyInfo = $this->hydrateColumnInfo($key);
|
||||
if ($cacheKeyInfo === null) {
|
||||
@@ -282,7 +296,6 @@ abstract class AbstractHydrator
|
||||
$value = $this->buildEnum($value, $cacheKeyInfo['enumType']);
|
||||
}
|
||||
|
||||
$rowData['newObjects'][$objIndex]['class'] = $cacheKeyInfo['class'];
|
||||
$rowData['newObjects'][$objIndex]['args'][$argIndex] = $value;
|
||||
break;
|
||||
|
||||
@@ -336,21 +349,32 @@ abstract class AbstractHydrator
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->resultSetMapping()->nestedNewObjectArguments as $objIndex => ['ownerIndex' => $ownerIndex, 'argIndex' => $argIndex]) {
|
||||
if (! isset($rowData['newObjects'][$ownerIndex . ':' . $argIndex])) {
|
||||
continue;
|
||||
$nestedEntities = [];
|
||||
/**@var string $argAlias */
|
||||
foreach ($this->resultSetMapping()->nestedNewObjectArguments as ['ownerIndex' => $ownerIndex, 'argIndex' => $argIndex, 'argAlias' => $argAlias]) {
|
||||
if (array_key_exists($argAlias, $rowData['newObjects'])) {
|
||||
ksort($rowData['newObjects'][$argAlias]['args']);
|
||||
$rowData['newObjects'][$ownerIndex]['args'][$argIndex] = $rowData['newObjects'][$argAlias]['class']->newInstanceArgs($rowData['newObjects'][$argAlias]['args']);
|
||||
unset($rowData['newObjects'][$argAlias]);
|
||||
} elseif (array_key_exists($argAlias, $rowData['data'])) {
|
||||
if (! array_key_exists($argAlias, $nestedEntities)) {
|
||||
$nestedEntities[$argAlias] = '';
|
||||
$rowData['data'][$argAlias] = $this->hydrateNestedEntity($rowData['data'][$argAlias], $argAlias);
|
||||
}
|
||||
|
||||
$rowData['newObjects'][$ownerIndex]['args'][$argIndex] = $rowData['data'][$argAlias];
|
||||
} else {
|
||||
throw new LogicException($argAlias . ' does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
$newObject = $rowData['newObjects'][$ownerIndex . ':' . $argIndex];
|
||||
unset($rowData['newObjects'][$ownerIndex . ':' . $argIndex]);
|
||||
|
||||
$obj = $newObject['class']->newInstanceArgs($newObject['args']);
|
||||
|
||||
$rowData['newObjects'][$ownerIndex]['args'][$argIndex] = $obj;
|
||||
foreach (array_keys($nestedEntities) as $entity) {
|
||||
unset($rowData['data'][$entity]);
|
||||
}
|
||||
|
||||
foreach ($rowData['newObjects'] as $objIndex => $newObject) {
|
||||
$obj = $newObject['class']->newInstanceArgs($newObject['args']);
|
||||
ksort($rowData['newObjects'][$objIndex]['args']);
|
||||
$obj = $rowData['newObjects'][$objIndex]['class']->newInstanceArgs($rowData['newObjects'][$objIndex]['args']);
|
||||
|
||||
$rowData['newObjects'][$objIndex]['obj'] = $obj;
|
||||
}
|
||||
@@ -358,6 +382,12 @@ abstract class AbstractHydrator
|
||||
return $rowData;
|
||||
}
|
||||
|
||||
/** @param mixed[] $data pre-hydrated SQL Result Row. */
|
||||
protected function hydrateNestedEntity(array $data, string $dqlAlias): mixed
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a row of the result set.
|
||||
*
|
||||
@@ -454,7 +484,6 @@ abstract class AbstractHydrator
|
||||
'type' => Type::getType($this->rsm->typeMappings[$key]),
|
||||
'argIndex' => $mapping['argIndex'],
|
||||
'objIndex' => $mapping['objIndex'],
|
||||
'class' => new ReflectionClass($mapping['className']),
|
||||
'enumType' => $this->rsm->enumMappings[$key] ?? null,
|
||||
];
|
||||
|
||||
|
||||
@@ -70,6 +70,10 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$parent = $this->resultSetMapping()->parentAliasMap[$dqlAlias];
|
||||
|
||||
if (! isset($this->resultSetMapping()->aliasMap[$parent])) {
|
||||
if (isset($this->resultSetMapping()->nestedEntities[$dqlAlias])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
throw HydrationException::parentObjectOfRelationNotFound($dqlAlias, $parent);
|
||||
}
|
||||
|
||||
@@ -171,7 +175,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
): PersistentCollection {
|
||||
$oid = spl_object_id($entity);
|
||||
$relation = $class->associationMappings[$fieldName];
|
||||
$value = $class->reflFields[$fieldName]->getValue($entity);
|
||||
$value = $class->propertyAccessors[$fieldName]->getValue($entity);
|
||||
|
||||
if ($value === null || is_array($value)) {
|
||||
$value = new ArrayCollection((array) $value);
|
||||
@@ -186,7 +190,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
);
|
||||
$value->setOwner($entity, $relation);
|
||||
|
||||
$class->reflFields[$fieldName]->setValue($entity, $value);
|
||||
$class->propertyAccessors[$fieldName]->setValue($entity, $value);
|
||||
$this->uow->setOriginalEntityProperty($oid, $fieldName, $value);
|
||||
|
||||
$this->initializedCollections[$oid . $fieldName] = $value;
|
||||
@@ -346,7 +350,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$parentClass = $this->metadataCache[$this->resultSetMapping()->aliasMap[$parentAlias]];
|
||||
$relationField = $this->resultSetMapping()->relationMap[$dqlAlias];
|
||||
$relation = $parentClass->associationMappings[$relationField];
|
||||
$reflField = $parentClass->reflFields[$relationField];
|
||||
$reflField = $parentClass->propertyAccessors[$relationField];
|
||||
|
||||
// Get a reference to the parent object to which the joined element belongs.
|
||||
if ($this->resultSetMapping()->isMixed && isset($this->rootAliases[$parentAlias])) {
|
||||
@@ -446,13 +450,13 @@ class ObjectHydrator extends AbstractHydrator
|
||||
if ($relation->inversedBy !== null) {
|
||||
$inverseAssoc = $targetClass->associationMappings[$relation->inversedBy];
|
||||
if ($inverseAssoc->isToOne()) {
|
||||
$targetClass->reflFields[$inverseAssoc->fieldName]->setValue($element, $parentObject);
|
||||
$targetClass->propertyAccessors[$inverseAssoc->fieldName]->setValue($element, $parentObject);
|
||||
$this->uow->setOriginalEntityProperty(spl_object_id($element), $inverseAssoc->fieldName, $parentObject);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// For sure bidirectional, as there is no inverse side in unidirectional mappings
|
||||
$targetClass->reflFields[$relation->mappedBy]->setValue($element, $parentObject);
|
||||
$targetClass->propertyAccessors[$relation->mappedBy]->setValue($element, $parentObject);
|
||||
$this->uow->setOriginalEntityProperty(spl_object_id($element), $relation->mappedBy, $parentObject);
|
||||
}
|
||||
|
||||
@@ -569,6 +573,16 @@ class ObjectHydrator extends AbstractHydrator
|
||||
}
|
||||
}
|
||||
|
||||
/** @param mixed[] $data pre-hydrated SQL Result Row. */
|
||||
protected function hydrateNestedEntity(array $data, string $dqlAlias): mixed
|
||||
{
|
||||
if (isset($this->resultSetMapping()->nestedEntities[$dqlAlias])) {
|
||||
return $this->getEntity($data, $dqlAlias);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* When executed in a hydrate() loop we may have to clear internal state to
|
||||
* decrease memory consumption.
|
||||
|
||||
@@ -17,6 +17,7 @@ use function array_search;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function key;
|
||||
use function reset;
|
||||
use function sprintf;
|
||||
@@ -138,14 +139,21 @@ class SimpleObjectHydrator extends AbstractHydrator
|
||||
}
|
||||
|
||||
if ($value !== null && isset($cacheKeyInfo['enumType'])) {
|
||||
$originalValue = $value;
|
||||
$originalValue = $currentValue = $value;
|
||||
try {
|
||||
$value = $this->buildEnum($originalValue, $cacheKeyInfo['enumType']);
|
||||
if (! is_array($originalValue)) {
|
||||
$value = $this->buildEnum($originalValue, $cacheKeyInfo['enumType']);
|
||||
} else {
|
||||
$value = [];
|
||||
foreach ($originalValue as $i => $currentValue) {
|
||||
$value[$i] = $this->buildEnum($currentValue, $cacheKeyInfo['enumType']);
|
||||
}
|
||||
}
|
||||
} catch (ValueError $e) {
|
||||
throw MappingException::invalidEnumValue(
|
||||
$entityName,
|
||||
$cacheKeyInfo['fieldName'],
|
||||
(string) $originalValue,
|
||||
(string) $currentValue,
|
||||
$cacheKeyInfo['enumType'],
|
||||
$e,
|
||||
);
|
||||
|
||||
@@ -135,7 +135,13 @@ abstract class AssociationMapping implements ArrayAccess
|
||||
continue;
|
||||
}
|
||||
|
||||
assert($mapping instanceof ManyToManyOwningSideMapping);
|
||||
if (! $mapping instanceof ManyToManyOwningSideMapping) {
|
||||
throw new MappingException(
|
||||
"Mapping error on field '" .
|
||||
$mapping->fieldName . "' in " . $mapping->sourceEntity .
|
||||
" : 'joinTable' can only be set on many-to-many owning side.",
|
||||
);
|
||||
}
|
||||
|
||||
$mapping->joinTable = JoinTableMapping::fromMappingArray($value);
|
||||
|
||||
|
||||
@@ -14,9 +14,12 @@ use Doctrine\Instantiator\InstantiatorInterface;
|
||||
use Doctrine\ORM\Cache\Exception\NonCacheableEntityAssociation;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Id\AbstractIdGenerator;
|
||||
use Doctrine\ORM\Mapping\PropertyAccessors\EmbeddablePropertyAccessor;
|
||||
use Doctrine\ORM\Mapping\PropertyAccessors\EnumPropertyAccessor;
|
||||
use Doctrine\ORM\Mapping\PropertyAccessors\PropertyAccessor;
|
||||
use Doctrine\ORM\Mapping\PropertyAccessors\PropertyAccessorFactory;
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata;
|
||||
use Doctrine\Persistence\Mapping\ReflectionService;
|
||||
use Doctrine\Persistence\Reflection\EnumReflectionProperty;
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
use ReflectionClass;
|
||||
@@ -541,9 +544,12 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
/**
|
||||
* The ReflectionProperty instances of the mapped class.
|
||||
*
|
||||
* @var array<string, ReflectionProperty|null>
|
||||
* @var LegacyReflectionFields|array<string, ReflectionProperty>
|
||||
*/
|
||||
public array $reflFields = [];
|
||||
public LegacyReflectionFields|array $reflFields = [];
|
||||
|
||||
/** @var array<string, PropertyAccessors\PropertyAccessor> */
|
||||
public array $propertyAccessors = [];
|
||||
|
||||
private InstantiatorInterface|null $instantiator = null;
|
||||
|
||||
@@ -567,14 +573,24 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
/**
|
||||
* Gets the ReflectionProperties of the mapped class.
|
||||
*
|
||||
* @return ReflectionProperty[]|null[] An array of ReflectionProperty instances.
|
||||
* @phpstan-return array<ReflectionProperty|null>
|
||||
* @return LegacyReflectionFields|ReflectionProperty[] An array of ReflectionProperty instances.
|
||||
* @phpstan-return LegacyReflectionFields|array<string, ReflectionProperty>
|
||||
*/
|
||||
public function getReflectionProperties(): array
|
||||
public function getReflectionProperties(): array|LegacyReflectionFields
|
||||
{
|
||||
return $this->reflFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ReflectionProperties of the mapped class.
|
||||
*
|
||||
* @return PropertyAccessor[] An array of PropertyAccessor instances.
|
||||
*/
|
||||
public function getPropertyAccessors(): array
|
||||
{
|
||||
return $this->propertyAccessors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a ReflectionProperty for a specific field of the mapped class.
|
||||
*/
|
||||
@@ -583,11 +599,12 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
return $this->reflFields[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ReflectionProperty for the single identifier field.
|
||||
*
|
||||
* @throws BadMethodCallException If the class has a composite identifier.
|
||||
*/
|
||||
public function getPropertyAccessor(string $name): PropertyAccessor|null
|
||||
{
|
||||
return $this->propertyAccessors[$name] ?? null;
|
||||
}
|
||||
|
||||
/** @throws BadMethodCallException If the class has a composite identifier. */
|
||||
public function getSingleIdReflectionProperty(): ReflectionProperty|null
|
||||
{
|
||||
if ($this->isIdentifierComposite) {
|
||||
@@ -597,6 +614,16 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
return $this->reflFields[$this->identifier[0]];
|
||||
}
|
||||
|
||||
/** @throws BadMethodCallException If the class has a composite identifier. */
|
||||
public function getSingleIdPropertyAccessor(): PropertyAccessor|null
|
||||
{
|
||||
if ($this->isIdentifierComposite) {
|
||||
throw new BadMethodCallException('Class ' . $this->name . ' has a composite identifier.');
|
||||
}
|
||||
|
||||
return $this->propertyAccessors[$this->identifier[0]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the identifier values of an entity of this class.
|
||||
*
|
||||
@@ -611,7 +638,7 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
$id = [];
|
||||
|
||||
foreach ($this->identifier as $idField) {
|
||||
$value = $this->reflFields[$idField]->getValue($entity);
|
||||
$value = $this->propertyAccessors[$idField]->getValue($entity);
|
||||
|
||||
if ($value !== null) {
|
||||
$id[$idField] = $value;
|
||||
@@ -622,7 +649,7 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
}
|
||||
|
||||
$id = $this->identifier[0];
|
||||
$value = $this->reflFields[$id]->getValue($entity);
|
||||
$value = $this->propertyAccessors[$id]->getValue($entity);
|
||||
|
||||
if ($value === null) {
|
||||
return [];
|
||||
@@ -641,7 +668,7 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
public function setIdentifierValues(object $entity, array $id): void
|
||||
{
|
||||
foreach ($id as $idField => $idValue) {
|
||||
$this->reflFields[$idField]->setValue($entity, $idValue);
|
||||
$this->propertyAccessors[$idField]->setValue($entity, $idValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -650,7 +677,7 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
*/
|
||||
public function setFieldValue(object $entity, string $field, mixed $value): void
|
||||
{
|
||||
$this->reflFields[$field]->setValue($entity, $value);
|
||||
$this->propertyAccessors[$field]->setValue($entity, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -658,7 +685,7 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
*/
|
||||
public function getFieldValue(object $entity, string $field): mixed
|
||||
{
|
||||
return $this->reflFields[$field]->getValue($entity);
|
||||
return $this->propertyAccessors[$field]->getValue($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -792,76 +819,74 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
{
|
||||
// Restore ReflectionClass and properties
|
||||
$this->reflClass = $reflService->getClass($this->name);
|
||||
$this->reflFields = new LegacyReflectionFields($this, $reflService);
|
||||
$this->instantiator = $this->instantiator ?: new Instantiator();
|
||||
|
||||
$parentReflFields = [];
|
||||
$parentAccessors = [];
|
||||
|
||||
foreach ($this->embeddedClasses as $property => $embeddedClass) {
|
||||
if (isset($embeddedClass->declaredField)) {
|
||||
assert($embeddedClass->originalField !== null);
|
||||
$childProperty = $this->getAccessibleProperty(
|
||||
$reflService,
|
||||
$childAccessor = PropertyAccessorFactory::createPropertyAccessor(
|
||||
$this->embeddedClasses[$embeddedClass->declaredField]->class,
|
||||
$embeddedClass->originalField,
|
||||
);
|
||||
assert($childProperty !== null);
|
||||
$parentReflFields[$property] = new ReflectionEmbeddedProperty(
|
||||
$parentReflFields[$embeddedClass->declaredField],
|
||||
$childProperty,
|
||||
|
||||
$parentAccessors[$property] = new EmbeddablePropertyAccessor(
|
||||
$parentAccessors[$embeddedClass->declaredField],
|
||||
$childAccessor,
|
||||
$this->embeddedClasses[$embeddedClass->declaredField]->class,
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$fieldRefl = $this->getAccessibleProperty(
|
||||
$reflService,
|
||||
$accessor = PropertyAccessorFactory::createPropertyAccessor(
|
||||
$embeddedClass->declared ?? $this->name,
|
||||
$property,
|
||||
);
|
||||
|
||||
$parentReflFields[$property] = $fieldRefl;
|
||||
$this->reflFields[$property] = $fieldRefl;
|
||||
$parentAccessors[$property] = $accessor;
|
||||
$this->propertyAccessors[$property] = $accessor;
|
||||
}
|
||||
|
||||
foreach ($this->fieldMappings as $field => $mapping) {
|
||||
if (isset($mapping->declaredField) && isset($parentReflFields[$mapping->declaredField])) {
|
||||
if (isset($mapping->declaredField) && isset($parentAccessors[$mapping->declaredField])) {
|
||||
assert($mapping->originalField !== null);
|
||||
assert($mapping->originalClass !== null);
|
||||
$childProperty = $this->getAccessibleProperty($reflService, $mapping->originalClass, $mapping->originalField);
|
||||
assert($childProperty !== null);
|
||||
$accessor = PropertyAccessorFactory::createPropertyAccessor($mapping->originalClass, $mapping->originalField);
|
||||
|
||||
if (isset($mapping->enumType)) {
|
||||
$childProperty = new EnumReflectionProperty(
|
||||
$childProperty,
|
||||
if ($mapping->enumType !== null) {
|
||||
$accessor = new EnumPropertyAccessor(
|
||||
$accessor,
|
||||
$mapping->enumType,
|
||||
);
|
||||
}
|
||||
|
||||
$this->reflFields[$field] = new ReflectionEmbeddedProperty(
|
||||
$parentReflFields[$mapping->declaredField],
|
||||
$childProperty,
|
||||
$this->propertyAccessors[$field] = new EmbeddablePropertyAccessor(
|
||||
$parentAccessors[$mapping->declaredField],
|
||||
$accessor,
|
||||
$mapping->originalClass,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->reflFields[$field] = isset($mapping->declared)
|
||||
? $this->getAccessibleProperty($reflService, $mapping->declared, $field)
|
||||
: $this->getAccessibleProperty($reflService, $this->name, $field);
|
||||
$this->propertyAccessors[$field] = isset($mapping->declared)
|
||||
? PropertyAccessorFactory::createPropertyAccessor($mapping->declared, $field)
|
||||
: PropertyAccessorFactory::createPropertyAccessor($this->name, $field);
|
||||
|
||||
if (isset($mapping->enumType) && $this->reflFields[$field] !== null) {
|
||||
$this->reflFields[$field] = new EnumReflectionProperty(
|
||||
$this->reflFields[$field],
|
||||
if ($mapping->enumType !== null) {
|
||||
$this->propertyAccessors[$field] = new EnumPropertyAccessor(
|
||||
$this->propertyAccessors[$field],
|
||||
$mapping->enumType,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->associationMappings as $field => $mapping) {
|
||||
$this->reflFields[$field] = isset($mapping->declared)
|
||||
? $this->getAccessibleProperty($reflService, $mapping->declared, $field)
|
||||
: $this->getAccessibleProperty($reflService, $this->name, $field);
|
||||
$this->propertyAccessors[$field] = isset($mapping->declared)
|
||||
? PropertyAccessorFactory::createPropertyAccessor($mapping->declared, $field)
|
||||
: PropertyAccessorFactory::createPropertyAccessor($this->name, $field);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2657,22 +2682,4 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
|
||||
return $sequencePrefix;
|
||||
}
|
||||
|
||||
/** @phpstan-param class-string $class */
|
||||
private function getAccessibleProperty(ReflectionService $reflService, string $class, string $field): ReflectionProperty|null
|
||||
{
|
||||
$reflectionProperty = $reflService->getAccessibleProperty($class, $field);
|
||||
if ($reflectionProperty?->isReadOnly()) {
|
||||
$declaringClass = $reflectionProperty->class;
|
||||
if ($declaringClass !== $class) {
|
||||
$reflectionProperty = $reflService->getAccessibleProperty($declaringClass, $field);
|
||||
}
|
||||
|
||||
if ($reflectionProperty !== null) {
|
||||
$reflectionProperty = new ReflectionReadonlyProperty($reflectionProperty);
|
||||
}
|
||||
}
|
||||
|
||||
return $reflectionProperty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ use function strlen;
|
||||
use function strtolower;
|
||||
use function substr;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
|
||||
* metadata mapping information of a class which describes how a class should be mapped
|
||||
@@ -440,8 +442,8 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
$subClass->addInheritedFieldMapping($subClassMapping);
|
||||
}
|
||||
|
||||
foreach ($parentClass->reflFields as $name => $field) {
|
||||
$subClass->reflFields[$name] = $field;
|
||||
foreach ($parentClass->propertyAccessors as $name => $field) {
|
||||
$subClass->propertyAccessors[$name] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -699,6 +701,18 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
protected function wakeupReflection(ClassMetadataInterface $class, ReflectionService $reflService): void
|
||||
{
|
||||
$class->wakeupReflection($reflService);
|
||||
|
||||
if (PHP_VERSION_ID < 80400) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($class->propertyAccessors as $propertyAccessor) {
|
||||
$property = $propertyAccessor->getUnderlyingReflector();
|
||||
|
||||
if ($property->isVirtual()) {
|
||||
throw MappingException::mappingVirtualPropertyNotAllowed($class->name, $property->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function initializeReflection(ClassMetadataInterface $class, ReflectionService $reflService): void
|
||||
|
||||
@@ -24,7 +24,7 @@ class DefaultQuoteStrategy implements QuoteStrategy
|
||||
public function getColumnName(string $fieldName, ClassMetadata $class, AbstractPlatform $platform): string
|
||||
{
|
||||
return isset($class->fieldMappings[$fieldName]->quoted)
|
||||
? $platform->quoteIdentifier($class->fieldMappings[$fieldName]->columnName)
|
||||
? $platform->quoteSingleIdentifier($class->fieldMappings[$fieldName]->columnName)
|
||||
: $class->fieldMappings[$fieldName]->columnName;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class DefaultQuoteStrategy implements QuoteStrategy
|
||||
}
|
||||
|
||||
return isset($class->table['quoted'])
|
||||
? $platform->quoteIdentifier($tableName)
|
||||
? $platform->quoteSingleIdentifier($tableName)
|
||||
: $tableName;
|
||||
}
|
||||
|
||||
@@ -52,14 +52,14 @@ class DefaultQuoteStrategy implements QuoteStrategy
|
||||
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform): string
|
||||
{
|
||||
return isset($definition['quoted'])
|
||||
? $platform->quoteIdentifier($definition['sequenceName'])
|
||||
? $platform->quoteSingleIdentifier($definition['sequenceName'])
|
||||
: $definition['sequenceName'];
|
||||
}
|
||||
|
||||
public function getJoinColumnName(JoinColumnMapping $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
|
||||
{
|
||||
return isset($joinColumn->quoted)
|
||||
? $platform->quoteIdentifier($joinColumn->name)
|
||||
? $platform->quoteSingleIdentifier($joinColumn->name)
|
||||
: $joinColumn->name;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class DefaultQuoteStrategy implements QuoteStrategy
|
||||
AbstractPlatform $platform,
|
||||
): string {
|
||||
return isset($joinColumn->quoted)
|
||||
? $platform->quoteIdentifier($joinColumn->referencedColumnName)
|
||||
? $platform->quoteSingleIdentifier($joinColumn->referencedColumnName)
|
||||
: $joinColumn->referencedColumnName;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class DefaultQuoteStrategy implements QuoteStrategy
|
||||
$tableName = $association->joinTable->name;
|
||||
|
||||
if (isset($association->joinTable->quoted)) {
|
||||
$tableName = $platform->quoteIdentifier($tableName);
|
||||
$tableName = $platform->quoteSingleIdentifier($tableName);
|
||||
}
|
||||
|
||||
return $schema . $tableName;
|
||||
@@ -113,7 +113,7 @@ class DefaultQuoteStrategy implements QuoteStrategy
|
||||
$joinColumns = $assoc->joinColumns;
|
||||
$assocQuotedColumnNames = array_map(
|
||||
static fn (JoinColumnMapping $joinColumn) => isset($joinColumn->quoted)
|
||||
? $platform->quoteIdentifier($joinColumn->name)
|
||||
? $platform->quoteSingleIdentifier($joinColumn->name)
|
||||
: $joinColumn->name,
|
||||
$joinColumns,
|
||||
);
|
||||
|
||||
@@ -684,6 +684,7 @@ class AttributeDriver implements MappingDriver
|
||||
{
|
||||
$mapping = [
|
||||
'name' => $joinColumn->name,
|
||||
'deferrable' => $joinColumn->deferrable,
|
||||
'unique' => $joinColumn->unique,
|
||||
'nullable' => $joinColumn->nullable,
|
||||
'onDelete' => $joinColumn->onDelete,
|
||||
|
||||
@@ -6,6 +6,12 @@ namespace Doctrine\ORM\Mapping\Driver;
|
||||
|
||||
use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
use Doctrine\DBAL\Schema\Index\IndexedColumn;
|
||||
use Doctrine\DBAL\Schema\Index\IndexType;
|
||||
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
|
||||
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\SchemaException;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
@@ -21,12 +27,15 @@ use TypeError;
|
||||
|
||||
use function array_diff;
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function current;
|
||||
use function enum_exists;
|
||||
use function get_debug_type;
|
||||
use function in_array;
|
||||
use function method_exists;
|
||||
use function preg_replace;
|
||||
use function sort;
|
||||
use function sprintf;
|
||||
@@ -187,7 +196,7 @@ class DatabaseDriver implements MappingDriver
|
||||
foreach ($this->manyToManyTables as $manyTable) {
|
||||
foreach ($manyTable->getForeignKeys() as $foreignKey) {
|
||||
// foreign key maps to the table of the current entity, many to many association probably exists
|
||||
if (! (strtolower($tableName) === strtolower($foreignKey->getForeignTableName()))) {
|
||||
if (! (strtolower($tableName) === strtolower(self::getReferencedTableName($foreignKey)))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -207,22 +216,22 @@ class DatabaseDriver implements MappingDriver
|
||||
continue;
|
||||
}
|
||||
|
||||
$localColumn = current($myFk->getLocalColumns());
|
||||
$localColumn = current(self::getReferencingColumnNames($myFk));
|
||||
|
||||
$associationMapping = [];
|
||||
$associationMapping['fieldName'] = $this->getFieldNameForColumn($manyTable->getName(), current($otherFk->getLocalColumns()), true);
|
||||
$associationMapping['targetEntity'] = $this->getClassNameForTable($otherFk->getForeignTableName());
|
||||
$associationMapping['fieldName'] = $this->getFieldNameForColumn($manyTable->getName(), current(self::getReferencingColumnNames($otherFk)), true);
|
||||
$associationMapping['targetEntity'] = $this->getClassNameForTable(self::getReferencedTableName($otherFk));
|
||||
|
||||
if (current($manyTable->getColumns())->getName() === $localColumn) {
|
||||
$associationMapping['inversedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getLocalColumns()), true);
|
||||
$associationMapping['inversedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current(self::getReferencingColumnNames($myFk)), true);
|
||||
$associationMapping['joinTable'] = [
|
||||
'name' => strtolower($manyTable->getName()),
|
||||
'joinColumns' => [],
|
||||
'inverseJoinColumns' => [],
|
||||
];
|
||||
|
||||
$fkCols = $myFk->getForeignColumns();
|
||||
$cols = $myFk->getLocalColumns();
|
||||
$fkCols = self::getReferencedColumnNames($myFk);
|
||||
$cols = self::getReferencingColumnNames($myFk);
|
||||
|
||||
for ($i = 0, $colsCount = count($cols); $i < $colsCount; $i++) {
|
||||
$associationMapping['joinTable']['joinColumns'][] = [
|
||||
@@ -231,8 +240,8 @@ class DatabaseDriver implements MappingDriver
|
||||
];
|
||||
}
|
||||
|
||||
$fkCols = $otherFk->getForeignColumns();
|
||||
$cols = $otherFk->getLocalColumns();
|
||||
$fkCols = self::getReferencedColumnNames($otherFk);
|
||||
$cols = self::getReferencingColumnNames($otherFk);
|
||||
|
||||
for ($i = 0, $colsCount = count($cols); $i < $colsCount; $i++) {
|
||||
$associationMapping['joinTable']['inverseJoinColumns'][] = [
|
||||
@@ -241,7 +250,7 @@ class DatabaseDriver implements MappingDriver
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$associationMapping['mappedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getLocalColumns()), true);
|
||||
$associationMapping['mappedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current(self::getReferencingColumnNames($myFk)), true);
|
||||
}
|
||||
|
||||
$metadata->mapManyToMany($associationMapping);
|
||||
@@ -267,10 +276,15 @@ class DatabaseDriver implements MappingDriver
|
||||
$allForeignKeyColumns = [];
|
||||
|
||||
foreach ($foreignKeys as $foreignKey) {
|
||||
$allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
|
||||
$allForeignKeyColumns = array_merge($allForeignKeyColumns, self::getReferencingColumnNames($foreignKey));
|
||||
}
|
||||
|
||||
if (method_exists($table, 'getPrimaryKeyConstraint')) {
|
||||
$primaryKey = $table->getPrimaryKeyConstraint();
|
||||
} else {
|
||||
$primaryKey = $table->getPrimaryKey();
|
||||
}
|
||||
|
||||
$primaryKey = $table->getPrimaryKey();
|
||||
if ($primaryKey === null) {
|
||||
throw new MappingException(
|
||||
'Table ' . $tableName . ' has no primary key. Doctrine does not ' .
|
||||
@@ -278,7 +292,11 @@ class DatabaseDriver implements MappingDriver
|
||||
);
|
||||
}
|
||||
|
||||
$pkColumns = $primaryKey->getColumns();
|
||||
if ($primaryKey instanceof PrimaryKeyConstraint) {
|
||||
$pkColumns = array_map(static fn (UnqualifiedName $name) => $name->toString(), $primaryKey->getColumnNames());
|
||||
} else {
|
||||
$pkColumns = self::getIndexedColumns($primaryKey);
|
||||
}
|
||||
|
||||
sort($pkColumns);
|
||||
sort($allForeignKeyColumns);
|
||||
@@ -301,17 +319,25 @@ class DatabaseDriver implements MappingDriver
|
||||
*/
|
||||
private function buildIndexes(ClassMetadata $metadata): void
|
||||
{
|
||||
$tableName = $metadata->table['name'];
|
||||
$indexes = $this->tables[$tableName]->getIndexes();
|
||||
$tableName = $metadata->table['name'];
|
||||
$table = $this->tables[$tableName];
|
||||
$primaryKey = self::getPrimaryKey($table);
|
||||
$indexes = $table->getIndexes();
|
||||
|
||||
foreach ($indexes as $index) {
|
||||
if ($index->isPrimary()) {
|
||||
if ($index === $primaryKey) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (enum_exists(IndexType::class) && method_exists($index, 'getType')) {
|
||||
$isUnique = $index->getType() === IndexType::UNIQUE;
|
||||
} else {
|
||||
$isUnique = $index->isUnique();
|
||||
}
|
||||
|
||||
$indexName = $index->getName();
|
||||
$indexColumns = $index->getColumns();
|
||||
$constraintType = $index->isUnique()
|
||||
$indexColumns = self::getIndexedColumns($index);
|
||||
$constraintType = $isUnique
|
||||
? 'uniqueConstraints'
|
||||
: 'indexes';
|
||||
|
||||
@@ -331,7 +357,7 @@ class DatabaseDriver implements MappingDriver
|
||||
$allForeignKeys = [];
|
||||
|
||||
foreach ($foreignKeys as $foreignKey) {
|
||||
$allForeignKeys = array_merge($allForeignKeys, $foreignKey->getLocalColumns());
|
||||
$allForeignKeys = array_merge($allForeignKeys, self::getReferencingColumnNames($foreignKey));
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
@@ -441,9 +467,9 @@ class DatabaseDriver implements MappingDriver
|
||||
$foreignKeys = $this->tables[$tableName]->getForeignKeys();
|
||||
|
||||
foreach ($foreignKeys as $foreignKey) {
|
||||
$foreignTableName = $foreignKey->getForeignTableName();
|
||||
$fkColumns = $foreignKey->getLocalColumns();
|
||||
$fkForeignColumns = $foreignKey->getForeignColumns();
|
||||
$foreignTableName = self::getReferencedTableName($foreignKey);
|
||||
$fkColumns = self::getReferencingColumnNames($foreignKey);
|
||||
$fkForeignColumns = self::getReferencedColumnNames($foreignKey);
|
||||
$localColumn = current($fkColumns);
|
||||
$associationMapping = [
|
||||
'fieldName' => $this->getFieldNameForColumn($tableName, $localColumn, true),
|
||||
@@ -482,7 +508,11 @@ class DatabaseDriver implements MappingDriver
|
||||
private function getTablePrimaryKeys(Table $table): array
|
||||
{
|
||||
try {
|
||||
return $table->getPrimaryKey()->getColumns();
|
||||
if (method_exists($table, 'getPrimaryKeyConstraint')) {
|
||||
return array_map(static fn (UnqualifiedName $name) => $name->toString(), $table->getPrimaryKeyConstraint()->getColumnNames());
|
||||
}
|
||||
|
||||
return self::getIndexedColumns($table->getPrimaryKey());
|
||||
} catch (SchemaException) {
|
||||
// Do nothing
|
||||
}
|
||||
@@ -527,4 +557,66 @@ class DatabaseDriver implements MappingDriver
|
||||
|
||||
return $this->inflector->camelize($columnName);
|
||||
}
|
||||
|
||||
private static function getReferencedTableName(ForeignKeyConstraint $foreignKey): string
|
||||
{
|
||||
if (method_exists(ForeignKeyConstraint::class, 'getReferencedTableName')) {
|
||||
return $foreignKey->getReferencedTableName()->toString();
|
||||
}
|
||||
|
||||
return $foreignKey->getForeignTableName();
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private static function getReferencingColumnNames(ForeignKeyConstraint $foreignKey): array
|
||||
{
|
||||
if (method_exists(ForeignKeyConstraint::class, 'getReferencingColumnNames')) {
|
||||
return array_map(static fn (UnqualifiedName $name) => $name->toString(), $foreignKey->getReferencingColumnNames());
|
||||
}
|
||||
|
||||
return $foreignKey->getLocalColumns();
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private static function getReferencedColumnNames(ForeignKeyConstraint $foreignKey): array
|
||||
{
|
||||
if (method_exists(ForeignKeyConstraint::class, 'getReferencedColumnNames')) {
|
||||
return array_map(static fn (UnqualifiedName $name) => $name->toString(), $foreignKey->getReferencedColumnNames());
|
||||
}
|
||||
|
||||
return $foreignKey->getForeignColumns();
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private static function getIndexedColumns(Index $index): array
|
||||
{
|
||||
if (method_exists(Index::class, 'getIndexedColumns')) {
|
||||
return array_map(static fn (IndexedColumn $indexedColumn) => $indexedColumn->getColumnName()->toString(), $index->getIndexedColumns());
|
||||
}
|
||||
|
||||
return $index->getColumns();
|
||||
}
|
||||
|
||||
private static function getPrimaryKey(Table $table): Index|null
|
||||
{
|
||||
$primaryKeyConstraint = null;
|
||||
|
||||
if (method_exists(Table::class, 'getPrimaryKeyConstraint')) {
|
||||
$primaryKeyConstraint = $table->getPrimaryKeyConstraint();
|
||||
}
|
||||
|
||||
foreach ($table->getIndexes() as $index) {
|
||||
if ($primaryKeyConstraint !== null) {
|
||||
$primaryKeyConstraintColumns = array_map(static fn (UnqualifiedName $name) => $name->toString(), $primaryKeyConstraint->getColumnNames());
|
||||
|
||||
if ($primaryKeyConstraintColumns === self::getIndexedColumns($index)) {
|
||||
return $index;
|
||||
}
|
||||
} elseif ($index->isPrimary()) {
|
||||
return $index;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,13 @@ trait ReflectionBasedDriver
|
||||
*/
|
||||
private function isRepeatedPropertyDeclaration(ReflectionProperty $property, ClassMetadata $metadata): bool
|
||||
{
|
||||
/** @var class-string $declaringClass */
|
||||
$declaringClass = $property->class;
|
||||
|
||||
if ($this->isTransient($declaringClass)) {
|
||||
return isset($metadata->fieldMappings[$property->name]);
|
||||
}
|
||||
|
||||
if (
|
||||
isset($metadata->fieldMappings[$property->name]->declared)
|
||||
&& $metadata->fieldMappings[$property->name]->declared === $declaringClass
|
||||
|
||||
@@ -54,6 +54,7 @@ final class FieldMapping implements ArrayAccess
|
||||
*/
|
||||
public string|null $inherited = null;
|
||||
|
||||
/** @var class-string|null */
|
||||
public string|null $originalClass = null;
|
||||
public string|null $originalField = null;
|
||||
public bool|null $quoted = null;
|
||||
@@ -101,7 +102,7 @@ final class FieldMapping implements ArrayAccess
|
||||
* scale?: int|null,
|
||||
* unique?: bool|null,
|
||||
* inherited?: string|null,
|
||||
* originalClass?: string|null,
|
||||
* originalClass?: class-string|null,
|
||||
* originalField?: string|null,
|
||||
* quoted?: bool|null,
|
||||
* declared?: string|null,
|
||||
|
||||
@@ -13,6 +13,7 @@ final class JoinColumnMapping implements ArrayAccess
|
||||
{
|
||||
use ArrayAccessImplementation;
|
||||
|
||||
public bool|null $deferrable = null;
|
||||
public bool|null $unique = null;
|
||||
public bool|null $quoted = null;
|
||||
public string|null $fieldName = null;
|
||||
@@ -33,7 +34,7 @@ final class JoinColumnMapping implements ArrayAccess
|
||||
* @param array<string, mixed> $mappingArray
|
||||
* @phpstan-param array{
|
||||
* name: string,
|
||||
* referencedColumnName: string,
|
||||
* referencedColumnName: string|null,
|
||||
* unique?: bool|null,
|
||||
* quoted?: bool|null,
|
||||
* fieldName?: string|null,
|
||||
@@ -66,7 +67,7 @@ final class JoinColumnMapping implements ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['unique', 'quoted', 'nullable'] as $boolKey) {
|
||||
foreach (['deferrable', 'unique', 'quoted', 'nullable'] as $boolKey) {
|
||||
if ($this->$boolKey !== null) {
|
||||
$serialized[] = $boolKey;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ trait JoinColumnProperties
|
||||
/** @param array<string, mixed> $options */
|
||||
public function __construct(
|
||||
public readonly string|null $name = null,
|
||||
public readonly string $referencedColumnName = 'id',
|
||||
public readonly string|null $referencedColumnName = null,
|
||||
public readonly bool $deferrable = false,
|
||||
public readonly bool $unique = false,
|
||||
public readonly bool $nullable = true,
|
||||
public readonly mixed $onDelete = null,
|
||||
|
||||
170
src/Mapping/LegacyReflectionFields.php
Normal file
170
src/Mapping/LegacyReflectionFields.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Mapping;
|
||||
|
||||
use ArrayAccess;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use Doctrine\Persistence\Mapping\ReflectionService;
|
||||
use Doctrine\Persistence\Reflection\EnumReflectionProperty;
|
||||
use Generator;
|
||||
use IteratorAggregate;
|
||||
use OutOfBoundsException;
|
||||
use ReflectionProperty;
|
||||
use Traversable;
|
||||
|
||||
use function array_keys;
|
||||
use function assert;
|
||||
use function is_string;
|
||||
use function str_contains;
|
||||
use function str_replace;
|
||||
|
||||
/**
|
||||
* @template-implements ArrayAccess<string, ReflectionProperty|null>
|
||||
* @template-implements IteratorAggregate<string, ReflectionProperty|null>
|
||||
*/
|
||||
class LegacyReflectionFields implements ArrayAccess, IteratorAggregate
|
||||
{
|
||||
/** @var array<string, ReflectionProperty|null> */
|
||||
private array $reflFields = [];
|
||||
|
||||
public function __construct(private ClassMetadata $classMetadata, private ReflectionService $reflectionService)
|
||||
{
|
||||
}
|
||||
|
||||
/** @param string $offset */
|
||||
public function offsetExists($offset): bool // phpcs:ignore
|
||||
{
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/11659',
|
||||
'Access to ClassMetadata::$reflFields is deprecated and will be removed in Doctrine ORM 4.0.',
|
||||
);
|
||||
|
||||
return isset($this->classMetadata->propertyAccessors[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @psalm-suppress LessSpecificImplementedReturnType
|
||||
*/
|
||||
public function offsetGet($field): mixed // phpcs:ignore
|
||||
{
|
||||
if (isset($this->reflFields[$field])) {
|
||||
return $this->reflFields[$field];
|
||||
}
|
||||
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/11659',
|
||||
'Access to ClassMetadata::$reflFields is deprecated and will be removed in Doctrine ORM 4.0.',
|
||||
);
|
||||
|
||||
if (isset($this->classMetadata->propertyAccessors[$field])) {
|
||||
$fieldName = str_contains($field, '.') ? $this->classMetadata->fieldMappings[$field]->originalField : $field;
|
||||
$className = $this->classMetadata->name;
|
||||
|
||||
assert(is_string($fieldName));
|
||||
|
||||
if (isset($this->classMetadata->fieldMappings[$field]) && $this->classMetadata->fieldMappings[$field]->originalClass !== null) {
|
||||
$className = $this->classMetadata->fieldMappings[$field]->originalClass;
|
||||
} elseif (isset($this->classMetadata->fieldMappings[$field]) && $this->classMetadata->fieldMappings[$field]->declared !== null) {
|
||||
$className = $this->classMetadata->fieldMappings[$field]->declared;
|
||||
} elseif (isset($this->classMetadata->associationMappings[$field]) && $this->classMetadata->associationMappings[$field]->declared !== null) {
|
||||
$className = $this->classMetadata->associationMappings[$field]->declared;
|
||||
} elseif (isset($this->classMetadata->embeddedClasses[$field]) && $this->classMetadata->embeddedClasses[$field]->declared !== null) {
|
||||
$className = $this->classMetadata->embeddedClasses[$field]->declared;
|
||||
}
|
||||
|
||||
/** @psalm-suppress ArgumentTypeCoercion */
|
||||
$this->reflFields[$field] = $this->getAccessibleProperty($className, $fieldName);
|
||||
|
||||
if (isset($this->classMetadata->fieldMappings[$field])) {
|
||||
if ($this->classMetadata->fieldMappings[$field]->enumType !== null) {
|
||||
$this->reflFields[$field] = new EnumReflectionProperty(
|
||||
$this->reflFields[$field],
|
||||
$this->classMetadata->fieldMappings[$field]->enumType,
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->classMetadata->fieldMappings[$field]->originalField !== null) {
|
||||
$parentField = str_replace('.' . $fieldName, '', $field);
|
||||
$originalClass = $this->classMetadata->fieldMappings[$field]->originalClass;
|
||||
|
||||
if (! str_contains($parentField, '.')) {
|
||||
$parentClass = $this->classMetadata->name;
|
||||
} else {
|
||||
$parentClass = $this->classMetadata->fieldMappings[$parentField]->originalClass;
|
||||
}
|
||||
|
||||
/** @psalm-var class-string $parentClass */
|
||||
/** @psalm-var class-string $originalClass */
|
||||
|
||||
$this->reflFields[$field] = new ReflectionEmbeddedProperty(
|
||||
$this->getAccessibleProperty($parentClass, $parentField),
|
||||
$this->reflFields[$field],
|
||||
$originalClass,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->reflFields[$field];
|
||||
}
|
||||
|
||||
throw new OutOfBoundsException('Unknown field: ' . $this->classMetadata->name . ' ::$' . $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $offset
|
||||
* @param ReflectionProperty $value
|
||||
*/
|
||||
public function offsetSet($offset, $value): void // phpcs:ignore
|
||||
{
|
||||
$this->reflFields[$offset] = $value;
|
||||
}
|
||||
|
||||
/** @param string $offset */
|
||||
public function offsetUnset($offset): void // phpcs:ignore
|
||||
{
|
||||
unset($this->reflFields[$offset]);
|
||||
}
|
||||
|
||||
/** @psalm-param class-string $class */
|
||||
private function getAccessibleProperty(string $class, string $field): ReflectionProperty
|
||||
{
|
||||
$reflectionProperty = $this->reflectionService->getAccessibleProperty($class, $field);
|
||||
|
||||
assert($reflectionProperty !== null);
|
||||
|
||||
if ($reflectionProperty->isReadOnly()) {
|
||||
$declaringClass = $reflectionProperty->class;
|
||||
if ($declaringClass !== $class) {
|
||||
$reflectionProperty = $this->reflectionService->getAccessibleProperty($declaringClass, $field);
|
||||
|
||||
assert($reflectionProperty !== null);
|
||||
}
|
||||
|
||||
$reflectionProperty = new ReflectionReadonlyProperty($reflectionProperty);
|
||||
}
|
||||
|
||||
return $reflectionProperty;
|
||||
}
|
||||
|
||||
/** @return Generator<string, ReflectionProperty> */
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/11659',
|
||||
'Access to ClassMetadata::$reflFields is deprecated and will be removed in Doctrine ORM 4.0.',
|
||||
);
|
||||
|
||||
$keys = array_keys($this->classMetadata->propertyAccessors);
|
||||
|
||||
foreach ($keys as $key) {
|
||||
yield $key => $this->offsetGet($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,10 +61,14 @@ final class ManyToManyOwningSideMapping extends ToManyOwningSideMapping implemen
|
||||
{
|
||||
if (isset($mappingArray['joinTable']['joinColumns'])) {
|
||||
foreach ($mappingArray['joinTable']['joinColumns'] as $key => $joinColumn) {
|
||||
if (empty($joinColumn['referencedColumnName'])) {
|
||||
$mappingArray['joinTable']['joinColumns'][$key]['referencedColumnName'] = $namingStrategy->referenceColumnName();
|
||||
}
|
||||
|
||||
if (empty($joinColumn['name'])) {
|
||||
$mappingArray['joinTable']['joinColumns'][$key]['name'] = $namingStrategy->joinKeyColumnName(
|
||||
$mappingArray['sourceEntity'],
|
||||
$joinColumn['referencedColumnName'] ?? null,
|
||||
$joinColumn['referencedColumnName'] ?? $namingStrategy->referenceColumnName(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -72,10 +76,14 @@ final class ManyToManyOwningSideMapping extends ToManyOwningSideMapping implemen
|
||||
|
||||
if (isset($mappingArray['joinTable']['inverseJoinColumns'])) {
|
||||
foreach ($mappingArray['joinTable']['inverseJoinColumns'] as $key => $joinColumn) {
|
||||
if (empty($joinColumn['referencedColumnName'])) {
|
||||
$mappingArray['joinTable']['inverseJoinColumns'][$key]['referencedColumnName'] = $namingStrategy->referenceColumnName();
|
||||
}
|
||||
|
||||
if (empty($joinColumn['name'])) {
|
||||
$mappingArray['joinTable']['inverseJoinColumns'][$key]['name'] = $namingStrategy->joinKeyColumnName(
|
||||
$mappingArray['targetEntity'],
|
||||
$joinColumn['referencedColumnName'] ?? null,
|
||||
$joinColumn['referencedColumnName'] ?? $namingStrategy->referenceColumnName(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,4 +688,13 @@ EXCEPTION
|
||||
$entityName,
|
||||
));
|
||||
}
|
||||
|
||||
public static function mappingVirtualPropertyNotAllowed(string $entityName, string $propertyName): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
'Mapping virtual property "%s" on entity "%s" is not allowed.',
|
||||
$propertyName,
|
||||
$entityName,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
53
src/Mapping/PropertyAccessors/EmbeddablePropertyAccessor.php
Normal file
53
src/Mapping/PropertyAccessors/EmbeddablePropertyAccessor.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Mapping\PropertyAccessors;
|
||||
|
||||
use Doctrine\Instantiator\Instantiator;
|
||||
use ReflectionProperty;
|
||||
|
||||
/** @internal */
|
||||
class EmbeddablePropertyAccessor implements PropertyAccessor
|
||||
{
|
||||
private static Instantiator|null $instantiator = null;
|
||||
|
||||
public function __construct(
|
||||
private PropertyAccessor $parent,
|
||||
private PropertyAccessor $child,
|
||||
/** @var class-string */
|
||||
private string $embeddedClass,
|
||||
) {
|
||||
}
|
||||
|
||||
public function setValue(object $object, mixed $value): void
|
||||
{
|
||||
$embeddedObject = $this->parent->getValue($object);
|
||||
|
||||
if ($embeddedObject === null) {
|
||||
self::$instantiator ??= new Instantiator();
|
||||
|
||||
$embeddedObject = self::$instantiator->instantiate($this->embeddedClass);
|
||||
|
||||
$this->parent->setValue($object, $embeddedObject);
|
||||
}
|
||||
|
||||
$this->child->setValue($embeddedObject, $value);
|
||||
}
|
||||
|
||||
public function getValue(object $object): mixed
|
||||
{
|
||||
$embeddedObject = $this->parent->getValue($object);
|
||||
|
||||
if ($embeddedObject === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->child->getValue($embeddedObject);
|
||||
}
|
||||
|
||||
public function getUnderlyingReflector(): ReflectionProperty
|
||||
{
|
||||
return $this->child->getUnderlyingReflector();
|
||||
}
|
||||
}
|
||||
85
src/Mapping/PropertyAccessors/EnumPropertyAccessor.php
Normal file
85
src/Mapping/PropertyAccessors/EnumPropertyAccessor.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Mapping\PropertyAccessors;
|
||||
|
||||
use BackedEnum;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function array_map;
|
||||
use function is_array;
|
||||
use function reset;
|
||||
|
||||
/** @internal */
|
||||
class EnumPropertyAccessor implements PropertyAccessor
|
||||
{
|
||||
/** @param class-string<BackedEnum> $enumType */
|
||||
public function __construct(private PropertyAccessor $parent, private string $enumType)
|
||||
{
|
||||
}
|
||||
|
||||
public function setValue(object $object, mixed $value): void
|
||||
{
|
||||
if ($value !== null) {
|
||||
$value = $this->toEnum($value);
|
||||
}
|
||||
|
||||
$this->parent->setValue($object, $value);
|
||||
}
|
||||
|
||||
public function getValue(object $object): mixed
|
||||
{
|
||||
$enum = $this->parent->getValue($object);
|
||||
|
||||
if ($enum === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->fromEnum($enum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BackedEnum|BackedEnum[] $enum
|
||||
*
|
||||
* @return ($enum is BackedEnum ? (string|int) : (string[]|int[]))
|
||||
*/
|
||||
private function fromEnum($enum) // phpcs:ignore
|
||||
{
|
||||
if (is_array($enum)) {
|
||||
return array_map(static function (BackedEnum $enum) {
|
||||
return $enum->value;
|
||||
}, $enum);
|
||||
}
|
||||
|
||||
return $enum->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param BackedEnum|BackedEnum[]|int|string|int[]|string[] $value
|
||||
*
|
||||
* @return ($value is int|string|BackedEnum ? BackedEnum : BackedEnum[])
|
||||
*/
|
||||
private function toEnum($value): BackedEnum|array
|
||||
{
|
||||
if ($value instanceof BackedEnum) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$v = reset($value);
|
||||
if ($v instanceof BackedEnum) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return array_map([$this->enumType, 'from'], $value);
|
||||
}
|
||||
|
||||
return $this->enumType::from($value);
|
||||
}
|
||||
|
||||
public function getUnderlyingReflector(): ReflectionProperty
|
||||
{
|
||||
return $this->parent->getUnderlyingReflector();
|
||||
}
|
||||
}
|
||||
61
src/Mapping/PropertyAccessors/ObjectCastPropertyAccessor.php
Normal file
61
src/Mapping/PropertyAccessors/ObjectCastPropertyAccessor.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Mapping\PropertyAccessors;
|
||||
|
||||
use Doctrine\ORM\Proxy\InternalProxy;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function ltrim;
|
||||
|
||||
/** @internal */
|
||||
class ObjectCastPropertyAccessor implements PropertyAccessor
|
||||
{
|
||||
/** @param class-string $class */
|
||||
public static function fromNames(string $class, string $name): self
|
||||
{
|
||||
$reflectionProperty = new ReflectionProperty($class, $name);
|
||||
|
||||
$key = $reflectionProperty->isPrivate() ? "\0" . ltrim($class, '\\') . "\0" . $name : ($reflectionProperty->isProtected() ? "\0*\0" . $name : $name);
|
||||
|
||||
return new self($reflectionProperty, $key);
|
||||
}
|
||||
|
||||
public static function fromReflectionProperty(ReflectionProperty $reflectionProperty): self
|
||||
{
|
||||
$name = $reflectionProperty->getName();
|
||||
$key = $reflectionProperty->isPrivate() ? "\0" . ltrim($reflectionProperty->getDeclaringClass()->getName(), '\\') . "\0" . $name : ($reflectionProperty->isProtected() ? "\0*\0" . $name : $name);
|
||||
|
||||
return new self($reflectionProperty, $key);
|
||||
}
|
||||
|
||||
private function __construct(private ReflectionProperty $reflectionProperty, private string $key)
|
||||
{
|
||||
}
|
||||
|
||||
public function setValue(object $object, mixed $value): void
|
||||
{
|
||||
if (! ($object instanceof InternalProxy && ! $object->__isInitialized())) {
|
||||
$this->reflectionProperty->setValue($object, $value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$object->__setInitialized(true);
|
||||
|
||||
$this->reflectionProperty->setValue($object, $value);
|
||||
|
||||
$object->__setInitialized(false);
|
||||
}
|
||||
|
||||
public function getValue(object $object): mixed
|
||||
{
|
||||
return ((array) $object)[$this->key] ?? null;
|
||||
}
|
||||
|
||||
public function getUnderlyingReflector(): ReflectionProperty
|
||||
{
|
||||
return $this->reflectionProperty;
|
||||
}
|
||||
}
|
||||
27
src/Mapping/PropertyAccessors/PropertyAccessor.php
Normal file
27
src/Mapping/PropertyAccessors/PropertyAccessor.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Mapping\PropertyAccessors;
|
||||
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* A property accessor is a class that allows to read and write properties on objects regardless of visibility.
|
||||
*
|
||||
* We use them while creating objects from database rows in {@link UnitOfWork::createEntity()} or when
|
||||
* computing changesets from objects that are about to be written back to the database in {@link UnitOfWork::computeChangeSet()}.
|
||||
*
|
||||
* This abstraction over ReflectionProperty is necessary, because for several features of either Doctrine or PHP, we
|
||||
* need to handle edge cases in reflection at a central location in the code.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface PropertyAccessor
|
||||
{
|
||||
public function setValue(object $object, mixed $value): void;
|
||||
|
||||
public function getValue(object $object): mixed;
|
||||
|
||||
public function getUnderlyingReflector(): ReflectionProperty;
|
||||
}
|
||||
32
src/Mapping/PropertyAccessors/PropertyAccessorFactory.php
Normal file
32
src/Mapping/PropertyAccessors/PropertyAccessorFactory.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Mapping\PropertyAccessors;
|
||||
|
||||
use ReflectionProperty;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
class PropertyAccessorFactory
|
||||
{
|
||||
/** @phpstan-param class-string $className */
|
||||
public static function createPropertyAccessor(string $className, string $propertyName): PropertyAccessor
|
||||
{
|
||||
$reflectionProperty = new ReflectionProperty($className, $propertyName);
|
||||
|
||||
$accessor = PHP_VERSION_ID >= 80400
|
||||
? RawValuePropertyAccessor::fromReflectionProperty($reflectionProperty)
|
||||
: ObjectCastPropertyAccessor::fromReflectionProperty($reflectionProperty);
|
||||
|
||||
if ($reflectionProperty->hasType() && ! $reflectionProperty->getType()->allowsNull()) {
|
||||
$accessor = new TypedNoDefaultPropertyAccessor($accessor, $reflectionProperty);
|
||||
}
|
||||
|
||||
if ($reflectionProperty->isReadOnly()) {
|
||||
$accessor = new ReadonlyAccessor($accessor, $reflectionProperty);
|
||||
}
|
||||
|
||||
return $accessor;
|
||||
}
|
||||
}
|
||||
63
src/Mapping/PropertyAccessors/RawValuePropertyAccessor.php
Normal file
63
src/Mapping/PropertyAccessors/RawValuePropertyAccessor.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Mapping\PropertyAccessors;
|
||||
|
||||
use Doctrine\ORM\Proxy\InternalProxy;
|
||||
use LogicException;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function ltrim;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* This is a PHP 8.4 and up only class and replaces ObjectCastPropertyAccessor.
|
||||
*
|
||||
* It works based on the raw values of a property, which for a case of property hooks
|
||||
* is the backed value. If we kept using setValue/getValue, this would go through the hooks,
|
||||
* which potentially change the data.
|
||||
*/
|
||||
class RawValuePropertyAccessor implements PropertyAccessor
|
||||
{
|
||||
public static function fromReflectionProperty(ReflectionProperty $reflectionProperty): self
|
||||
{
|
||||
$name = $reflectionProperty->getName();
|
||||
$key = $reflectionProperty->isPrivate() ? "\0" . ltrim($reflectionProperty->getDeclaringClass()->getName(), '\\') . "\0" . $name : ($reflectionProperty->isProtected() ? "\0*\0" . $name : $name);
|
||||
|
||||
return new self($reflectionProperty, $key);
|
||||
}
|
||||
|
||||
private function __construct(private ReflectionProperty $reflectionProperty, private string $key)
|
||||
{
|
||||
if (PHP_VERSION_ID < 80400) {
|
||||
throw new LogicException('This class requires PHP 8.4 or higher.');
|
||||
}
|
||||
}
|
||||
|
||||
public function setValue(object $object, mixed $value): void
|
||||
{
|
||||
if (! ($object instanceof InternalProxy && ! $object->__isInitialized())) {
|
||||
$this->reflectionProperty->setRawValueWithoutLazyInitialization($object, $value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$object->__setInitialized(true);
|
||||
|
||||
$this->reflectionProperty->setRawValue($object, $value);
|
||||
|
||||
$object->__setInitialized(false);
|
||||
}
|
||||
|
||||
public function getValue(object $object): mixed
|
||||
{
|
||||
return ((array) $object)[$this->key] ?? null;
|
||||
}
|
||||
|
||||
public function getUnderlyingReflector(): ReflectionProperty
|
||||
{
|
||||
return $this->reflectionProperty;
|
||||
}
|
||||
}
|
||||
53
src/Mapping/PropertyAccessors/ReadonlyAccessor.php
Normal file
53
src/Mapping/PropertyAccessors/ReadonlyAccessor.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Mapping\PropertyAccessors;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
/** @internal */
|
||||
class ReadonlyAccessor implements PropertyAccessor
|
||||
{
|
||||
public function __construct(private PropertyAccessor $parent, private ReflectionProperty $reflectionProperty)
|
||||
{
|
||||
if (! $this->reflectionProperty->isReadOnly()) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'%s::$%s must be readonly property',
|
||||
$this->reflectionProperty->getDeclaringClass()->getName(),
|
||||
$this->reflectionProperty->getName(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function setValue(object $object, mixed $value): void
|
||||
{
|
||||
if (! $this->reflectionProperty->isInitialized($object)) {
|
||||
$this->parent->setValue($object, $value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->parent->getValue($object) !== $value) {
|
||||
throw new LogicException(sprintf(
|
||||
'Attempting to change readonly property %s::$%s.',
|
||||
$this->reflectionProperty->getDeclaringClass()->getName(),
|
||||
$this->reflectionProperty->getName(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function getValue(object $object): mixed
|
||||
{
|
||||
return $this->parent->getValue($object);
|
||||
}
|
||||
|
||||
public function getUnderlyingReflector(): ReflectionProperty
|
||||
{
|
||||
return $this->reflectionProperty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Mapping\PropertyAccessors;
|
||||
|
||||
use Closure;
|
||||
use InvalidArgumentException;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function assert;
|
||||
use function sprintf;
|
||||
|
||||
/** @internal */
|
||||
class TypedNoDefaultPropertyAccessor implements PropertyAccessor
|
||||
{
|
||||
private Closure|null $unsetter = null;
|
||||
|
||||
public function __construct(private PropertyAccessor $parent, private ReflectionProperty $reflectionProperty)
|
||||
{
|
||||
if (! $this->reflectionProperty->hasType()) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'%s::$%s must have a type when used with TypedNoDefaultPropertyAccessor',
|
||||
$this->reflectionProperty->getDeclaringClass()->getName(),
|
||||
$this->reflectionProperty->getName(),
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->reflectionProperty->getType()->allowsNull()) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'%s::$%s must not be nullable when used with TypedNoDefaultPropertyAccessor',
|
||||
$this->reflectionProperty->getDeclaringClass()->getName(),
|
||||
$this->reflectionProperty->getName(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function setValue(object $object, mixed $value): void
|
||||
{
|
||||
if ($value === null) {
|
||||
if ($this->unsetter === null) {
|
||||
$propertyName = $this->reflectionProperty->getName();
|
||||
$this->unsetter = function () use ($propertyName): void {
|
||||
unset($this->$propertyName);
|
||||
};
|
||||
}
|
||||
|
||||
$unsetter = $this->unsetter->bindTo($object, $this->reflectionProperty->getDeclaringClass()->getName());
|
||||
|
||||
assert($unsetter instanceof Closure);
|
||||
|
||||
$unsetter();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->parent->setValue($object, $value);
|
||||
}
|
||||
|
||||
public function getValue(object $object): mixed
|
||||
{
|
||||
return $this->reflectionProperty->isInitialized($object) ? $this->parent->getValue($object) : null;
|
||||
}
|
||||
|
||||
public function getUnderlyingReflector(): ReflectionProperty
|
||||
{
|
||||
return $this->reflectionProperty;
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,10 @@ abstract class ToOneOwningSideMapping extends OwningSideMapping implements ToOne
|
||||
if (empty($joinColumn['name'])) {
|
||||
$mappingArray['joinColumns'][$index]['name'] = $namingStrategy->joinColumnName($mappingArray['fieldName'], $name);
|
||||
}
|
||||
|
||||
if (empty($joinColumn['referencedColumnName'])) {
|
||||
$mappingArray['joinColumns'][$index]['referencedColumnName'] = $namingStrategy->referenceColumnName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ EXCEPTION
|
||||
. ' configured to cascade persist operations for entity: ' . self::objToStr($entity) . '.'
|
||||
. ' To solve this issue: Either explicitly call EntityManager#persist()'
|
||||
. ' on this unknown entity or configure cascade persist'
|
||||
. ' this association in the mapping for example @ManyToOne(..,cascade={"persist"}).'
|
||||
. ' this association in the mapping for example #[ORM\ManyToOne(..., cascade: [\'persist\'])].'
|
||||
. ($entity instanceof Stringable
|
||||
? ''
|
||||
: ' If you cannot find out which entity causes the problem implement \''
|
||||
|
||||
@@ -140,7 +140,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
|
||||
if ($this->backRefFieldName && $this->getMapping()->isOneToMany()) {
|
||||
assert($this->typeClass !== null);
|
||||
// Set back reference to owner
|
||||
$this->typeClass->reflFields[$this->backRefFieldName]->setValue(
|
||||
$this->typeClass->propertyAccessors[$this->backRefFieldName]->setValue(
|
||||
$element,
|
||||
$this->owner,
|
||||
);
|
||||
@@ -166,7 +166,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
|
||||
if ($this->backRefFieldName && $this->getMapping()->isOneToMany()) {
|
||||
assert($this->typeClass !== null);
|
||||
// Set back reference to owner
|
||||
$this->typeClass->reflFields[$this->backRefFieldName]->setValue(
|
||||
$this->typeClass->propertyAccessors[$this->backRefFieldName]->setValue(
|
||||
$element,
|
||||
$this->owner,
|
||||
);
|
||||
|
||||
@@ -201,6 +201,16 @@ class BasicEntityPersister implements EntityPersister
|
||||
);
|
||||
}
|
||||
|
||||
final protected function isFilterHashUpToDate(): bool
|
||||
{
|
||||
return $this->filterHash === $this->em->getFilters()->getHash();
|
||||
}
|
||||
|
||||
final protected function updateFilterHash(): void
|
||||
{
|
||||
$this->filterHash = $this->em->getFilters()->getHash();
|
||||
}
|
||||
|
||||
public function getClassMetadata(): ClassMetadata
|
||||
{
|
||||
return $this->class;
|
||||
@@ -470,7 +480,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
|
||||
$where[] = $versionColumn;
|
||||
$types[] = $this->class->fieldMappings[$versionField]->type;
|
||||
$params[] = $this->class->reflFields[$versionField]->getValue($entity);
|
||||
$params[] = $this->class->propertyAccessors[$versionField]->getValue($entity);
|
||||
|
||||
switch ($versionFieldType) {
|
||||
case Types::SMALLINT:
|
||||
@@ -781,7 +791,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
|
||||
// Complete bidirectional association, if necessary
|
||||
if ($targetEntity !== null && $isInverseSingleValued) {
|
||||
$targetClass->reflFields[$assoc->inversedBy]->setValue($targetEntity, $sourceEntity);
|
||||
$targetClass->propertyAccessors[$assoc->inversedBy]->setValue($targetEntity, $sourceEntity);
|
||||
}
|
||||
|
||||
return $targetEntity;
|
||||
@@ -828,7 +838,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
}
|
||||
} else {
|
||||
$computedIdentifier[$targetClass->getFieldForColumn($targetKeyColumn)] =
|
||||
$sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
|
||||
$sourceClass->propertyAccessors[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1045,7 +1055,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
switch (true) {
|
||||
case $sourceClass->containsForeignIdentifier:
|
||||
$field = $sourceClass->getFieldForColumn($sourceKeyColumn);
|
||||
$value = $sourceClass->reflFields[$field]->getValue($sourceEntity);
|
||||
$value = $sourceClass->propertyAccessors[$field]->getValue($sourceEntity);
|
||||
|
||||
if (isset($sourceClass->associationMappings[$field])) {
|
||||
$value = $this->em->getUnitOfWork()->getEntityIdentifier($value);
|
||||
@@ -1056,7 +1066,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
|
||||
case isset($sourceClass->fieldNames[$sourceKeyColumn]):
|
||||
$field = $sourceClass->fieldNames[$sourceKeyColumn];
|
||||
$value = $sourceClass->reflFields[$field]->getValue($sourceEntity);
|
||||
$value = $sourceClass->propertyAccessors[$field]->getValue($sourceEntity);
|
||||
|
||||
break;
|
||||
|
||||
@@ -1231,7 +1241,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
*/
|
||||
protected function getSelectColumnsSQL(): string
|
||||
{
|
||||
if ($this->currentPersisterContext->selectColumnListSql !== null && $this->filterHash === $this->em->getFilters()->getHash()) {
|
||||
if ($this->currentPersisterContext->selectColumnListSql !== null && $this->isFilterHashUpToDate()) {
|
||||
return $this->currentPersisterContext->selectColumnListSql;
|
||||
}
|
||||
|
||||
@@ -1334,6 +1344,12 @@ class BasicEntityPersister implements EntityPersister
|
||||
$joinCondition[] = $this->getSQLTableAlias($association->sourceEntity, $assocAlias) . '.' . $sourceCol . ' = '
|
||||
. $this->getSQLTableAlias($association->targetEntity) . '.' . $targetCol;
|
||||
}
|
||||
|
||||
// Add filter SQL
|
||||
$filterSql = $this->generateFilterConditionSQL($eagerEntity, $joinTableAlias);
|
||||
if ($filterSql) {
|
||||
$joinCondition[] = $filterSql;
|
||||
}
|
||||
}
|
||||
|
||||
$this->currentPersisterContext->selectJoinSql .= ' ' . $joinTableName . ' ' . $joinTableAlias . ' ON ';
|
||||
@@ -1341,7 +1357,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
}
|
||||
|
||||
$this->currentPersisterContext->selectColumnListSql = implode(', ', $columnList);
|
||||
$this->filterHash = $this->em->getFilters()->getHash();
|
||||
$this->updateFilterHash();
|
||||
|
||||
return $this->currentPersisterContext->selectColumnListSql;
|
||||
}
|
||||
@@ -1454,7 +1470,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
{
|
||||
$columns = [];
|
||||
|
||||
foreach ($this->class->reflFields as $name => $field) {
|
||||
foreach ($this->class->propertyAccessors as $name => $field) {
|
||||
if ($this->class->isVersioned && $this->class->versionField === $name) {
|
||||
continue;
|
||||
}
|
||||
@@ -1500,7 +1516,15 @@ class BasicEntityPersister implements EntityPersister
|
||||
$tableAlias = $this->getSQLTableAlias($class->name, $root);
|
||||
$fieldMapping = $class->fieldMappings[$field];
|
||||
$sql = sprintf('%s.%s', $tableAlias, $this->quoteStrategy->getColumnName($field, $class, $this->platform));
|
||||
$columnAlias = $this->getSQLColumnAlias($fieldMapping->columnName);
|
||||
|
||||
$columnAlias = null;
|
||||
if ($this->currentPersisterContext->rsm->hasColumnAliasByField($alias, $field)) {
|
||||
$columnAlias = $this->currentPersisterContext->rsm->getColumnAliasByField($alias, $field);
|
||||
}
|
||||
|
||||
if ($columnAlias === null) {
|
||||
$columnAlias = $this->getSQLColumnAlias($fieldMapping->columnName);
|
||||
}
|
||||
|
||||
$this->currentPersisterContext->rsm->addFieldResult($alias, $columnAlias, $field);
|
||||
if (! empty($fieldMapping->enumType)) {
|
||||
@@ -1800,7 +1824,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
foreach ($owningAssoc->targetToSourceKeyColumns as $sourceKeyColumn => $targetKeyColumn) {
|
||||
if ($sourceClass->containsForeignIdentifier) {
|
||||
$field = $sourceClass->getFieldForColumn($sourceKeyColumn);
|
||||
$value = $sourceClass->reflFields[$field]->getValue($sourceEntity);
|
||||
$value = $sourceClass->propertyAccessors[$field]->getValue($sourceEntity);
|
||||
|
||||
if (isset($sourceClass->associationMappings[$field])) {
|
||||
$value = $this->em->getUnitOfWork()->getEntityIdentifier($value);
|
||||
@@ -1818,7 +1842,7 @@ class BasicEntityPersister implements EntityPersister
|
||||
}
|
||||
|
||||
$field = $sourceClass->fieldNames[$sourceKeyColumn];
|
||||
$value = $sourceClass->reflFields[$field]->getValue($sourceEntity);
|
||||
$value = $sourceClass->propertyAccessors[$field]->getValue($sourceEntity);
|
||||
|
||||
$criteria[$tableAlias . '.' . $targetKeyColumn] = $value;
|
||||
$parameters[] = [
|
||||
|
||||
@@ -358,7 +358,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
protected function getSelectColumnsSQL(): string
|
||||
{
|
||||
// Create the column list fragment only once
|
||||
if ($this->currentPersisterContext->selectColumnListSql !== null) {
|
||||
if ($this->currentPersisterContext->selectColumnListSql !== null && $this->isFilterHashUpToDate()) {
|
||||
return $this->currentPersisterContext->selectColumnListSql;
|
||||
}
|
||||
|
||||
@@ -445,6 +445,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
}
|
||||
|
||||
$this->currentPersisterContext->selectColumnListSql = implode(', ', $columnList);
|
||||
$this->updateFilterHash();
|
||||
|
||||
return $this->currentPersisterContext->selectColumnListSql;
|
||||
}
|
||||
@@ -459,7 +460,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
? $this->class->getIdentifierColumnNames()
|
||||
: [];
|
||||
|
||||
foreach ($this->class->reflFields as $name => $field) {
|
||||
foreach ($this->class->propertyAccessors as $name => $field) {
|
||||
if (
|
||||
isset($this->class->fieldMappings[$name]->inherited)
|
||||
&& ! isset($this->class->fieldMappings[$name]->id)
|
||||
|
||||
@@ -35,7 +35,7 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
|
||||
protected function getSelectColumnsSQL(): string
|
||||
{
|
||||
$columnList = [];
|
||||
if ($this->currentPersisterContext->selectColumnListSql !== null) {
|
||||
if ($this->currentPersisterContext->selectColumnListSql !== null && $this->isFilterHashUpToDate()) {
|
||||
return $this->currentPersisterContext->selectColumnListSql;
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
|
||||
}
|
||||
|
||||
$this->currentPersisterContext->selectColumnListSql = implode(', ', $columnList);
|
||||
$this->updateFilterHash();
|
||||
|
||||
return $this->currentPersisterContext->selectColumnListSql;
|
||||
}
|
||||
|
||||
@@ -13,16 +13,19 @@ use Doctrine\ORM\UnitOfWork;
|
||||
use Doctrine\ORM\Utility\IdentifierFlattener;
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Persistence\Proxy;
|
||||
use LogicException;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
use Symfony\Component\VarExporter\ProxyHelper;
|
||||
|
||||
use function array_combine;
|
||||
use function array_flip;
|
||||
use function array_intersect_key;
|
||||
use function array_keys;
|
||||
use function assert;
|
||||
use function bin2hex;
|
||||
use function chmod;
|
||||
use function class_exists;
|
||||
use function count;
|
||||
use function dirname;
|
||||
use function file_exists;
|
||||
use function file_put_contents;
|
||||
@@ -37,6 +40,7 @@ use function preg_match_all;
|
||||
use function random_bytes;
|
||||
use function rename;
|
||||
use function rtrim;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function strpos;
|
||||
use function strrpos;
|
||||
@@ -45,6 +49,7 @@ use function substr;
|
||||
use function ucfirst;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* This factory is used to create proxy objects for entities at runtime.
|
||||
@@ -127,6 +132,9 @@ EOPHP;
|
||||
/** @var array<class-string, Closure> */
|
||||
private array $proxyFactories = [];
|
||||
|
||||
private readonly string $proxyDir;
|
||||
private readonly string $proxyNs;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the <tt>ProxyFactory</tt> class that is
|
||||
* connected to the given <tt>EntityManager</tt>.
|
||||
@@ -138,15 +146,15 @@ EOPHP;
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly string $proxyDir,
|
||||
private readonly string $proxyNs,
|
||||
string|null $proxyDir = null,
|
||||
string|null $proxyNs = null,
|
||||
bool|int $autoGenerate = self::AUTOGENERATE_NEVER,
|
||||
) {
|
||||
if (! $proxyDir) {
|
||||
if (! $proxyDir && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
throw ORMInvalidArgumentException::proxyDirectoryRequired();
|
||||
}
|
||||
|
||||
if (! $proxyNs) {
|
||||
if (! $proxyNs && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
throw ORMInvalidArgumentException::proxyNamespaceRequired();
|
||||
}
|
||||
|
||||
@@ -154,6 +162,17 @@ EOPHP;
|
||||
throw ORMInvalidArgumentException::invalidAutoGenerateMode($autoGenerate);
|
||||
}
|
||||
|
||||
if ($proxyDir === null && $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
$proxyDir = '';
|
||||
}
|
||||
|
||||
if ($proxyNs === null && $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
$proxyNs = '';
|
||||
}
|
||||
|
||||
$this->proxyDir = $proxyDir;
|
||||
$this->proxyNs = $proxyNs;
|
||||
|
||||
$this->uow = $em->getUnitOfWork();
|
||||
$this->autoGenerate = (int) $autoGenerate;
|
||||
$this->identifierFlattener = new IdentifierFlattener($this->uow, $em->getMetadataFactory());
|
||||
@@ -163,8 +182,35 @@ EOPHP;
|
||||
* @param class-string $className
|
||||
* @param array<mixed> $identifier
|
||||
*/
|
||||
public function getProxy(string $className, array $identifier): InternalProxy
|
||||
public function getProxy(string $className, array $identifier): object
|
||||
{
|
||||
if ($this->em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
$classMetadata = $this->em->getClassMetadata($className);
|
||||
$entityPersister = $this->uow->getEntityPersister($className);
|
||||
$identifierFlattener = $this->identifierFlattener;
|
||||
|
||||
$proxy = $classMetadata->reflClass->newLazyGhost(static function (object $object) use (
|
||||
$identifier,
|
||||
$entityPersister,
|
||||
$identifierFlattener,
|
||||
$classMetadata,
|
||||
): void {
|
||||
$original = $entityPersister->loadById($identifier, $object);
|
||||
if ($original === null) {
|
||||
throw EntityNotFoundException::fromClassNameAndIdentifier(
|
||||
$classMetadata->getName(),
|
||||
$identifierFlattener->flattenIdentifier($classMetadata, $identifier),
|
||||
);
|
||||
}
|
||||
}, ReflectionClass::SKIP_INITIALIZATION_ON_SERIALIZE);
|
||||
|
||||
foreach ($identifier as $idField => $value) {
|
||||
$classMetadata->propertyAccessors[$idField]->setValue($proxy, $value);
|
||||
}
|
||||
|
||||
return $proxy;
|
||||
}
|
||||
|
||||
$proxyFactory = $this->proxyFactories[$className] ?? $this->getProxyFactory($className);
|
||||
|
||||
return $proxyFactory($identifier);
|
||||
@@ -182,6 +228,10 @@ EOPHP;
|
||||
*/
|
||||
public function generateProxyClasses(array $classes, string|null $proxyDir = null): int
|
||||
{
|
||||
if ($this->em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$generated = 0;
|
||||
|
||||
foreach ($classes as $class) {
|
||||
@@ -232,8 +282,8 @@ EOPHP;
|
||||
|
||||
$class = $entityPersister->getClassMetadata();
|
||||
|
||||
foreach ($class->getReflectionProperties() as $property) {
|
||||
if (! $property || isset($identifier[$property->getName()]) || ! $class->hasField($property->getName()) && ! $class->hasAssociation($property->getName())) {
|
||||
foreach ($class->getPropertyAccessors() as $name => $property) {
|
||||
if (isset($identifier[$name])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -262,7 +312,15 @@ EOPHP;
|
||||
foreach ($reflector->getProperties($filter) as $property) {
|
||||
$name = $property->name;
|
||||
|
||||
if ($property->isStatic() || (($class->hasField($name) || $class->hasAssociation($name)) && ! isset($identifiers[$name]))) {
|
||||
if (PHP_VERSION_ID >= 80400 && count($property->getHooks()) > 0) {
|
||||
throw new LogicException(sprintf(
|
||||
'Doctrine ORM does not support property hook on %s::%s without using native lazy objects. Check https://github.com/doctrine/orm/issues/11624 for details of versions that support property hooks.',
|
||||
$property->getDeclaringClass()->getName(),
|
||||
$property->getName(),
|
||||
));
|
||||
}
|
||||
|
||||
if ($property->isStatic() || ! isset($identifiers[$name])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -279,7 +337,11 @@ EOPHP;
|
||||
$entityPersister = $this->uow->getEntityPersister($className);
|
||||
$initializer = $this->createLazyInitializer($class, $entityPersister, $this->identifierFlattener);
|
||||
$proxyClassName = $this->loadProxyClass($class);
|
||||
$identifierFields = array_intersect_key($class->getReflectionProperties(), $identifiers);
|
||||
$identifierFields = [];
|
||||
|
||||
foreach (array_keys($identifiers) as $identifier) {
|
||||
$identifierFields[$identifier] = $class->getPropertyAccessor($identifier);
|
||||
}
|
||||
|
||||
$proxyFactory = Closure::bind(static function (array $identifier) use ($initializer, $skippedProperties, $identifierFields, $className): InternalProxy {
|
||||
$proxy = self::createLazyGhost(static function (InternalProxy $object) use ($initializer, $identifier): void {
|
||||
@@ -383,6 +445,7 @@ EOPHP;
|
||||
|
||||
private function generateUseLazyGhostTrait(ClassMetadata $class): string
|
||||
{
|
||||
// @phpstan-ignore staticMethod.deprecated (Because we support Symfony < 7.3)
|
||||
$code = ProxyHelper::generateLazyGhost($class->getReflectionClass());
|
||||
$code = substr($code, 7 + (int) strpos($code, "\n{"));
|
||||
$code = substr($code, 0, (int) strpos($code, "\n}"));
|
||||
|
||||
26
src/Query/AST/EntityAsDtoArgumentExpression.php
Normal file
26
src/Query/AST/EntityAsDtoArgumentExpression.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Query\AST;
|
||||
|
||||
use Doctrine\ORM\Query\SqlWalker;
|
||||
|
||||
/**
|
||||
* EntityAsDtoArgumentExpression ::= IdentificationVariable
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
class EntityAsDtoArgumentExpression extends Node
|
||||
{
|
||||
public function __construct(
|
||||
public mixed $expression,
|
||||
public string|null $identificationVariable,
|
||||
) {
|
||||
}
|
||||
|
||||
public function dispatch(SqlWalker $walker): string
|
||||
{
|
||||
return $walker->walkEntityAsDtoArgumentExpression($this);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ namespace Doctrine\ORM\Query\AST;
|
||||
|
||||
use Doctrine\ORM\Query\SqlWalker;
|
||||
|
||||
use function func_get_arg;
|
||||
use function func_num_args;
|
||||
|
||||
/**
|
||||
* NewObjectExpression ::= "NEW" IdentificationVariable "(" NewObjectArg {"," NewObjectArg}* ")"
|
||||
*
|
||||
@@ -13,13 +16,18 @@ use Doctrine\ORM\Query\SqlWalker;
|
||||
*/
|
||||
class NewObjectExpression extends Node
|
||||
{
|
||||
/** @param mixed[] $args */
|
||||
/**
|
||||
* @param class-string $className
|
||||
* @param mixed[] $args
|
||||
*/
|
||||
public function __construct(public string $className, public array $args)
|
||||
{
|
||||
}
|
||||
|
||||
public function dispatch(SqlWalker $walker): string
|
||||
public function dispatch(SqlWalker $walker /*, string|null $parentAlias = null */): string
|
||||
{
|
||||
return $walker->walkNewObject($this);
|
||||
$parentAlias = func_num_args() > 1 ? func_get_arg(1) : null;
|
||||
|
||||
return $walker->walkNewObject($this, $parentAlias);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1106,6 +1106,50 @@ final class Parser
|
||||
return $this->PathExpression(AST\PathExpression::TYPE_COLLECTION_VALUED_ASSOCIATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* EntityAsDtoArgumentExpression ::= IdentificationVariable
|
||||
*/
|
||||
public function EntityAsDtoArgumentExpression(): AST\EntityAsDtoArgumentExpression
|
||||
{
|
||||
assert($this->lexer->lookahead !== null);
|
||||
$expression = null;
|
||||
$identVariable = null;
|
||||
$peek = $this->lexer->glimpse();
|
||||
$lookaheadType = $this->lexer->lookahead->type;
|
||||
assert($peek !== null);
|
||||
|
||||
assert($lookaheadType === TokenType::T_IDENTIFIER);
|
||||
assert($peek->type !== TokenType::T_DOT);
|
||||
assert($peek->type !== TokenType::T_OPEN_PARENTHESIS);
|
||||
|
||||
$expression = $identVariable = $this->IdentificationVariable();
|
||||
|
||||
// [["AS"] AliasResultVariable]
|
||||
$mustHaveAliasResultVariable = false;
|
||||
|
||||
if ($this->lexer->isNextToken(TokenType::T_AS)) {
|
||||
$this->match(TokenType::T_AS);
|
||||
|
||||
$mustHaveAliasResultVariable = true;
|
||||
}
|
||||
|
||||
$aliasResultVariable = null;
|
||||
|
||||
if ($mustHaveAliasResultVariable || $this->lexer->isNextToken(TokenType::T_IDENTIFIER)) {
|
||||
$token = $this->lexer->lookahead;
|
||||
$aliasResultVariable = $this->AliasResultVariable();
|
||||
|
||||
// Include AliasResultVariable in query components.
|
||||
$this->queryComponents[$aliasResultVariable] = [
|
||||
'resultVariable' => $expression,
|
||||
'nestingLevel' => $this->nestingLevel,
|
||||
'token' => $token,
|
||||
];
|
||||
}
|
||||
|
||||
return new AST\EntityAsDtoArgumentExpression($expression, $identVariable);
|
||||
}
|
||||
|
||||
/**
|
||||
* SelectClause ::= "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression}
|
||||
*/
|
||||
@@ -1767,6 +1811,7 @@ final class Parser
|
||||
$useNamedArguments = true;
|
||||
}
|
||||
|
||||
/** @var class-string $className */
|
||||
$className = $this->AbstractSchemaName(); // note that this is not yet validated
|
||||
$token = $this->lexer->token;
|
||||
|
||||
@@ -1848,13 +1893,19 @@ final class Parser
|
||||
$this->match(TokenType::T_CLOSE_PARENTHESIS);
|
||||
} elseif ($token->type === TokenType::T_NEW) {
|
||||
$expression = $this->NewObjectExpression();
|
||||
} elseif ($token->type === TokenType::T_IDENTIFIER && $peek->type !== TokenType::T_DOT && $peek->type !== TokenType::T_OPEN_PARENTHESIS) {
|
||||
$expression = $this->EntityAsDtoArgumentExpression();
|
||||
} else {
|
||||
$expression = $this->ScalarExpression();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(TokenType::T_AS)) {
|
||||
$this->match(TokenType::T_AS);
|
||||
$fieldAlias = $this->AliasIdentificationVariable();
|
||||
$this->match(TokenType::T_IDENTIFIER);
|
||||
|
||||
assert($this->lexer->token !== null);
|
||||
|
||||
$fieldAlias = $this->lexer->token->value;
|
||||
}
|
||||
|
||||
return $expression;
|
||||
|
||||
@@ -66,6 +66,13 @@ class ResultSetMapping
|
||||
*/
|
||||
public array $fieldMappings = [];
|
||||
|
||||
/**
|
||||
* Map field names for each class to alias
|
||||
*
|
||||
* @var array<class-string, array<string, array<string, string>>>
|
||||
*/
|
||||
public array $columnAliasMappings = [];
|
||||
|
||||
/**
|
||||
* Maps column names in the result set to the alias/field name to use in the mapped result.
|
||||
*
|
||||
@@ -152,10 +159,17 @@ class ResultSetMapping
|
||||
*/
|
||||
public array $newObjectMappings = [];
|
||||
|
||||
/**
|
||||
* Maps object Ids in the result set to classnames.
|
||||
*
|
||||
* @phpstan-var array<string|int, class-string>
|
||||
*/
|
||||
public array $newObject = [];
|
||||
|
||||
/**
|
||||
* Maps last argument for new objects in order to initiate object construction
|
||||
*
|
||||
* @phpstan-var array<int|string, array{ownerIndex: string|int, argIndex: int|string}>
|
||||
* @phpstan-var array<int|string, array{ownerIndex: string|int, argIndex: int|string, argAlias: string}>
|
||||
*/
|
||||
public array $nestedNewObjectArguments = [];
|
||||
|
||||
@@ -173,6 +187,13 @@ class ResultSetMapping
|
||||
*/
|
||||
public array $discriminatorParameters = [];
|
||||
|
||||
/**
|
||||
* Entities nested in Dto's
|
||||
*
|
||||
* @phpstan-var array<string, array<string, (int|string)>>
|
||||
*/
|
||||
public array $nestedEntities = [];
|
||||
|
||||
/**
|
||||
* Adds an entity result to this ResultSetMapping.
|
||||
*
|
||||
@@ -328,7 +349,10 @@ class ResultSetMapping
|
||||
// column name => alias of owner
|
||||
$this->columnOwnerMap[$columnName] = $alias;
|
||||
// field name => class name of declaring class
|
||||
$this->declaringClasses[$columnName] = $declaringClass ?: $this->aliasMap[$alias];
|
||||
$declaringClass = $declaringClass ?: $this->aliasMap[$alias];
|
||||
$this->declaringClasses[$columnName] = $declaringClass;
|
||||
|
||||
$this->columnAliasMappings[$declaringClass][$alias][$fieldName] = $columnName;
|
||||
|
||||
if (! $this->isMixed && $this->scalarMappings) {
|
||||
$this->isMixed = true;
|
||||
@@ -337,6 +361,20 @@ class ResultSetMapping
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasColumnAliasByField(string $alias, string $fieldName): bool
|
||||
{
|
||||
$declaringClass = $this->aliasMap[$alias];
|
||||
|
||||
return isset($this->columnAliasMappings[$declaringClass][$alias][$fieldName]);
|
||||
}
|
||||
|
||||
public function getColumnAliasByField(string $alias, string $fieldName): string
|
||||
{
|
||||
$declaringClass = $this->aliasMap[$alias];
|
||||
|
||||
return $this->columnAliasMappings[$declaringClass][$alias][$fieldName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a joined entity result.
|
||||
*
|
||||
|
||||
@@ -24,10 +24,8 @@ use function array_filter;
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function array_pop;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function end;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
@@ -84,13 +82,6 @@ class SqlWalker
|
||||
*/
|
||||
private int $newObjectCounter = 0;
|
||||
|
||||
/**
|
||||
* Contains nesting levels of new objects arguments
|
||||
*
|
||||
* @phpstan-var array<int, array{0: string|int, 1: int}>
|
||||
*/
|
||||
private array $newObjectStack = [];
|
||||
|
||||
private readonly EntityManagerInterface $em;
|
||||
private readonly Connection $conn;
|
||||
|
||||
@@ -584,6 +575,14 @@ class SqlWalker
|
||||
return implode(', ', $sqlParts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks down an EntityAsDtoArgumentExpression AST node, thereby generating the appropriate SQL.
|
||||
*/
|
||||
public function walkEntityAsDtoArgumentExpression(AST\EntityAsDtoArgumentExpression $expr): string
|
||||
{
|
||||
return implode(', ', $this->walkObjectExpression($expr->expression, [], $expr->identificationVariable ?: null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks down an IdentificationVariable (no AST node associated), thereby generating the SQL.
|
||||
*/
|
||||
@@ -1365,32 +1364,79 @@ class SqlWalker
|
||||
$partialFieldSet = [];
|
||||
}
|
||||
|
||||
$class = $this->getMetadataForDqlAlias($dqlAlias);
|
||||
$resultAlias = $selectExpression->fieldIdentificationVariable ?: null;
|
||||
$sql .= implode(', ', $this->walkObjectExpression($dqlAlias, $partialFieldSet, $selectExpression->fieldIdentificationVariable ?: null));
|
||||
}
|
||||
|
||||
if (! isset($this->selectedClasses[$dqlAlias])) {
|
||||
$this->selectedClasses[$dqlAlias] = [
|
||||
'class' => $class,
|
||||
'dqlAlias' => $dqlAlias,
|
||||
'resultAlias' => $resultAlias,
|
||||
];
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
$sqlParts = [];
|
||||
/**
|
||||
* Walks down an Object Expression AST node and return Sql Parts
|
||||
*
|
||||
* @param mixed[] $partialFieldSet
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function walkObjectExpression(string $dqlAlias, array $partialFieldSet, string|null $resultAlias): array
|
||||
{
|
||||
$class = $this->getMetadataForDqlAlias($dqlAlias);
|
||||
|
||||
// Select all fields from the queried class
|
||||
foreach ($class->fieldMappings as $fieldName => $mapping) {
|
||||
if ($partialFieldSet && ! in_array($fieldName, $partialFieldSet, true)) {
|
||||
if (! isset($this->selectedClasses[$dqlAlias])) {
|
||||
$this->selectedClasses[$dqlAlias] = [
|
||||
'class' => $class,
|
||||
'dqlAlias' => $dqlAlias,
|
||||
'resultAlias' => $resultAlias,
|
||||
];
|
||||
}
|
||||
|
||||
$sqlParts = [];
|
||||
|
||||
// Select all fields from the queried class
|
||||
foreach ($class->fieldMappings as $fieldName => $mapping) {
|
||||
if ($partialFieldSet && ! in_array($fieldName, $partialFieldSet, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tableName = isset($mapping->inherited)
|
||||
? $this->em->getClassMetadata($mapping->inherited)->getTableName()
|
||||
: $class->getTableName();
|
||||
|
||||
$sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias);
|
||||
$columnAlias = $this->getSQLColumnAlias($mapping->columnName);
|
||||
$quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform);
|
||||
|
||||
$col = $sqlTableAlias . '.' . $quotedColumnName;
|
||||
|
||||
$type = Type::getType($mapping->type);
|
||||
$col = $type->convertToPHPValueSQL($col, $this->platform);
|
||||
|
||||
$sqlParts[] = $col . ' AS ' . $columnAlias;
|
||||
|
||||
$this->scalarResultAliasMap[$resultAlias][] = $columnAlias;
|
||||
|
||||
$this->rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name);
|
||||
|
||||
if (! empty($mapping->enumType)) {
|
||||
$this->rsm->addEnumResult($columnAlias, $mapping->enumType);
|
||||
}
|
||||
}
|
||||
|
||||
// Add any additional fields of subclasses (excluding inherited fields)
|
||||
// 1) on Single Table Inheritance: always, since its marginal overhead
|
||||
// 2) on Class Table Inheritance only if partial objects are disallowed,
|
||||
// since it requires outer joining subtables.
|
||||
if ($class->isInheritanceTypeSingleTable() || ! $this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) {
|
||||
foreach ($class->subClasses as $subClassName) {
|
||||
$subClass = $this->em->getClassMetadata($subClassName);
|
||||
$sqlTableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias);
|
||||
|
||||
foreach ($subClass->fieldMappings as $fieldName => $mapping) {
|
||||
if (isset($mapping->inherited) || ($partialFieldSet && ! in_array($fieldName, $partialFieldSet, true))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tableName = isset($mapping->inherited)
|
||||
? $this->em->getClassMetadata($mapping->inherited)->getTableName()
|
||||
: $class->getTableName();
|
||||
|
||||
$sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias);
|
||||
$columnAlias = $this->getSQLColumnAlias($mapping->columnName);
|
||||
$quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform);
|
||||
$quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $subClass, $this->platform);
|
||||
|
||||
$col = $sqlTableAlias . '.' . $quotedColumnName;
|
||||
|
||||
@@ -1401,48 +1447,12 @@ class SqlWalker
|
||||
|
||||
$this->scalarResultAliasMap[$resultAlias][] = $columnAlias;
|
||||
|
||||
$this->rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name);
|
||||
|
||||
if (! empty($mapping->enumType)) {
|
||||
$this->rsm->addEnumResult($columnAlias, $mapping->enumType);
|
||||
}
|
||||
$this->rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $subClassName);
|
||||
}
|
||||
|
||||
// Add any additional fields of subclasses (excluding inherited fields)
|
||||
// 1) on Single Table Inheritance: always, since its marginal overhead
|
||||
// 2) on Class Table Inheritance only if partial objects are disallowed,
|
||||
// since it requires outer joining subtables.
|
||||
if ($class->isInheritanceTypeSingleTable() || ! $this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) {
|
||||
foreach ($class->subClasses as $subClassName) {
|
||||
$subClass = $this->em->getClassMetadata($subClassName);
|
||||
$sqlTableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias);
|
||||
|
||||
foreach ($subClass->fieldMappings as $fieldName => $mapping) {
|
||||
if (isset($mapping->inherited) || ($partialFieldSet && ! in_array($fieldName, $partialFieldSet, true))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columnAlias = $this->getSQLColumnAlias($mapping->columnName);
|
||||
$quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $subClass, $this->platform);
|
||||
|
||||
$col = $sqlTableAlias . '.' . $quotedColumnName;
|
||||
|
||||
$type = Type::getType($mapping->type);
|
||||
$col = $type->convertToPHPValueSQL($col, $this->platform);
|
||||
|
||||
$sqlParts[] = $col . ' AS ' . $columnAlias;
|
||||
|
||||
$this->scalarResultAliasMap[$resultAlias][] = $columnAlias;
|
||||
|
||||
$this->rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $subClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= implode(', ', $sqlParts);
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
return $sqlParts;
|
||||
}
|
||||
|
||||
public function walkQuantifiedExpression(AST\QuantifiedExpression $qExpr): string
|
||||
@@ -1507,14 +1517,7 @@ class SqlWalker
|
||||
public function walkNewObject(AST\NewObjectExpression $newObjectExpression, string|null $newObjectResultAlias = null): string
|
||||
{
|
||||
$sqlSelectExpressions = [];
|
||||
$objOwner = $objOwnerIdx = null;
|
||||
|
||||
if ($this->newObjectStack !== []) {
|
||||
[$objOwner, $objOwnerIdx] = end($this->newObjectStack);
|
||||
$objIndex = $objOwner . ':' . $objOwnerIdx;
|
||||
} else {
|
||||
$objIndex = $newObjectResultAlias ?: $this->newObjectCounter++;
|
||||
}
|
||||
$objIndex = $newObjectResultAlias ?: $this->newObjectCounter++;
|
||||
|
||||
foreach ($newObjectExpression->args as $argIndex => $e) {
|
||||
$resultAlias = $this->scalarResultCounter++;
|
||||
@@ -1523,10 +1526,8 @@ class SqlWalker
|
||||
|
||||
switch (true) {
|
||||
case $e instanceof AST\NewObjectExpression:
|
||||
$this->newObjectStack[] = [$objIndex, $argIndex];
|
||||
$sqlSelectExpressions[] = $e->dispatch($this);
|
||||
array_pop($this->newObjectStack);
|
||||
$this->rsm->nestedNewObjectArguments[$columnAlias] = ['ownerIndex' => $objIndex, 'argIndex' => $argIndex];
|
||||
$sqlSelectExpressions[] = $e->dispatch($this, $columnAlias);
|
||||
$this->rsm->nestedNewObjectArguments[$columnAlias] = ['ownerIndex' => $objIndex, 'argIndex' => $argIndex, 'argAlias' => $columnAlias];
|
||||
break;
|
||||
|
||||
case $e instanceof AST\Subselect:
|
||||
@@ -1567,6 +1568,14 @@ class SqlWalker
|
||||
$sqlSelectExpressions[] = trim($e->dispatch($this)) . ' AS ' . $columnAlias;
|
||||
break;
|
||||
|
||||
case $e instanceof AST\EntityAsDtoArgumentExpression:
|
||||
$alias = $e->identificationVariable ?: $columnAlias;
|
||||
$this->rsm->nestedNewObjectArguments[$columnAlias] = ['ownerIndex' => $objIndex, 'argIndex' => $argIndex, 'argAlias' => $alias];
|
||||
$this->rsm->nestedEntities[$alias] = ['parent' => $objIndex, 'argIndex' => $argIndex, 'type' => 'entity'];
|
||||
|
||||
$sqlSelectExpressions[] = trim($e->dispatch($this));
|
||||
break;
|
||||
|
||||
default:
|
||||
$sqlSelectExpressions[] = trim($e->dispatch($this)) . ' AS ' . $columnAlias;
|
||||
break;
|
||||
@@ -1576,12 +1585,13 @@ class SqlWalker
|
||||
$this->rsm->addScalarResult($columnAlias, $resultAlias, $fieldType);
|
||||
|
||||
$this->rsm->newObjectMappings[$columnAlias] = [
|
||||
'className' => $newObjectExpression->className,
|
||||
'objIndex' => $objIndex,
|
||||
'argIndex' => $argIndex,
|
||||
];
|
||||
}
|
||||
|
||||
$this->rsm->newObject[$objIndex] = $newObjectExpression->className;
|
||||
|
||||
return implode(', ', $sqlSelectExpressions);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\DBAL\ArrayParameterType;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Doctrine\ORM\Internal\NoUnknownNamedArguments;
|
||||
use Doctrine\ORM\Internal\QueryType;
|
||||
use Doctrine\ORM\Query\Expr;
|
||||
use Doctrine\ORM\Query\Parameter;
|
||||
use Doctrine\ORM\Query\QueryExpressionVisitor;
|
||||
@@ -128,6 +127,11 @@ class QueryBuilder implements Stringable
|
||||
$this->parameters = new ArrayCollection();
|
||||
}
|
||||
|
||||
final protected function getType(): QueryType
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an ExpressionBuilder used for object-oriented construction of query expressions.
|
||||
* This producer method is intended for convenient inline usage. Example:
|
||||
@@ -504,7 +508,7 @@ class QueryBuilder implements Stringable
|
||||
$key = Parameter::normalizeName($key);
|
||||
|
||||
$filteredParameters = $this->parameters->filter(
|
||||
static fn (Parameter $parameter): bool => $key === $parameter->getName()
|
||||
static fn (Parameter $parameter): bool => $key === $parameter->getName(),
|
||||
);
|
||||
|
||||
return ! $filteredParameters->isEmpty() ? $filteredParameters->first() : null;
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Internal;
|
||||
namespace Doctrine\ORM;
|
||||
|
||||
/** @internal To be used inside the QueryBuilder only. */
|
||||
enum QueryType
|
||||
{
|
||||
case Select;
|
||||
28
src/Tools/Console/ApplicationCompatibility.php
Normal file
28
src/Tools/Console/ApplicationCompatibility.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
use function method_exists;
|
||||
|
||||
/**
|
||||
* Forward compatibility with Symfony Console 7.4
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
trait ApplicationCompatibility
|
||||
{
|
||||
private static function addCommandToApplication(Application $application, Command $command): Command|null
|
||||
{
|
||||
if (method_exists(Application::class, 'addCommand')) {
|
||||
// @phpstan-ignore method.notFound (This method will be added in Symfony 7.4)
|
||||
return $application->addCommand($command);
|
||||
}
|
||||
|
||||
return $application->add($command);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ EOT);
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$entityManager = $this->getEntityManager($input);
|
||||
|
||||
@@ -43,7 +43,7 @@ EOT);
|
||||
->getAllClassNames();
|
||||
|
||||
if (! $entityClassNames) {
|
||||
$ui->caution(
|
||||
$ui->getErrorStyle()->caution(
|
||||
[
|
||||
'You do not have any mapped Doctrine ORM entities according to the current configuration.',
|
||||
'If you have entities or mapping files you should check your mapping configuration for errors.',
|
||||
|
||||
@@ -64,7 +64,7 @@ EOT);
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$entityManager = $this->getEntityManager($input);
|
||||
|
||||
@@ -162,7 +162,7 @@ EOT);
|
||||
|
||||
$matches = array_filter(
|
||||
$this->getMappedEntities($entityManager),
|
||||
static fn ($mappedEntity) => preg_match('{' . preg_quote($entityName) . '}', $mappedEntity)
|
||||
static fn ($mappedEntity) => preg_match('{' . preg_quote($entityName) . '}', $mappedEntity),
|
||||
);
|
||||
|
||||
if (! $matches) {
|
||||
|
||||
@@ -19,6 +19,8 @@ use function class_exists;
|
||||
*/
|
||||
final class ConsoleRunner
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/**
|
||||
* Runs console with the given helper set.
|
||||
*
|
||||
@@ -59,7 +61,10 @@ final class ConsoleRunner
|
||||
$connectionProvider = new ConnectionFromManagerProvider($entityManagerProvider);
|
||||
|
||||
if (class_exists(DBALConsole\Command\ReservedWordsCommand::class)) {
|
||||
$cli->add(new DBALConsole\Command\ReservedWordsCommand($connectionProvider));
|
||||
self::addCommandToApplication(
|
||||
$cli,
|
||||
new DBALConsole\Command\ReservedWordsCommand($connectionProvider),
|
||||
);
|
||||
}
|
||||
|
||||
$cli->addCommands(
|
||||
|
||||
@@ -89,17 +89,24 @@ class LimitSubqueryOutputWalker extends SqlOutputWalker
|
||||
$this->platform = $query->getEntityManager()->getConnection()->getDatabasePlatform();
|
||||
$this->rsm = $parserResult->getResultSetMapping();
|
||||
|
||||
$query = clone $query;
|
||||
$cloneQuery = clone $query;
|
||||
|
||||
$cloneQuery->setParameters(clone $query->getParameters());
|
||||
$cloneQuery->setCacheable(false);
|
||||
|
||||
foreach ($query->getHints() as $name => $value) {
|
||||
$cloneQuery->setHint($name, $value);
|
||||
}
|
||||
|
||||
// Reset limit and offset
|
||||
$this->firstResult = $query->getFirstResult();
|
||||
$this->maxResults = $query->getMaxResults();
|
||||
$query->setFirstResult(0)->setMaxResults(null);
|
||||
$this->firstResult = $cloneQuery->getFirstResult();
|
||||
$this->maxResults = $cloneQuery->getMaxResults();
|
||||
$cloneQuery->setFirstResult(0)->setMaxResults(null);
|
||||
|
||||
$this->em = $query->getEntityManager();
|
||||
$this->em = $cloneQuery->getEntityManager();
|
||||
$this->quoteStrategy = $this->em->getConfiguration()->getQuoteStrategy();
|
||||
|
||||
parent::__construct($query, $parserResult, $queryComponents);
|
||||
parent::__construct($cloneQuery, $parserResult, $queryComponents);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,13 @@ use BackedEnum;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\AbstractAsset;
|
||||
use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
use Doctrine\DBAL\Schema\ComparatorConfig;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraintEditor;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
use Doctrine\DBAL\Schema\Index\IndexedColumn;
|
||||
use Doctrine\DBAL\Schema\Name\Identifier;
|
||||
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
|
||||
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -31,12 +37,15 @@ use function array_diff_key;
|
||||
use function array_filter;
|
||||
use function array_flip;
|
||||
use function array_intersect_key;
|
||||
use function array_map;
|
||||
use function assert;
|
||||
use function class_exists;
|
||||
use function count;
|
||||
use function current;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function is_numeric;
|
||||
use function method_exists;
|
||||
use function strtolower;
|
||||
|
||||
/**
|
||||
@@ -282,7 +291,7 @@ class SchemaTool
|
||||
}
|
||||
|
||||
if ($pkColumns !== []) {
|
||||
$table->setPrimaryKey($pkColumns);
|
||||
self::addPrimaryKeyConstraint($table, $pkColumns);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -306,7 +315,7 @@ class SchemaTool
|
||||
}
|
||||
|
||||
if (! $table->hasIndex('primary')) {
|
||||
$table->setPrimaryKey($pkColumns);
|
||||
self::addPrimaryKeyConstraint($table, $pkColumns);
|
||||
}
|
||||
|
||||
// there can be unique indexes automatically created for join column
|
||||
@@ -315,7 +324,7 @@ class SchemaTool
|
||||
$primaryKey = $table->getIndex('primary');
|
||||
|
||||
foreach ($table->getIndexes() as $idxKey => $existingIndex) {
|
||||
if ($primaryKey->overrules($existingIndex)) {
|
||||
if ($existingIndex !== $primaryKey && $primaryKey->spansColumns(self::getIndexedColumns($existingIndex))) {
|
||||
$table->dropIndex($idxKey);
|
||||
}
|
||||
}
|
||||
@@ -346,7 +355,7 @@ class SchemaTool
|
||||
}
|
||||
}
|
||||
|
||||
$table->addUniqueIndex($uniqIndex->getColumns(), is_numeric($indexName) ? null : $indexName, $indexData['options'] ?? []);
|
||||
$table->addUniqueIndex(self::getIndexedColumns($uniqIndex), is_numeric($indexName) ? null : $indexName, $indexData['options'] ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,7 +581,7 @@ class SchemaTool
|
||||
$blacklistedFks,
|
||||
);
|
||||
|
||||
$theJoinTable->setPrimaryKey($primaryKeyColumns);
|
||||
self::addPrimaryKeyConstraint($theJoinTable, $primaryKeyColumns);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -709,6 +718,10 @@ class SchemaTool
|
||||
if (isset($joinColumn->onDelete)) {
|
||||
$fkOptions['onDelete'] = $joinColumn->onDelete;
|
||||
}
|
||||
|
||||
if (isset($joinColumn->deferrable)) {
|
||||
$fkOptions['deferrable'] = $joinColumn->deferrable;
|
||||
}
|
||||
}
|
||||
|
||||
// Prefer unique constraints over implicit simple indexes created for foreign keys.
|
||||
@@ -725,7 +738,18 @@ class SchemaTool
|
||||
) {
|
||||
foreach ($theJoinTable->getForeignKeys() as $fkName => $key) {
|
||||
if (
|
||||
count(array_diff($key->getLocalColumns(), $localColumns)) === 0
|
||||
class_exists(ForeignKeyConstraintEditor::class)
|
||||
&& count(array_diff(array_map(static fn (UnqualifiedName $name) => $name->toString(), $key->getReferencingColumnNames()), $localColumns)) === 0
|
||||
&& (($key->getReferencedTableName()->toString() !== $foreignTableName)
|
||||
|| 0 < count(array_diff(array_map(static fn (UnqualifiedName $name) => $name->toString(), $key->getReferencedColumnNames()), $foreignColumns)))
|
||||
) {
|
||||
$theJoinTable->dropForeignKey($fkName);
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
! class_exists(ForeignKeyConstraintEditor::class)
|
||||
&& count(array_diff($key->getLocalColumns(), $localColumns)) === 0
|
||||
&& (($key->getForeignTableName() !== $foreignTableName)
|
||||
|| 0 < count(array_diff($key->getForeignColumns(), $foreignColumns)))
|
||||
) {
|
||||
@@ -843,12 +867,22 @@ class SchemaTool
|
||||
}
|
||||
|
||||
foreach ($schema->getTables() as $table) {
|
||||
$primaryKey = $table->getPrimaryKey();
|
||||
if (method_exists($table, 'getPrimaryKeyConstraint')) {
|
||||
$primaryKey = $table->getPrimaryKeyConstraint();
|
||||
} else {
|
||||
$primaryKey = $table->getPrimaryKey();
|
||||
}
|
||||
|
||||
if ($primaryKey === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columns = $primaryKey->getColumns();
|
||||
if ($primaryKey instanceof PrimaryKeyConstraint) {
|
||||
$columns = array_map(static fn (UnqualifiedName $name) => $name->toString(), $primaryKey->getColumnNames());
|
||||
} else {
|
||||
$columns = self::getIndexedColumns($primaryKey);
|
||||
}
|
||||
|
||||
if (count($columns) === 1) {
|
||||
$checkSequence = $table->getName() . '_' . $columns[0] . '_seq';
|
||||
if ($deployedSchema->hasSequence($checkSequence) && ! $schema->hasSequence($checkSequence)) {
|
||||
@@ -888,7 +922,13 @@ class SchemaTool
|
||||
{
|
||||
$toSchema = $this->getSchemaFromMetadata($classes);
|
||||
$fromSchema = $this->createSchemaForComparison($toSchema);
|
||||
$comparator = $this->schemaManager->createComparator();
|
||||
|
||||
if (class_exists(ComparatorConfig::class)) {
|
||||
$comparator = $this->schemaManager->createComparator((new ComparatorConfig())->withReportModifiedIndexes(false));
|
||||
} else {
|
||||
$comparator = $this->schemaManager->createComparator();
|
||||
}
|
||||
|
||||
$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);
|
||||
|
||||
return $this->platform->getAlterSchemaSQL($schemaDiff);
|
||||
@@ -923,4 +963,30 @@ class SchemaTool
|
||||
$config->setSchemaAssetsFilter($previousFilter);
|
||||
}
|
||||
}
|
||||
|
||||
/** @param string[] $primaryKeyColumns */
|
||||
private function addPrimaryKeyConstraint(Table $table, array $primaryKeyColumns): void
|
||||
{
|
||||
if (class_exists(PrimaryKeyConstraint::class)) {
|
||||
$primaryKeyColumnNames = [];
|
||||
|
||||
foreach ($primaryKeyColumns as $primaryKeyColumn) {
|
||||
$primaryKeyColumnNames[] = new UnqualifiedName(Identifier::unquoted($primaryKeyColumn));
|
||||
}
|
||||
|
||||
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, $primaryKeyColumnNames, true));
|
||||
} else {
|
||||
$table->setPrimaryKey($primaryKeyColumns);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private static function getIndexedColumns(Index $index): array
|
||||
{
|
||||
if (method_exists(Index::class, 'getIndexedColumns')) {
|
||||
return array_map(static fn (IndexedColumn $indexedColumn) => $indexedColumn->getColumnName()->toString(), $index->getIndexedColumns());
|
||||
}
|
||||
|
||||
return $index->getColumns();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ use function array_map;
|
||||
use function array_push;
|
||||
use function array_search;
|
||||
use function array_values;
|
||||
use function assert;
|
||||
use function class_exists;
|
||||
use function class_parents;
|
||||
use function count;
|
||||
@@ -329,9 +328,8 @@ class SchemaValidator
|
||||
array_filter(
|
||||
array_map(
|
||||
function (FieldMapping $fieldMapping) use ($class): string|null {
|
||||
$fieldName = $fieldMapping->fieldName;
|
||||
assert(isset($class->reflFields[$fieldName]));
|
||||
$propertyType = $class->reflFields[$fieldName]->getType();
|
||||
$fieldName = $fieldMapping->fieldName;
|
||||
$propertyType = $class->propertyAccessors[$fieldName]->getUnderlyingReflector()->getType();
|
||||
|
||||
// If the field type is not a built-in type, we cannot check it
|
||||
if (! Type::hasType($fieldMapping->type)) {
|
||||
|
||||
@@ -49,6 +49,7 @@ use Exception;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Stringable;
|
||||
use Symfony\Component\VarExporter\Hydrator;
|
||||
use UnexpectedValueException;
|
||||
|
||||
use function array_chunk;
|
||||
@@ -585,7 +586,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$actualData = [];
|
||||
|
||||
foreach ($class->reflFields as $name => $refProp) {
|
||||
foreach ($class->propertyAccessors as $name => $refProp) {
|
||||
$value = $refProp->getValue($entity);
|
||||
|
||||
if ($class->isCollectionValuedAssociation($name) && $value !== null) {
|
||||
@@ -705,7 +706,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$newValue = clone $actualValue;
|
||||
$newValue->setOwner($entity, $assoc);
|
||||
$class->reflFields[$propName]->setValue($entity, $newValue);
|
||||
$class->propertyAccessors[$propName]->setValue($entity, $newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,7 +745,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
// Look for changes in associations of the entity
|
||||
foreach ($class->associationMappings as $field => $assoc) {
|
||||
$val = $class->reflFields[$field]->getValue($entity);
|
||||
$val = $class->propertyAccessors[$field]->getValue($entity);
|
||||
if ($val === null) {
|
||||
continue;
|
||||
}
|
||||
@@ -980,7 +981,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$actualData = [];
|
||||
|
||||
foreach ($class->reflFields as $name => $refProp) {
|
||||
foreach ($class->propertyAccessors as $name => $refProp) {
|
||||
if (
|
||||
( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity())
|
||||
&& ($name !== $class->versionField)
|
||||
@@ -1166,7 +1167,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
// is obtained by a new entity because the old one went out of scope.
|
||||
//$this->entityStates[$oid] = self::STATE_NEW;
|
||||
if (! $class->isIdentifierNatural()) {
|
||||
$class->reflFields[$class->identifier[0]]->setValue($entity, null);
|
||||
$class->propertyAccessors[$class->identifier[0]]->setValue($entity, null);
|
||||
}
|
||||
|
||||
if ($invoke !== ListenersInvoker::INVOKE_NONE) {
|
||||
@@ -2024,11 +2025,11 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$associationMappings = array_filter(
|
||||
$class->associationMappings,
|
||||
static fn (AssociationMapping $assoc): bool => $assoc->isCascadeRefresh()
|
||||
static fn (AssociationMapping $assoc): bool => $assoc->isCascadeRefresh(),
|
||||
);
|
||||
|
||||
foreach ($associationMappings as $assoc) {
|
||||
$relatedEntities = $class->reflFields[$assoc->fieldName]->getValue($entity);
|
||||
$relatedEntities = $class->propertyAccessors[$assoc->fieldName]->getValue($entity);
|
||||
|
||||
switch (true) {
|
||||
case $relatedEntities instanceof PersistentCollection:
|
||||
@@ -2065,11 +2066,11 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$associationMappings = array_filter(
|
||||
$class->associationMappings,
|
||||
static fn (AssociationMapping $assoc): bool => $assoc->isCascadeDetach()
|
||||
static fn (AssociationMapping $assoc): bool => $assoc->isCascadeDetach(),
|
||||
);
|
||||
|
||||
foreach ($associationMappings as $assoc) {
|
||||
$relatedEntities = $class->reflFields[$assoc->fieldName]->getValue($entity);
|
||||
$relatedEntities = $class->propertyAccessors[$assoc->fieldName]->getValue($entity);
|
||||
|
||||
switch (true) {
|
||||
case $relatedEntities instanceof PersistentCollection:
|
||||
@@ -2111,11 +2112,11 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$associationMappings = array_filter(
|
||||
$class->associationMappings,
|
||||
static fn (AssociationMapping $assoc): bool => $assoc->isCascadePersist()
|
||||
static fn (AssociationMapping $assoc): bool => $assoc->isCascadePersist(),
|
||||
);
|
||||
|
||||
foreach ($associationMappings as $assoc) {
|
||||
$relatedEntities = $class->reflFields[$assoc->fieldName]->getValue($entity);
|
||||
$relatedEntities = $class->propertyAccessors[$assoc->fieldName]->getValue($entity);
|
||||
|
||||
switch (true) {
|
||||
case $relatedEntities instanceof PersistentCollection:
|
||||
@@ -2168,7 +2169,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$associationMappings = array_filter(
|
||||
$class->associationMappings,
|
||||
static fn (AssociationMapping $assoc): bool => $assoc->isCascadeRemove()
|
||||
static fn (AssociationMapping $assoc): bool => $assoc->isCascadeRemove(),
|
||||
);
|
||||
|
||||
if ($associationMappings) {
|
||||
@@ -2178,7 +2179,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$entitiesToCascade = [];
|
||||
|
||||
foreach ($associationMappings as $assoc) {
|
||||
$relatedEntities = $class->reflFields[$assoc->fieldName]->getValue($entity);
|
||||
$relatedEntities = $class->propertyAccessors[$assoc->fieldName]->getValue($entity);
|
||||
|
||||
switch (true) {
|
||||
case $relatedEntities instanceof Collection:
|
||||
@@ -2234,7 +2235,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$this->initializeObject($entity);
|
||||
|
||||
assert($class->versionField !== null);
|
||||
$entityVersion = $class->reflFields[$class->versionField]->getValue($entity);
|
||||
$entityVersion = $class->propertyAccessors[$class->versionField]->getValue($entity);
|
||||
|
||||
// phpcs:ignore SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator
|
||||
if ($entityVersion != $lockVersion) {
|
||||
@@ -2378,7 +2379,13 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
|
||||
if ($this->isUninitializedObject($entity)) {
|
||||
$entity->__setInitialized(true);
|
||||
if ($this->em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
$class->reflClass->markLazyObjectAsInitialized($entity);
|
||||
} else {
|
||||
$entity->__setInitialized(true);
|
||||
}
|
||||
|
||||
Hydrator::hydrate($entity, (array) $class->reflClass->newInstanceWithoutConstructor());
|
||||
} else {
|
||||
if (
|
||||
! isset($hints[Query::HINT_REFRESH])
|
||||
@@ -2401,7 +2408,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
foreach ($data as $field => $value) {
|
||||
if (isset($class->fieldMappings[$field])) {
|
||||
$class->reflFields[$field]->setValue($entity, $value);
|
||||
$class->propertyAccessors[$field]->setValue($entity, $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2431,21 +2438,21 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if (isset($data[$field]) && is_object($data[$field]) && isset($this->entityStates[spl_object_id($data[$field])])) {
|
||||
$this->originalEntityData[$oid][$field] = $data[$field];
|
||||
|
||||
$class->reflFields[$field]->setValue($entity, $data[$field]);
|
||||
$targetClass->reflFields[$assoc->mappedBy]->setValue($data[$field], $entity);
|
||||
$class->propertyAccessors[$field]->setValue($entity, $data[$field]);
|
||||
$targetClass->propertyAccessors[$assoc->mappedBy]->setValue($data[$field], $entity);
|
||||
|
||||
continue 2;
|
||||
}
|
||||
|
||||
// Inverse side of x-to-one can never be lazy
|
||||
$class->reflFields[$field]->setValue($entity, $this->getEntityPersister($assoc->targetEntity)->loadOneToOneEntity($assoc, $entity));
|
||||
$class->propertyAccessors[$field]->setValue($entity, $this->getEntityPersister($assoc->targetEntity)->loadOneToOneEntity($assoc, $entity));
|
||||
|
||||
continue 2;
|
||||
}
|
||||
|
||||
// use the entity association
|
||||
if (isset($data[$field]) && is_object($data[$field]) && isset($this->entityStates[spl_object_id($data[$field])])) {
|
||||
$class->reflFields[$field]->setValue($entity, $data[$field]);
|
||||
$class->propertyAccessors[$field]->setValue($entity, $data[$field]);
|
||||
$this->originalEntityData[$oid][$field] = $data[$field];
|
||||
|
||||
break;
|
||||
@@ -2477,7 +2484,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
if (! $associatedId) {
|
||||
// Foreign key is NULL
|
||||
$class->reflFields[$field]->setValue($entity, null);
|
||||
$class->propertyAccessors[$field]->setValue($entity, null);
|
||||
$this->originalEntityData[$oid][$field] = null;
|
||||
|
||||
break;
|
||||
@@ -2543,11 +2550,11 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
|
||||
$this->originalEntityData[$oid][$field] = $newValue;
|
||||
$class->reflFields[$field]->setValue($entity, $newValue);
|
||||
$class->propertyAccessors[$field]->setValue($entity, $newValue);
|
||||
|
||||
if ($assoc->inversedBy !== null && $assoc->isOneToOne() && $newValue !== null) {
|
||||
$inverseAssoc = $targetClass->associationMappings[$assoc->inversedBy];
|
||||
$targetClass->reflFields[$inverseAssoc->fieldName]->setValue($newValue, $entity);
|
||||
$targetClass->propertyAccessors[$inverseAssoc->fieldName]->setValue($newValue, $entity);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -2563,7 +2570,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if (isset($data[$field]) && $data[$field] instanceof PersistentCollection) {
|
||||
$data[$field]->setOwner($entity, $assoc);
|
||||
|
||||
$class->reflFields[$field]->setValue($entity, $data[$field]);
|
||||
$class->propertyAccessors[$field]->setValue($entity, $data[$field]);
|
||||
$this->originalEntityData[$oid][$field] = $data[$field];
|
||||
|
||||
break;
|
||||
@@ -2574,7 +2581,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$pColl->setOwner($entity, $assoc);
|
||||
$pColl->setInitialized(false);
|
||||
|
||||
$reflField = $class->reflFields[$field];
|
||||
$reflField = $class->propertyAccessors[$field];
|
||||
$reflField->setValue($entity, $pColl);
|
||||
|
||||
if ($hints['fetchMode'][$class->name][$field] === ClassMetadata::FETCH_EAGER) {
|
||||
@@ -2654,7 +2661,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$found = $this->getEntityPersister($targetEntity)->loadAll([$mappedBy => $entities], $mapping->orderBy);
|
||||
|
||||
$targetClass = $this->em->getClassMetadata($targetEntity);
|
||||
$targetProperty = $targetClass->getReflectionProperty($mappedBy);
|
||||
$targetProperty = $targetClass->getPropertyAccessor($mappedBy);
|
||||
assert($targetProperty !== null);
|
||||
|
||||
foreach ($found as $targetValue) {
|
||||
@@ -2676,7 +2683,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$idHash = implode(' ', $id);
|
||||
|
||||
if ($mapping->indexBy !== null) {
|
||||
$indexByProperty = $targetClass->getReflectionProperty($mapping->indexBy);
|
||||
$indexByProperty = $targetClass->getPropertyAccessor($mapping->indexBy);
|
||||
assert($indexByProperty !== null);
|
||||
$collectionBatch[$idHash]->hydrateSet($indexByProperty->getValue($targetValue), $targetValue);
|
||||
} else {
|
||||
@@ -3033,6 +3040,13 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
if ($obj instanceof PersistentCollection) {
|
||||
$obj->initialize();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
$reflection = $this->em->getClassMetadata($obj::class)->getReflectionClass();
|
||||
$reflection->initializeLazyObject($obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3043,6 +3057,10 @@ class UnitOfWork implements PropertyChangedListener
|
||||
*/
|
||||
public function isUninitializedObject(mixed $obj): bool
|
||||
{
|
||||
if ($this->em->getConfiguration()->isNativeLazyObjectsEnabled() && ! ($obj instanceof Collection) && is_object($obj)) {
|
||||
return $this->em->getClassMetadata($obj::class)->reflClass->isUninitializedLazyObject($obj);
|
||||
}
|
||||
|
||||
return $obj instanceof InternalProxy && ! $obj->__isInitialized();
|
||||
}
|
||||
|
||||
@@ -3241,7 +3259,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$idValue = $this->convertSingleFieldIdentifierToPHPValue($class, $generatedId);
|
||||
$oid = spl_object_id($entity);
|
||||
|
||||
$class->reflFields[$idField]->setValue($entity, $idValue);
|
||||
$class->propertyAccessors[$idField]->setValue($entity, $idValue);
|
||||
|
||||
$this->entityIdentifiers[$oid] = [$idField => $idValue];
|
||||
$this->entityStates[$oid] = self::STATE_MANAGED;
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Doctrine\Tests\Models\CMS;
|
||||
|
||||
class CmsAddressDTO
|
||||
{
|
||||
public function __construct(public string|null $country = null, public string|null $city = null, public string|null $zip = null, public CmsAddressDTO|string|null $address = null)
|
||||
public function __construct(public string|null $country = null, public string|null $city = null, public string|null $zip = null, public string|null $address = null, public CmsDumbDTO|null $other = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user