Skip to content

Commit 6b7a492

Browse files
committed
Update advanced-configuration docs and make proxy config variables not required anymore with native lazy objects.
1 parent db057a2 commit 6b7a492

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

docs/en/reference/advanced-configuration.rst

+31-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ steps of configuration.
1919
2020
// ...
2121
22-
if ($applicationMode == "development") {
22+
if ($applicationMode === "development") {
2323
$queryCache = new ArrayAdapter();
2424
$metadataCache = new ArrayAdapter();
2525
} else {
@@ -35,10 +35,14 @@ steps of configuration.
3535
$config->setProxyDir('/path/to/myproject/lib/MyProject/Proxies');
3636
$config->setProxyNamespace('MyProject\Proxies');
3737
38-
if ($applicationMode == "development") {
39-
$config->setAutoGenerateProxyClasses(true);
38+
if (PHP_VERSION_ID > 80400) {
39+
$config->enableNativeLazyObjects(true);
4040
} else {
41-
$config->setAutoGenerateProxyClasses(false);
41+
if ($applicationMode === "development") {
42+
$config->setAutoGenerateProxyClasses(true);
43+
} else {
44+
$config->setAutoGenerateProxyClasses(false);
45+
}
4246
}
4347
4448
$connection = DriverManager::getConnection([
@@ -71,9 +75,26 @@ Configuration Options
7175
The following sections describe all the configuration options
7276
available on a ``Doctrine\ORM\Configuration`` instance.
7377

78+
Native Lazy Objects (***OPTIONAL***)
79+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80+
81+
With PHP 8.4 we recommend that you use native lazy objects instead of
82+
the code generation approach using the symfony/var-exporter Ghost trait.
83+
84+
With Doctrine 4, the minimal requirement will become PHP 8.4 and native lazy objects
85+
will become the only approach to lazy loading.
86+
87+
.. code-block:: php
88+
89+
<?php
90+
$config->enableNativeLazyObjects(true);
91+
7492
Proxy Directory (***REQUIRED***)
7593
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7694

95+
This setting is not required if you use native lazy objects with PHP 8.4
96+
and will be removed in the future.
97+
7798
.. code-block:: php
7899
79100
<?php
@@ -88,6 +109,9 @@ down.
88109
Proxy Namespace (***REQUIRED***)
89110
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90111

112+
This setting is not required if you use native lazy objects with PHP 8.4
113+
and will be removed in the future.
114+
91115
.. code-block:: php
92116
93117
<?php
@@ -200,6 +224,9 @@ deprecated ``Doctrine\DBAL\Logging\SQLLogger`` interface.
200224
Auto-generating Proxy Classes (***OPTIONAL***)
201225
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
202226

227+
This setting is not required if you use native lazy objects with PHP 8.4
228+
and will be removed in the future.
229+
203230
Proxy classes can either be generated manually through the Doctrine
204231
Console or automatically at runtime by Doctrine. The configuration
205232
option that controls this behavior is:

src/Proxy/ProxyFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ public function __construct(
143143
private readonly string $proxyNs,
144144
bool|int $autoGenerate = self::AUTOGENERATE_NEVER,
145145
) {
146-
if (! $proxyDir) {
146+
if (! $proxyDir && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
147147
throw ORMInvalidArgumentException::proxyDirectoryRequired();
148148
}
149149

150-
if (! $proxyNs) {
150+
if (! $proxyNs && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
151151
throw ORMInvalidArgumentException::proxyNamespaceRequired();
152152
}
153153

0 commit comments

Comments
 (0)