Skip to content

Commit 98331a6

Browse files
committed
Merge branch '2.11.x' into 3.0.x
* 2.11.x: PHPStan 1.3.3, Psalm 4.18.1 Remove Psalm job for analyzing DBAL 2 Use the readonly annotation (doctrine#9340) Add support for custom types with requireSQLConversion and ResultSetMappingBuilder::generateSelectClause() PSR-6 second level cache Fix type errors in AbstractQuery and QueryBuilder (doctrine#9275) Mark columnName as always set Add support for PHP 8.1 enums. Remove ignore rules for issues fixed upstream (doctrine#9336) [doctrineGH-9277] deprecate php driver (doctrine#9309)
2 parents 2dce2d0 + 0d911b9 commit 98331a6

File tree

63 files changed

+897
-571
lines changed

Some content is hidden

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

63 files changed

+897
-571
lines changed

.github/workflows/static-analysis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ jobs:
5454
matrix:
5555
php-version:
5656
- "8.1"
57-
dbal-version:
58-
- "default"
5957

6058
steps:
6159
- name: "Checkout code"
@@ -67,10 +65,6 @@ jobs:
6765
coverage: "none"
6866
php-version: "${{ matrix.php-version }}"
6967

70-
- name: "Require specific DBAL version"
71-
run: "composer require doctrine/dbal ^${{ matrix.dbal-version }} --no-update"
72-
if: "${{ matrix.dbal-version != 'default' }}"
73-
7468
- name: "Install dependencies with Composer"
7569
uses: "ramsey/composer-install@v1"
7670
with:

UPGRADE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@ Use `toIterable()` instead.
107107

108108
# Upgrade to 2.11
109109

110+
## PSR-6-based second level cache
111+
112+
The second level cache has been reworked to consume a PSR-6 cache. Using a
113+
Doctrine Cache instance is deprecated.
114+
115+
* `DefaultCacheFactory`: The constructor expects a PSR-6 cache item pool as
116+
second argument now.
117+
* `DefaultMultiGetRegion`: This class is deprecated in favor of `DefaultRegion`.
118+
* `DefaultRegion`:
119+
* The constructor expects a PSR-6 cache item pool as second argument now.
120+
* The protected `$cache` property is deprecated.
121+
* The properties `$name` and `$lifetime` as well as the constant
122+
`REGION_KEY_SEPARATOR` and the method `getCacheEntryKey()` are flagged as
123+
`@internal` now. They all will become `private` in 3.0.
124+
* The method `getCache()` is deprecated without replacement.
125+
126+
## Deprecated: `Doctrine\ORM\Mapping\Driver\PHPDriver`
127+
128+
Use `StaticPHPDriver` instead when you want to programmatically configure
129+
entity metadata.
130+
131+
You can convert mappings with the `orm:convert-mapping` command or more simply
132+
in this case, `include` the metadata file from the `loadMetadata` static method
133+
used by the `StaticPHPDriver`.
134+
110135
## Deprecated: `Setup::registerAutoloadDirectory()`
111136

112137
Use Composer's autoloader instead.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
"doctrine/annotations": "^1.13",
4242
"doctrine/coding-standard": "^9.0",
4343
"phpbench/phpbench": "^1.0",
44-
"phpstan/phpstan": "1.3.0",
44+
"phpstan/phpstan": "1.3.3",
4545
"phpunit/phpunit": "^9.5",
4646
"squizlabs/php_codesniffer": "3.6.2",
4747
"symfony/cache": "^4.4 || ^5.4 || ^6.0",
48-
"vimeo/psalm": "4.17.0"
48+
"vimeo/psalm": "4.18.1"
4949
},
5050
"conflict": {
5151
"doctrine/annotations": "<1.13 || >= 2.0"

docs/en/reference/basic-mapping.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ list:
172172
unique key.
173173
- ``nullable``: (optional, default FALSE) Whether the database
174174
column is nullable.
175+
- ``enumType``: (optional, requires PHP 8.1 and ORM 2.11) The PHP enum type
176+
name to convert the database value into.
175177
- ``precision``: (optional, default 0) The precision for a decimal
176178
(exact numeric) column (applies only for decimal column),
177179
which is the maximum number of digits that are stored for the values.
@@ -206,6 +208,9 @@ Additionally, Doctrine will map PHP types to ``type`` attribute as follows:
206208
- ``int``: ``integer``
207209
- ``string`` or any other type: ``string``
208210

211+
As of version 2.11 Doctrine can also automatically map typed properties using a
212+
PHP 8.1 enum to set the right ``type`` and ``enumType``.
213+
209214
.. _reference-mapping-types:
210215

211216
Doctrine Mapping Types

docs/en/reference/php-mapping.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,3 @@ themselves.
249249
- ``setIdentifierValues($entity, $id)``
250250
- ``setFieldValue($entity, $field, $value)``
251251
- ``getFieldValue($entity, $field)``
252-
253-

docs/en/reference/second-level-cache.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ To enable the second-level-cache, you should provide a cache factory.
172172
173173
<?php
174174
/** @var \Doctrine\ORM\Cache\RegionsConfiguration $cacheConfig */
175-
/** @var \Doctrine\Common\Cache\Cache $cache */
175+
/** @var \Psr\Cache\CacheItemPoolInterface $cache */
176176
/** @var \Doctrine\ORM\Configuration $config */
177177
178178
$factory = new \Doctrine\ORM\Cache\DefaultCacheFactory($cacheConfig, $cache);

doctrine-mapping.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
<xs:attribute name="length" type="xs:NMTOKEN" />
300300
<xs:attribute name="unique" type="xs:boolean" default="false" />
301301
<xs:attribute name="nullable" type="xs:boolean" default="false" />
302+
<xs:attribute name="enum-type" type="xs:string" />
302303
<xs:attribute name="version" type="xs:boolean" />
303304
<xs:attribute name="column-definition" type="xs:string" />
304305
<xs:attribute name="precision" type="xs:integer" use="optional" />

lib/Doctrine/ORM/AbstractQuery.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Doctrine\ORM\Query\QueryException;
2020
use Doctrine\ORM\Query\ResultSetMapping;
2121
use Doctrine\Persistence\Mapping\MappingException;
22+
use LogicException;
2223
use Psr\Cache\CacheItemPoolInterface;
2324
use Traversable;
2425

@@ -87,7 +88,7 @@ abstract class AbstractQuery
8788
/**
8889
* The user-specified ResultSetMapping to use.
8990
*
90-
* @var ResultSetMapping
91+
* @var ResultSetMapping|null
9192
*/
9293
protected $_resultSetMapping;
9394

@@ -109,6 +110,7 @@ abstract class AbstractQuery
109110
* The hydration mode.
110111
*
111112
* @var string|int
113+
* @psalm-var string|AbstractQuery::HYDRATE_*
112114
*/
113115
protected $_hydrationMode = self::HYDRATE_OBJECT;
114116

@@ -146,6 +148,7 @@ abstract class AbstractQuery
146148
* Second level query cache mode.
147149
*
148150
* @var int|null
151+
* @psalm-var Cache::MODE_*|null
149152
*/
150153
protected $cacheMode;
151154

@@ -247,7 +250,8 @@ public function setLifetime($lifetime)
247250
}
248251

249252
/**
250-
* @return int
253+
* @return int|null
254+
* @psalm-return Cache::MODE_*|null
251255
*/
252256
public function getCacheMode()
253257
{
@@ -256,6 +260,7 @@ public function getCacheMode()
256260

257261
/**
258262
* @param int $cacheMode
263+
* @psalm-param Cache::MODE_* $cacheMode
259264
*
260265
* @return $this
261266
*/
@@ -488,7 +493,7 @@ public function setResultSetMapping(Query\ResultSetMapping $rsm)
488493
/**
489494
* Gets the ResultSetMapping used for hydration.
490495
*
491-
* @return ResultSetMapping
496+
* @return ResultSetMapping|null
492497
*/
493498
protected function getResultSetMapping()
494499
{
@@ -791,6 +796,7 @@ public function setFetchMode($class, $assocName, $fetchMode)
791796
*
792797
* @param string|int $hydrationMode Doctrine processing mode to be used during hydration process.
793798
* One of the Query::HYDRATE_* constants.
799+
* @psalm-param string|AbstractQuery::HYDRATE_* $hydrationMode
794800
*
795801
* @return $this
796802
*/
@@ -805,6 +811,7 @@ public function setHydrationMode($hydrationMode)
805811
* Gets the hydration mode currently used by the query.
806812
*
807813
* @return string|int
814+
* @psalm-return string|AbstractQuery::HYDRATE_*
808815
*/
809816
public function getHydrationMode()
810817
{
@@ -817,6 +824,7 @@ public function getHydrationMode()
817824
* Alias for execute(null, $hydrationMode = HYDRATE_OBJECT).
818825
*
819826
* @param string|int $hydrationMode
827+
* @psalm-param string|AbstractQuery::HYDRATE_* $hydrationMode
820828
*
821829
* @return mixed
822830
*/
@@ -864,7 +872,8 @@ public function getScalarResult()
864872
/**
865873
* Get exactly one result or null.
866874
*
867-
* @param string|int $hydrationMode
875+
* @param string|int|null $hydrationMode
876+
* @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
868877
*
869878
* @return mixed
870879
*
@@ -901,7 +910,8 @@ public function getOneOrNullResult($hydrationMode = null)
901910
* If the result is not unique, a NonUniqueResultException is thrown.
902911
* If there is no result, a NoResultException is thrown.
903912
*
904-
* @param string|int $hydrationMode
913+
* @param string|int|null $hydrationMode
914+
* @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
905915
*
906916
* @return mixed
907917
*
@@ -998,6 +1008,7 @@ public function getHints()
9981008
* @param ArrayCollection|array|mixed[] $parameters The query parameters.
9991009
* @param string|int|null $hydrationMode The hydration mode to use.
10001010
* @psalm-param ArrayCollection<int, Parameter>|mixed[] $parameters
1011+
* @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
10011012
*
10021013
* @return iterable<mixed>
10031014
*/
@@ -1015,6 +1026,9 @@ public function toIterable(iterable $parameters = [], $hydrationMode = null): it
10151026
}
10161027

10171028
$rsm = $this->getResultSetMapping();
1029+
if ($rsm === null) {
1030+
throw new LogicException('Uninitialized result set mapping.');
1031+
}
10181032

10191033
if ($rsm->isMixed && count($rsm->scalarMappings) > 0) {
10201034
throw QueryException::iterateWithMixedResultNotAllowed();
@@ -1031,6 +1045,7 @@ public function toIterable(iterable $parameters = [], $hydrationMode = null): it
10311045
* @param ArrayCollection|mixed[]|null $parameters Query parameters.
10321046
* @param string|int|null $hydrationMode Processing mode to be used during the hydration process.
10331047
* @psalm-param ArrayCollection<int, Parameter>|mixed[]|null $parameters
1048+
* @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
10341049
*
10351050
* @return mixed
10361051
*/
@@ -1049,6 +1064,7 @@ public function execute($parameters = null, $hydrationMode = null)
10491064
* @param ArrayCollection|mixed[]|null $parameters
10501065
* @param string|int|null $hydrationMode
10511066
* @psalm-param ArrayCollection<int, Parameter>|mixed[]|null $parameters
1067+
* @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
10521068
*
10531069
* @return mixed
10541070
*/
@@ -1093,7 +1109,11 @@ private function executeIgnoreQueryCache($parameters = null, $hydrationMode = nu
10931109
return $stmt;
10941110
}
10951111

1096-
$rsm = $this->getResultSetMapping();
1112+
$rsm = $this->getResultSetMapping();
1113+
if ($rsm === null) {
1114+
throw new LogicException('Uninitialized result set mapping.');
1115+
}
1116+
10971117
$data = $this->_em->newHydrator($this->_hydrationMode)->hydrateAll($stmt, $rsm, $this->_hints);
10981118

10991119
$setCacheEntry($data);
@@ -1117,12 +1137,17 @@ private function getHydrationCache(): CacheItemPoolInterface
11171137
* @param ArrayCollection|mixed[]|null $parameters
11181138
* @param string|int|null $hydrationMode
11191139
* @psalm-param ArrayCollection<int, Parameter>|mixed[]|null $parameters
1140+
* @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
11201141
*
11211142
* @return mixed
11221143
*/
11231144
private function executeUsingQueryCache($parameters = null, $hydrationMode = null)
11241145
{
1125-
$rsm = $this->getResultSetMapping();
1146+
$rsm = $this->getResultSetMapping();
1147+
if ($rsm === null) {
1148+
throw new LogicException('Uninitialized result set mapping.');
1149+
}
1150+
11261151
$queryCache = $this->_em->getCache()->getQueryCache($this->cacheRegion);
11271152
$queryKey = new QueryCacheKey(
11281153
$this->getHash(),
@@ -1157,6 +1182,7 @@ private function executeUsingQueryCache($parameters = null, $hydrationMode = nul
11571182

11581183
private function getTimestampKey(): ?TimestampCacheKey
11591184
{
1185+
assert($this->_resultSetMapping !== null);
11601186
$entityName = reset($this->_resultSetMapping->aliasMap);
11611187

11621188
if (empty($entityName)) {

lib/Doctrine/ORM/Cache/AssociationCacheEntry.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
class AssociationCacheEntry implements CacheEntry
1111
{
1212
/**
13-
* READ-ONLY: Public only for performance reasons, it should be considered immutable.
14-
*
13+
* @readonly Public only for performance reasons, it should be considered immutable.
1514
* @var array<string, mixed> The entity identifier
1615
*/
1716
public $identifier;
1817

1918
/**
20-
* READ-ONLY: Public only for performance reasons, it should be considered immutable.
21-
*
19+
* @readonly Public only for performance reasons, it should be considered immutable.
2220
* @var string The entity class name
2321
*/
2422
public $class;

lib/Doctrine/ORM/Cache/CacheKey.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
abstract class CacheKey
1212
{
1313
/**
14-
* READ-ONLY: Public only for performance reasons, it should be considered immutable.
15-
*
14+
* @readonly Public only for performance reasons, it should be considered immutable.
1615
* @var string Unique identifier
1716
*/
1817
public $hash;

0 commit comments

Comments
 (0)