mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 15:02:22 +01:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6deec3655b | ||
|
|
7f40422d21 | ||
|
|
e67fa5388b | ||
|
|
80053336c9 | ||
|
|
dddcc507ef | ||
|
|
b41d9da88d | ||
|
|
c04bfb78b7 | ||
|
|
8a5dfc86d4 | ||
|
|
79e103c07e | ||
|
|
5afadf163a | ||
|
|
edfaa37228 | ||
|
|
ea056e98ba | ||
|
|
bab5771e98 | ||
|
|
ee919d6231 | ||
|
|
04c390693a | ||
|
|
49293c4d48 | ||
|
|
8d9e2e7d4e | ||
|
|
ed543a205c | ||
|
|
60ff966d54 | ||
|
|
33684253c3 | ||
|
|
76852cfef3 | ||
|
|
3bd89caf36 | ||
|
|
eb2e7d959c | ||
|
|
a4b20356f4 | ||
|
|
2550b2d1de | ||
|
|
e94e1ab126 | ||
|
|
19e1a64a91 | ||
|
|
082e776e91 | ||
|
|
bbde41f712 | ||
|
|
8c0994f35f | ||
|
|
3d390bc053 | ||
|
|
16f1be7f10 | ||
|
|
1334162a56 | ||
|
|
68ec3ebaa3 | ||
|
|
4f4ed2f242 | ||
|
|
79cc70a62f | ||
|
|
4e6b5a1b0b | ||
|
|
21b144fff9 | ||
|
|
658940de38 | ||
|
|
ad487370f5 | ||
|
|
259f83b549 | ||
|
|
4a24860dcf | ||
|
|
116cdf8661 |
46
UPGRADE.md
46
UPGRADE.md
@@ -1,3 +1,49 @@
|
||||
# Upgrade to 3.5
|
||||
|
||||
## Deprecate not using native lazy objects on PHP 8.4+
|
||||
|
||||
Having native lazy objects disabled on PHP 8.4+ is deprecated and will not be
|
||||
possible in 4.0.
|
||||
|
||||
You can enable them through configuration:
|
||||
|
||||
```php
|
||||
$config->enableNativeLazyObjects(true);
|
||||
```
|
||||
|
||||
As a consequence, methods, parameters and commands related to userland lazy
|
||||
objects have been deprecated on PHP 8.4+:
|
||||
|
||||
- `Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand`
|
||||
- `Doctrine\ORM\Configuration::getAutoGenerateProxyClasses()`
|
||||
- `Doctrine\ORM\Configuration::getProxyDir()`
|
||||
- `Doctrine\ORM\Configuration::getProxyNamespace()`
|
||||
- `Doctrine\ORM\Configuration::setAutoGenerateProxyClasses()`
|
||||
- `Doctrine\ORM\Configuration::setProxyDir()`
|
||||
- `Doctrine\ORM\Configuration::setProxyNamespace()`
|
||||
- Passing more than one argument to `Doctrine\ORM\Proxy\ProxyFactory::__construct()`
|
||||
|
||||
Additionally, some methods of ORMSetup have been deprecated in favor of a new
|
||||
counterpart.
|
||||
|
||||
- `Doctrine\ORM\ORMSetup::createAttributeMetadataConfiguration()` is deprecated in favor of
|
||||
`Doctrine\ORM\ORMSetup::createAttributeMetadataConfig()`
|
||||
- `Doctrine\ORM\ORMSetup::createXMLMetadataConfiguration()` is deprecated in favor of
|
||||
`Doctrine\ORM\ORMSetup::createXMLMetadataConfig()`
|
||||
- `Doctrine\ORM\ORMSetup::createConfiguration()` is deprecated in favor of
|
||||
`Doctrine\ORM\ORMSetup::createConfig()`
|
||||
|
||||
## Deprecate methods for configuring no longer configurable features
|
||||
|
||||
Since 3.0, lazy ghosts are enabled unconditionally, and so is rejecting ID
|
||||
collisions in the identity map.
|
||||
|
||||
As a consequence, the following methods are deprecated and will be removed in 4.0:
|
||||
* `Doctrine\ORM\Configuration::setLazyGhostObjectEnabled()`
|
||||
* `Doctrine\ORM\Configuration::isLazyGhostObjectEnabled()`
|
||||
* `Doctrine\ORM\Configuration::setRejectIdCollisionInIdentityMap()`
|
||||
* `Doctrine\ORM\Configuration::isRejectIdCollisionInIdentityMapEnabled()`
|
||||
|
||||
# Upgrade to 3.4.1
|
||||
|
||||
## BC BREAK: You can no longer use the `.*` notation to get all fields of an entity in a DTO
|
||||
|
||||
@@ -175,6 +175,10 @@ Optional parameters:
|
||||
- **unique**: Boolean value to determine if the value of the column
|
||||
should be unique across all rows of the underlying entities table.
|
||||
|
||||
- **index**: Boolean value to generate an index for this column.
|
||||
For more advanced usages, take a look at :ref:`#[Index] <attrref_index>`.
|
||||
If not specified, default value is ``false``.
|
||||
|
||||
- **nullable**: Determines if NULL values allowed for this column.
|
||||
If not specified, default value is ``false``.
|
||||
|
||||
@@ -245,6 +249,9 @@ Examples:
|
||||
#[Column(type: "string", length: 32, unique: true, nullable: false)]
|
||||
protected $username;
|
||||
|
||||
#[Column(type: "string", index: true)]
|
||||
protected $firstName;
|
||||
|
||||
#[Column(type: "string", columnDefinition: "CHAR(2) NOT NULL")]
|
||||
protected $country;
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ access point to ORM functionality provided by Doctrine.
|
||||
'dbname' => 'foo',
|
||||
];
|
||||
|
||||
$config = ORMSetup::createAttributeMetadataConfiguration($paths, $isDevMode);
|
||||
$config = ORMSetup::createAttributeMetadataConfig($paths, $isDevMode);
|
||||
// on PHP < 8.4, use ORMSetup::createAttributeMetadataConfiguration() instead
|
||||
$connection = DriverManager::getConnection($dbParams, $config);
|
||||
$entityManager = new EntityManager($connection, $config);
|
||||
|
||||
@@ -66,7 +67,8 @@ Or if you prefer XML:
|
||||
|
||||
<?php
|
||||
$paths = ['/path/to/xml-mappings'];
|
||||
$config = ORMSetup::createXMLMetadataConfiguration($paths, $isDevMode);
|
||||
$config = ORMSetup::createXMLMetadataConfig($paths, $isDevMode);
|
||||
// on PHP < 8.4, use ORMSetup::createXMLMetadataConfiguration() instead
|
||||
$connection = DriverManager::getConnection($dbParams, $config);
|
||||
$entityManager = new EntityManager($connection, $config);
|
||||
|
||||
|
||||
@@ -209,6 +209,7 @@ Field & Association Getters
|
||||
|
||||
- ``isUniqueField($fieldName)``
|
||||
- ``isNullable($fieldName)``
|
||||
- ``isIndexed($fieldName)``
|
||||
- ``getColumnName($fieldName)``
|
||||
- ``getFieldMapping($fieldName)``
|
||||
- ``getAssociationMapping($fieldName)``
|
||||
|
||||
@@ -84,7 +84,7 @@ The following Commands are currently available:
|
||||
- ``orm:clear-cache:result`` Clear result cache of the various
|
||||
cache drivers.
|
||||
- ``orm:generate-proxies`` Generates proxy classes for entity
|
||||
classes.
|
||||
classes. Deprecated in favor of using native lazy objects.
|
||||
- ``orm:run-dql`` Executes arbitrary DQL directly from the command
|
||||
line.
|
||||
- ``orm:schema-tool:create`` Processes the schema and either
|
||||
|
||||
@@ -112,7 +112,6 @@ of several common elements:
|
||||
|
||||
<indexes>
|
||||
<index name="name_idx" columns="name"/>
|
||||
<index columns="user_email"/>
|
||||
</indexes>
|
||||
|
||||
<unique-constraints>
|
||||
@@ -131,7 +130,7 @@ of several common elements:
|
||||
</id>
|
||||
|
||||
<field name="name" column="name" type="string" length="50" nullable="true" unique="true" />
|
||||
<field name="email" column="user_email" type="string" column-definition="CHAR(32) NOT NULL" />
|
||||
<field name="email" column="user_email" type="string" index="true" column-definition="CHAR(32) NOT NULL" />
|
||||
|
||||
<one-to-one field="address" target-entity="Address" inversed-by="user">
|
||||
<cascade><cascade-remove /></cascade>
|
||||
@@ -255,6 +254,8 @@ Optional attributes:
|
||||
only.
|
||||
- unique - Should this field contain a unique value across the
|
||||
table? Defaults to false.
|
||||
- index - Should an index be created for this column? Defaults to
|
||||
false.
|
||||
- nullable - Should this field allow NULL as a value? Defaults to
|
||||
false.
|
||||
- insertable - Should this field be inserted? Defaults to true.
|
||||
|
||||
@@ -138,12 +138,12 @@ step:
|
||||
require_once "vendor/autoload.php";
|
||||
|
||||
// Create a simple "default" Doctrine ORM configuration for Attributes
|
||||
$config = ORMSetup::createAttributeMetadataConfiguration(
|
||||
$config = ORMSetup::createAttributeMetadataConfig( // on PHP < 8.4, use ORMSetup::createAttributeMetadataConfiguration()
|
||||
paths: [__DIR__ . '/src'],
|
||||
isDevMode: true,
|
||||
);
|
||||
// or if you prefer XML
|
||||
// $config = ORMSetup::createXMLMetadataConfiguration(
|
||||
// $config = ORMSetup::createXMLMetadataConfig( // on PHP < 8.4, use ORMSetup::createXMLMetadataConfiguration()
|
||||
// paths: [__DIR__ . '/config/xml'],
|
||||
// isDevMode: true,
|
||||
//);
|
||||
|
||||
@@ -243,6 +243,7 @@
|
||||
<xs:attribute name="length" type="xs:NMTOKEN" />
|
||||
<xs:attribute name="unique" type="xs:boolean" default="false" />
|
||||
<xs:attribute name="nullable" type="xs:boolean" default="false" />
|
||||
<xs:attribute name="index" type="xs:boolean" default="false" />
|
||||
<xs:attribute name="insertable" type="xs:boolean" default="true" />
|
||||
<xs:attribute name="updatable" type="xs:boolean" default="true" />
|
||||
<xs:attribute name="generated" type="orm:generated-type" default="NEVER" />
|
||||
|
||||
@@ -3450,12 +3450,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/UnitOfWork.php
|
||||
|
||||
-
|
||||
message: '#^PHPDoc tag @phpstan\-assert\-if\-true for \$obj contains generic interface Doctrine\\ORM\\Proxy\\InternalProxy but does not specify its types\: T$#'
|
||||
identifier: missingType.generics
|
||||
count: 1
|
||||
path: src/UnitOfWork.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$assoc of method Doctrine\\ORM\\PersistentCollection\<\(int\|string\),mixed\>\:\:setOwner\(\) expects Doctrine\\ORM\\Mapping\\AssociationMapping&Doctrine\\ORM\\Mapping\\ToManyAssociationMapping, Doctrine\\ORM\\Mapping\\ManyToManyInverseSideMapping\|Doctrine\\ORM\\Mapping\\ManyToManyOwningSideMapping\|Doctrine\\ORM\\Mapping\\ManyToOneAssociationMapping\|Doctrine\\ORM\\Mapping\\OneToManyAssociationMapping\|Doctrine\\ORM\\Mapping\\OneToOneInverseSideMapping\|Doctrine\\ORM\\Mapping\\OneToOneOwningSideMapping given\.$#'
|
||||
identifier: argument.type
|
||||
@@ -3498,6 +3492,12 @@ parameters:
|
||||
count: 1
|
||||
path: src/UnitOfWork.php
|
||||
|
||||
-
|
||||
message: '#^Unable to resolve the template type T in call to method static method Symfony\\Component\\VarExporter\\Hydrator\:\:hydrate\(\)$#'
|
||||
identifier: argument.templateType
|
||||
count: 1
|
||||
path: src/UnitOfWork.php
|
||||
|
||||
-
|
||||
message: '#^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$name\.$#'
|
||||
identifier: property.notFound
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Doctrine\ORM;
|
||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use Doctrine\ORM\Cache\CacheConfiguration;
|
||||
use Doctrine\ORM\Exception\InvalidEntityRepository;
|
||||
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
|
||||
@@ -63,6 +64,15 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*/
|
||||
public function setProxyDir(string $dir): void
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
|
||||
__METHOD__,
|
||||
);
|
||||
}
|
||||
|
||||
$this->attributes['proxyDir'] = $dir;
|
||||
}
|
||||
|
||||
@@ -71,6 +81,15 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*/
|
||||
public function getProxyDir(): string|null
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
|
||||
__METHOD__,
|
||||
);
|
||||
}
|
||||
|
||||
return $this->attributes['proxyDir'] ?? null;
|
||||
}
|
||||
|
||||
@@ -81,6 +100,15 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*/
|
||||
public function getAutoGenerateProxyClasses(): int
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
|
||||
__METHOD__,
|
||||
);
|
||||
}
|
||||
|
||||
return $this->attributes['autoGenerateProxyClasses'] ?? ProxyFactory::AUTOGENERATE_ALWAYS;
|
||||
}
|
||||
|
||||
@@ -91,6 +119,15 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*/
|
||||
public function setAutoGenerateProxyClasses(bool|int $autoGenerate): void
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
|
||||
__METHOD__,
|
||||
);
|
||||
}
|
||||
|
||||
$this->attributes['autoGenerateProxyClasses'] = (int) $autoGenerate;
|
||||
}
|
||||
|
||||
@@ -99,6 +136,15 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*/
|
||||
public function getProxyNamespace(): string|null
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
|
||||
__METHOD__,
|
||||
);
|
||||
}
|
||||
|
||||
return $this->attributes['proxyNamespace'] ?? null;
|
||||
}
|
||||
|
||||
@@ -107,6 +153,15 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*/
|
||||
public function setProxyNamespace(string $ns): void
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
|
||||
__METHOD__,
|
||||
);
|
||||
}
|
||||
|
||||
$this->attributes['proxyNamespace'] = $ns;
|
||||
}
|
||||
|
||||
@@ -597,12 +652,30 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
|
||||
public function isNativeLazyObjectsEnabled(): bool
|
||||
{
|
||||
return $this->attributes['nativeLazyObjects'] ?? false;
|
||||
$nativeLazyObjects = $this->attributes['nativeLazyObjects'] ?? false;
|
||||
|
||||
if (! $nativeLazyObjects && PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Not enabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0.',
|
||||
);
|
||||
}
|
||||
|
||||
return $nativeLazyObjects;
|
||||
}
|
||||
|
||||
public function enableNativeLazyObjects(bool $nativeLazyObjects): void
|
||||
{
|
||||
if (PHP_VERSION_ID < 80400) {
|
||||
if (PHP_VERSION_ID >= 80400 && ! $nativeLazyObjects) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Disabling native lazy objects is deprecated and will be impossible in Doctrine ORM 4.0.',
|
||||
);
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID < 80400 && $nativeLazyObjects) {
|
||||
throw new LogicException('Lazy loading proxies require PHP 8.4 or higher.');
|
||||
}
|
||||
|
||||
@@ -610,7 +683,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
}
|
||||
|
||||
/**
|
||||
* To be deprecated in 3.1.0
|
||||
* @deprecated lazy ghost objects are always enabled
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
@@ -619,7 +692,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
return true;
|
||||
}
|
||||
|
||||
/** To be deprecated in 3.1.0 */
|
||||
/** @deprecated lazy ghost objects cannot be disabled */
|
||||
public function setLazyGhostObjectEnabled(bool $flag): void
|
||||
{
|
||||
if (! $flag) {
|
||||
@@ -630,7 +703,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
}
|
||||
}
|
||||
|
||||
/** To be deprecated in 3.1.0 */
|
||||
/** @deprecated rejecting ID collisions in the identity map cannot be disabled */
|
||||
public function setRejectIdCollisionInIdentityMap(bool $flag): void
|
||||
{
|
||||
if (! $flag) {
|
||||
@@ -642,7 +715,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
}
|
||||
|
||||
/**
|
||||
* To be deprecated in 3.1.0
|
||||
* @deprecated rejecting ID collisions in the identity map is always enabled
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
|
||||
@@ -43,7 +43,7 @@ use function method_exists;
|
||||
*
|
||||
* $paths = ['/path/to/entity/mapping/files'];
|
||||
*
|
||||
* $config = ORMSetup::createAttributeMetadataConfiguration($paths);
|
||||
* $config = ORMSetup::createAttributeMetadataConfig($paths);
|
||||
* $connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true], $config);
|
||||
* $entityManager = new EntityManager($connection, $config);
|
||||
*
|
||||
@@ -134,12 +134,16 @@ class EntityManager implements EntityManagerInterface
|
||||
|
||||
$this->repositoryFactory = $config->getRepositoryFactory();
|
||||
$this->unitOfWork = new UnitOfWork($this);
|
||||
$this->proxyFactory = new ProxyFactory(
|
||||
$this,
|
||||
$config->getProxyDir(),
|
||||
$config->getProxyNamespace(),
|
||||
$config->getAutoGenerateProxyClasses(),
|
||||
);
|
||||
if ($config->isNativeLazyObjectsEnabled()) {
|
||||
$this->proxyFactory = new ProxyFactory($this);
|
||||
} else {
|
||||
$this->proxyFactory = new ProxyFactory(
|
||||
$this,
|
||||
$config->getProxyDir(),
|
||||
$config->getProxyNamespace(),
|
||||
$config->getAutoGenerateProxyClasses(),
|
||||
);
|
||||
}
|
||||
|
||||
if ($config->isSecondLevelCacheEnabled()) {
|
||||
$cacheConfig = $config->getSecondLevelCacheConfiguration();
|
||||
|
||||
79
src/Internal/UnitOfWork/InsertBatch.php
Normal file
79
src/Internal/UnitOfWork/InsertBatch.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Internal\UnitOfWork;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* An {@see InsertBatch} represents a set of entities that are safe to be batched
|
||||
* together in a single query.
|
||||
*
|
||||
* These entities are only those that have all fields already assigned, including the
|
||||
* identifier field(s).
|
||||
*
|
||||
* This data structure only exists for internal {@see UnitOfWork} optimisations, and
|
||||
* should not be relied upon outside the ORM.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @template TEntity of object
|
||||
*/
|
||||
final class InsertBatch
|
||||
{
|
||||
/**
|
||||
* @param ClassMetadata<TEntity> $class
|
||||
* @param non-empty-list<TEntity> $entities
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly ClassMetadata $class,
|
||||
public array $entities,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: Code in here is procedural/ugly due to it being in a hot path of the {@see UnitOfWork}
|
||||
*
|
||||
* This method will batch the given entity set by type, preserving their order. For example,
|
||||
* given an input [A1, A2, A3, B1, B2, A4, A5], it will create an [[A1, A2, A3], [B1, B2], [A4, A5]] batch.
|
||||
*
|
||||
* Entities for which the identifier needs to be generated or fetched by a sequence are put as single
|
||||
* items in a batch of their own, since it is unsafe to batch-insert them.
|
||||
*
|
||||
* @param list<TEntities> $entities
|
||||
*
|
||||
* @return list<self<TEntities>>
|
||||
*
|
||||
* @template TEntities of object
|
||||
*/
|
||||
public static function batchByEntityType(
|
||||
EntityManagerInterface $entityManager,
|
||||
array $entities,
|
||||
): array {
|
||||
$currentClass = null;
|
||||
$batches = [];
|
||||
$batchIndex = -1;
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
$entityClass = $entityManager->getClassMetadata($entity::class);
|
||||
|
||||
if (
|
||||
$currentClass?->name !== $entityClass->name
|
||||
|| ! $entityClass->idGenerator instanceof AssignedGenerator
|
||||
) {
|
||||
$currentClass = $entityClass;
|
||||
$batches[] = new InsertBatch($entityClass, [$entity]);
|
||||
$batchIndex += 1;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$batches[$batchIndex]->entities[] = $entity;
|
||||
}
|
||||
|
||||
return $batches;
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,18 @@ class FieldBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets indexed.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function index(bool $flag = true): static
|
||||
{
|
||||
$this->mapping['index'] = $flag;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets column name.
|
||||
*
|
||||
|
||||
@@ -1056,6 +1056,13 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
|
||||
return $mapping !== false && isset($mapping->nullable) && $mapping->nullable;
|
||||
}
|
||||
|
||||
public function isIndexed(string $fieldName): bool
|
||||
{
|
||||
$mapping = $this->getFieldMapping($fieldName);
|
||||
|
||||
return isset($mapping->index) && $mapping->index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a column name for a field name.
|
||||
* If the column name for the field cannot be found, the given field name
|
||||
|
||||
@@ -66,7 +66,9 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
|
||||
public function setEntityManager(EntityManagerInterface $em): void
|
||||
{
|
||||
parent::setProxyClassNameResolver(new DefaultProxyClassNameResolver());
|
||||
if (! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
parent::setProxyClassNameResolver(new DefaultProxyClassNameResolver());
|
||||
}
|
||||
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ final class Column implements MappingAttribute
|
||||
public readonly array $options = [],
|
||||
public readonly string|null $columnDefinition = null,
|
||||
public readonly string|null $generated = null,
|
||||
public readonly bool $index = false,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Doctrine\ORM\Mapping;
|
||||
|
||||
use BackedEnum;
|
||||
use BcMath\Number;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
@@ -40,7 +41,12 @@ final class DefaultTypedFieldMapper implements TypedFieldMapper
|
||||
/** @param array<class-string|ScalarName, class-string<Type>|string> $typedFieldMappings */
|
||||
public function __construct(array $typedFieldMappings = [])
|
||||
{
|
||||
$this->typedFieldMappings = array_merge(self::DEFAULT_TYPED_FIELD_MAPPINGS, $typedFieldMappings);
|
||||
$defaultMappings = self::DEFAULT_TYPED_FIELD_MAPPINGS;
|
||||
if (defined(Types::class . '::NUMBER')) { // DBAL 4.3+
|
||||
$defaultMappings[Number::class] = Types::NUMBER;
|
||||
}
|
||||
|
||||
$this->typedFieldMappings = array_merge($defaultMappings, $typedFieldMappings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -710,6 +710,7 @@ class AttributeDriver implements MappingDriver
|
||||
* length: int,
|
||||
* unique: bool,
|
||||
* nullable: bool,
|
||||
* index: bool,
|
||||
* precision: int,
|
||||
* enumType?: class-string,
|
||||
* options?: mixed[],
|
||||
@@ -726,6 +727,7 @@ class AttributeDriver implements MappingDriver
|
||||
'length' => $column->length,
|
||||
'unique' => $column->unique,
|
||||
'nullable' => $column->nullable,
|
||||
'index' => $column->index,
|
||||
'precision' => $column->precision,
|
||||
];
|
||||
|
||||
|
||||
@@ -754,6 +754,7 @@ class XmlDriver extends FileDriver
|
||||
* scale?: int,
|
||||
* unique?: bool,
|
||||
* nullable?: bool,
|
||||
* index?: bool,
|
||||
* notInsertable?: bool,
|
||||
* notUpdatable?: bool,
|
||||
* enumType?: string,
|
||||
@@ -792,6 +793,10 @@ class XmlDriver extends FileDriver
|
||||
$mapping['unique'] = $this->evaluateBoolean($fieldMapping['unique']);
|
||||
}
|
||||
|
||||
if (isset($fieldMapping['index'])) {
|
||||
$mapping['index'] = $this->evaluateBoolean($fieldMapping['index']);
|
||||
}
|
||||
|
||||
if (isset($fieldMapping['nullable'])) {
|
||||
$mapping['nullable'] = $this->evaluateBoolean($fieldMapping['nullable']);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ final class FieldMapping implements ArrayAccess
|
||||
public int|null $scale = null;
|
||||
/** Whether a unique constraint should be generated for the column. */
|
||||
public bool|null $unique = null;
|
||||
/** Whether an index should be generated for the column. */
|
||||
public bool|null $index = null;
|
||||
/**
|
||||
* @var class-string|null This is set when the field is inherited by this
|
||||
* class from another (inheritance) parent <em>entity</em> class. The value
|
||||
@@ -93,6 +95,7 @@ final class FieldMapping implements ArrayAccess
|
||||
* length?: int|null,
|
||||
* id?: bool|null,
|
||||
* nullable?: bool|null,
|
||||
* index?: bool|null,
|
||||
* notInsertable?: bool|null,
|
||||
* notUpdatable?: bool|null,
|
||||
* columnDefinition?: string|null,
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
|
||||
use Doctrine\ORM\Mapping\Driver\XmlDriver;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
@@ -20,6 +21,8 @@ use function extension_loaded;
|
||||
use function md5;
|
||||
use function sys_get_temp_dir;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
final class ORMSetup
|
||||
{
|
||||
/**
|
||||
@@ -33,12 +36,39 @@ final class ORMSetup
|
||||
string|null $proxyDir = null,
|
||||
CacheItemPoolInterface|null $cache = null,
|
||||
): Configuration {
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'%s is deprecated in favor of %s, and will be removed in 4.0.',
|
||||
__METHOD__,
|
||||
self::class . '::createAttributeMetadataConfig()',
|
||||
);
|
||||
}
|
||||
|
||||
$config = self::createConfiguration($isDevMode, $proxyDir, $cache);
|
||||
$config->setMetadataDriverImpl(new AttributeDriver($paths));
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a configuration with an attribute metadata driver.
|
||||
*
|
||||
* @param string[] $paths
|
||||
*/
|
||||
public static function createAttributeMetadataConfig(
|
||||
array $paths,
|
||||
bool $isDevMode = false,
|
||||
string|null $cacheNamespaceSeed = null,
|
||||
CacheItemPoolInterface|null $cache = null,
|
||||
): Configuration {
|
||||
$config = self::createConfig($isDevMode, $cacheNamespaceSeed, $cache);
|
||||
$config->setMetadataDriverImpl(new AttributeDriver($paths));
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a configuration with an XML metadata driver.
|
||||
*
|
||||
@@ -51,12 +81,44 @@ final class ORMSetup
|
||||
CacheItemPoolInterface|null $cache = null,
|
||||
bool $isXsdValidationEnabled = true,
|
||||
): Configuration {
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'%s is deprecated in favor of %s, and will be removed in 4.0.',
|
||||
__METHOD__,
|
||||
self::class . '::createXMLMetadataConfig()',
|
||||
);
|
||||
}
|
||||
|
||||
$config = self::createConfiguration($isDevMode, $proxyDir, $cache);
|
||||
$config->setMetadataDriverImpl(new XmlDriver($paths, XmlDriver::DEFAULT_FILE_EXTENSION, $isXsdValidationEnabled));
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a configuration with an XML metadata driver.
|
||||
*
|
||||
* @param string[] $paths
|
||||
*/
|
||||
public static function createXMLMetadataConfig(
|
||||
array $paths,
|
||||
bool $isDevMode = false,
|
||||
string|null $cacheNamespaceSeed = null,
|
||||
CacheItemPoolInterface|null $cache = null,
|
||||
bool $isXsdValidationEnabled = true,
|
||||
): Configuration {
|
||||
$config = self::createConfig($isDevMode, $cacheNamespaceSeed, $cache);
|
||||
$config->setMetadataDriverImpl(new XmlDriver(
|
||||
$paths,
|
||||
XmlDriver::DEFAULT_FILE_EXTENSION,
|
||||
$isXsdValidationEnabled,
|
||||
));
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a configuration without a metadata driver.
|
||||
*/
|
||||
@@ -65,6 +127,16 @@ final class ORMSetup
|
||||
string|null $proxyDir = null,
|
||||
CacheItemPoolInterface|null $cache = null,
|
||||
): Configuration {
|
||||
if (PHP_VERSION_ID >= 80400 && $proxyDir !== null) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'%s is deprecated in favor of %s, and will be removed in 4.0.',
|
||||
__METHOD__,
|
||||
self::class . '::createConfig()',
|
||||
);
|
||||
}
|
||||
|
||||
$proxyDir = $proxyDir ?: sys_get_temp_dir();
|
||||
|
||||
$cache = self::createCacheInstance($isDevMode, $proxyDir, $cache);
|
||||
@@ -81,9 +153,23 @@ final class ORMSetup
|
||||
return $config;
|
||||
}
|
||||
|
||||
public static function createConfig(
|
||||
bool $isDevMode = false,
|
||||
string|null $cacheNamespaceSeed = null,
|
||||
CacheItemPoolInterface|null $cache = null,
|
||||
): Configuration {
|
||||
$cache = self::createCacheInstance($isDevMode, $cacheNamespaceSeed, $cache);
|
||||
$config = new Configuration();
|
||||
$config->setMetadataCache($cache);
|
||||
$config->setQueryCache($cache);
|
||||
$config->setResultCache($cache);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
private static function createCacheInstance(
|
||||
bool $isDevMode,
|
||||
string $proxyDir,
|
||||
string|null $cacheNamespaceSeed,
|
||||
CacheItemPoolInterface|null $cache,
|
||||
): CacheItemPoolInterface {
|
||||
if ($cache !== null) {
|
||||
@@ -101,7 +187,7 @@ final class ORMSetup
|
||||
return new ArrayAdapter();
|
||||
}
|
||||
|
||||
$namespace = 'dc2_' . md5($proxyDir);
|
||||
$namespace = 'dc2_' . md5($cacheNamespaceSeed ?? 'default');
|
||||
|
||||
if (extension_loaded('apcu') && apcu_enabled()) {
|
||||
return new ApcuAdapter($namespace);
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Doctrine\ORM\Proxy;
|
||||
|
||||
use Closure;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function file_exists;
|
||||
use function ltrim;
|
||||
@@ -15,6 +16,7 @@ use function strlen;
|
||||
use function substr;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* Special Autoloader for Proxy classes, which are not PSR-0 compliant.
|
||||
@@ -34,6 +36,15 @@ final class Autoloader
|
||||
*/
|
||||
public static function resolveFile(string $proxyDir, string $proxyNamespace, string $className): string
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Class "%s" is deprecated. Use native lazy objects instead.',
|
||||
self::class,
|
||||
);
|
||||
}
|
||||
|
||||
if (! str_starts_with($className, $proxyNamespace)) {
|
||||
throw new NotAProxyClass($className, $proxyNamespace);
|
||||
}
|
||||
@@ -59,6 +70,15 @@ final class Autoloader
|
||||
string $proxyNamespace,
|
||||
Closure|null $notFoundCallback = null,
|
||||
): Closure {
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Class "%s" is deprecated. Use native lazy objects instead.',
|
||||
self::class,
|
||||
);
|
||||
}
|
||||
|
||||
$proxyNamespace = ltrim($proxyNamespace, '\\');
|
||||
|
||||
$autoloader = /** @param class-string $className */ static function (string $className) use ($proxyDir, $proxyNamespace, $notFoundCallback): void {
|
||||
|
||||
@@ -4,12 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Proxy;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use Doctrine\Persistence\Mapping\ProxyClassNameResolver;
|
||||
use Doctrine\Persistence\Proxy;
|
||||
|
||||
use function strrpos;
|
||||
use function substr;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* Class-related functionality for objects that might or not be proxy objects
|
||||
* at the moment.
|
||||
@@ -18,6 +21,15 @@ final class DefaultProxyClassNameResolver implements ProxyClassNameResolver
|
||||
{
|
||||
public function resolveClassName(string $className): string
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Class "%s" is deprecated. Use native lazy objects instead.',
|
||||
self::class,
|
||||
);
|
||||
}
|
||||
|
||||
$pos = strrpos($className, '\\' . Proxy::MARKER . '\\');
|
||||
|
||||
if ($pos === false) {
|
||||
@@ -30,6 +42,15 @@ final class DefaultProxyClassNameResolver implements ProxyClassNameResolver
|
||||
/** @return class-string */
|
||||
public static function getClass(object $object): string
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Class "%s" is deprecated. Use native lazy objects instead.',
|
||||
self::class,
|
||||
);
|
||||
}
|
||||
|
||||
return (new self())->resolveClassName($object::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Doctrine\ORM\Proxy;
|
||||
|
||||
use Closure;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityNotFoundException;
|
||||
use Doctrine\ORM\ORMInvalidArgumentException;
|
||||
@@ -30,6 +31,7 @@ use function dirname;
|
||||
use function file_exists;
|
||||
use function file_put_contents;
|
||||
use function filemtime;
|
||||
use function func_num_args;
|
||||
use function is_bool;
|
||||
use function is_dir;
|
||||
use function is_int;
|
||||
@@ -150,6 +152,15 @@ EOPHP;
|
||||
string|null $proxyNs = null,
|
||||
bool|int $autoGenerate = self::AUTOGENERATE_NEVER,
|
||||
) {
|
||||
if (PHP_VERSION_ID >= 80400 && func_num_args() > 1) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Passing more than just the EntityManager to the %s is deprecated and will not be possible in Doctrine ORM 4.0.',
|
||||
__METHOD__,
|
||||
);
|
||||
}
|
||||
|
||||
if (! $proxyDir && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
throw ORMInvalidArgumentException::proxyDirectoryRequired();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
@@ -19,6 +20,8 @@ use function mkdir;
|
||||
use function realpath;
|
||||
use function sprintf;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* Command to (re)generate the proxy classes used by doctrine.
|
||||
*
|
||||
@@ -39,6 +42,14 @@ class GenerateProxiesCommand extends AbstractEntityManagerCommand
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/orm/pull/12005',
|
||||
'Generating proxies is deprecated and will be impossible in Doctrine ORM 4.0.',
|
||||
);
|
||||
}
|
||||
|
||||
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
|
||||
|
||||
$em = $this->getEntityManager($input);
|
||||
|
||||
@@ -10,6 +10,8 @@ use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Mapping\FieldMapping;
|
||||
use Doctrine\Persistence\Mapping\MappingException;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
use Symfony\Component\Console\Completion\CompletionSuggestions;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
@@ -19,6 +21,7 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use function array_filter;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function array_values;
|
||||
use function count;
|
||||
use function current;
|
||||
use function get_debug_type;
|
||||
@@ -32,6 +35,7 @@ use function preg_match;
|
||||
use function preg_quote;
|
||||
use function print_r;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
|
||||
use const JSON_PRETTY_PRINT;
|
||||
use const JSON_THROW_ON_ERROR;
|
||||
@@ -73,6 +77,20 @@ EOT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
|
||||
{
|
||||
if ($input->mustSuggestArgumentValuesFor('entityName')) {
|
||||
$entityManager = $this->getEntityManager($input);
|
||||
|
||||
$entities = array_map(
|
||||
static fn (string $fqcn) => str_replace('\\', '\\\\', $fqcn),
|
||||
$this->getMappedEntities($entityManager),
|
||||
);
|
||||
|
||||
$suggestions->suggestValues(array_values($entities));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display all the mapping information for a single Entity.
|
||||
*
|
||||
|
||||
@@ -505,6 +505,11 @@ class SchemaTool
|
||||
if ($isUnique) {
|
||||
$table->addUniqueIndex([$columnName]);
|
||||
}
|
||||
|
||||
$isIndex = $mapping->index ?? false;
|
||||
if ($isIndex) {
|
||||
$table->addIndex([$columnName]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,7 @@ use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Internal\HydrationCompleteHandler;
|
||||
use Doctrine\ORM\Internal\StronglyConnectedComponents;
|
||||
use Doctrine\ORM\Internal\TopologicalSort;
|
||||
use Doctrine\ORM\Internal\UnitOfWork\InsertBatch;
|
||||
use Doctrine\ORM\Mapping\AssociationMapping;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Mapping\MappingException;
|
||||
@@ -1037,30 +1038,36 @@ class UnitOfWork implements PropertyChangedListener
|
||||
*/
|
||||
private function executeInserts(): void
|
||||
{
|
||||
$entities = $this->computeInsertExecutionOrder();
|
||||
$batchedByType = InsertBatch::batchByEntityType($this->em, $this->computeInsertExecutionOrder());
|
||||
$eventsToDispatch = [];
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
$oid = spl_object_id($entity);
|
||||
$class = $this->em->getClassMetadata($entity::class);
|
||||
foreach ($batchedByType as $batch) {
|
||||
$class = $batch->class;
|
||||
$invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postPersist);
|
||||
$persister = $this->getEntityPersister($class->name);
|
||||
|
||||
$persister->addInsert($entity);
|
||||
foreach ($batch->entities as $entity) {
|
||||
$oid = spl_object_id($entity);
|
||||
|
||||
unset($this->entityInsertions[$oid]);
|
||||
$persister->addInsert($entity);
|
||||
|
||||
unset($this->entityInsertions[$oid]);
|
||||
}
|
||||
|
||||
$persister->executeInserts();
|
||||
|
||||
if (! isset($this->entityIdentifiers[$oid])) {
|
||||
//entity was not added to identity map because some identifiers are foreign keys to new entities.
|
||||
//add it now
|
||||
$this->addToEntityIdentifiersAndEntityMap($class, $oid, $entity);
|
||||
}
|
||||
foreach ($batch->entities as $entity) {
|
||||
$oid = spl_object_id($entity);
|
||||
|
||||
$invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postPersist);
|
||||
if (! isset($this->entityIdentifiers[$oid])) {
|
||||
//entity was not added to identity map because some identifiers are foreign keys to new entities.
|
||||
//add it now
|
||||
$this->addToEntityIdentifiersAndEntityMap($class, $oid, $entity);
|
||||
}
|
||||
|
||||
if ($invoke !== ListenersInvoker::INVOKE_NONE) {
|
||||
$eventsToDispatch[] = ['class' => $class, 'entity' => $entity, 'invoke' => $invoke];
|
||||
if ($invoke !== ListenersInvoker::INVOKE_NONE) {
|
||||
$eventsToDispatch[] = ['class' => $class, 'entity' => $entity, 'invoke' => $invoke];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3050,11 +3057,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a value is an uninitialized entity.
|
||||
*
|
||||
* @phpstan-assert-if-true InternalProxy $obj
|
||||
*/
|
||||
/** Tests if a value is an uninitialized entity. */
|
||||
public function isUninitializedObject(mixed $obj): bool
|
||||
{
|
||||
if ($this->em->getConfiguration()->isNativeLazyObjectsEnabled() && ! ($obj instanceof Collection) && is_object($obj)) {
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Performance\LazyLoading;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Proxy\InternalProxy as Proxy;
|
||||
use Doctrine\Performance\EntityManagerFactory;
|
||||
use Doctrine\Performance\Mock\NonProxyLoadingEntityManager;
|
||||
@@ -25,9 +26,11 @@ final class ProxyInitializationTimeBench
|
||||
/** @var Proxy[] */
|
||||
private array|null $initializedEmployees = null;
|
||||
|
||||
private EntityManager $em;
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
$proxyFactory = (new NonProxyLoadingEntityManager(EntityManagerFactory::getEntityManager([])))
|
||||
$proxyFactory = (new NonProxyLoadingEntityManager($this->em = EntityManagerFactory::getEntityManager([])))
|
||||
->getProxyFactory();
|
||||
|
||||
for ($i = 0; $i < 10000; ++$i) {
|
||||
@@ -36,36 +39,36 @@ final class ProxyInitializationTimeBench
|
||||
$this->initializedUsers[$i] = $proxyFactory->getProxy(CmsUser::class, ['id' => $i]);
|
||||
$this->initializedEmployees[$i] = $proxyFactory->getProxy(CmsEmployee::class, ['id' => $i]);
|
||||
|
||||
$this->initializedUsers[$i]->__load();
|
||||
$this->initializedEmployees[$i]->__load();
|
||||
$this->em->getUnitOfWork()->initializeObject($this->initializedUsers[$i]);
|
||||
$this->em->getUnitOfWork()->initializeObject($this->initializedEmployees[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
public function benchCmsUserInitialization(): void
|
||||
{
|
||||
foreach ($this->cmsUsers as $proxy) {
|
||||
$proxy->__load();
|
||||
$this->em->getUnitOfWork()->initializeObject($proxy);
|
||||
}
|
||||
}
|
||||
|
||||
public function benchCmsEmployeeInitialization(): void
|
||||
{
|
||||
foreach ($this->cmsEmployees as $proxy) {
|
||||
$proxy->__load();
|
||||
$this->em->getUnitOfWork()->initializeObject($proxy);
|
||||
}
|
||||
}
|
||||
|
||||
public function benchInitializationOfAlreadyInitializedCmsUsers(): void
|
||||
{
|
||||
foreach ($this->initializedUsers as $proxy) {
|
||||
$proxy->__load();
|
||||
$this->em->getUnitOfWork()->initializeObject($proxy);
|
||||
}
|
||||
}
|
||||
|
||||
public function benchInitializationOfAlreadyInitializedCmsEmployees(): void
|
||||
{
|
||||
foreach ($this->initializedEmployees as $proxy) {
|
||||
$proxy->__load();
|
||||
$this->em->getUnitOfWork()->initializeObject($proxy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ use Doctrine\ORM\Persisters\Entity\BasicEntityPersister;
|
||||
*/
|
||||
class EntityPersisterMock extends BasicEntityPersister
|
||||
{
|
||||
/** @var int<0, max> */
|
||||
private int $countOfExecuteInsertCalls = 0;
|
||||
private array $inserts = [];
|
||||
private array $updates = [];
|
||||
private array $deletes = [];
|
||||
@@ -40,6 +42,8 @@ class EntityPersisterMock extends BasicEntityPersister
|
||||
|
||||
public function executeInserts(): void
|
||||
{
|
||||
$this->countOfExecuteInsertCalls += 1;
|
||||
|
||||
foreach ($this->postInsertIds as $item) {
|
||||
$this->em->getUnitOfWork()->assignPostInsertId($item['entity'], $item['generatedId']);
|
||||
}
|
||||
@@ -86,6 +90,7 @@ class EntityPersisterMock extends BasicEntityPersister
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
$this->countOfExecuteInsertCalls = 0;
|
||||
$this->existsCalled = false;
|
||||
$this->identityColumnValueCounter = 0;
|
||||
$this->inserts = [];
|
||||
@@ -97,4 +102,10 @@ class EntityPersisterMock extends BasicEntityPersister
|
||||
{
|
||||
return $this->existsCalled;
|
||||
}
|
||||
|
||||
/** @return int<0, max> */
|
||||
public function countOfExecuteInsertCalls(): int
|
||||
{
|
||||
return $this->countOfExecuteInsertCalls;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\Models\TypedProperties;
|
||||
|
||||
use BcMath\Number;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
@@ -54,6 +55,9 @@ class UserTyped
|
||||
#[ORM\Embedded]
|
||||
public Contact|null $contact = null;
|
||||
|
||||
#[ORM\Column(precision: 5, scale: 2)]
|
||||
public Number|null $bodyHeight = null;
|
||||
|
||||
public static function loadMetadata(ClassMetadata $metadata): void
|
||||
{
|
||||
$metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_NONE);
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM;
|
||||
|
||||
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
|
||||
use Doctrine\ORM\Cache\CacheConfiguration;
|
||||
use Doctrine\ORM\Configuration;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
@@ -17,6 +18,8 @@ use Doctrine\ORM\Proxy\ProxyFactory;
|
||||
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\Tests\Models\DDC753\DDC753CustomRepository;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhp;
|
||||
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
|
||||
@@ -25,6 +28,8 @@ use Psr\Cache\CacheItemPoolInterface;
|
||||
*/
|
||||
class ConfigurationTest extends TestCase
|
||||
{
|
||||
use VerifyDeprecations;
|
||||
|
||||
private Configuration $configuration;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -34,6 +39,7 @@ class ConfigurationTest extends TestCase
|
||||
$this->configuration = new Configuration();
|
||||
}
|
||||
|
||||
#[WithoutErrorHandler]
|
||||
public function testSetGetProxyDir(): void
|
||||
{
|
||||
self::assertNull($this->configuration->getProxyDir()); // defaults
|
||||
@@ -42,6 +48,7 @@ class ConfigurationTest extends TestCase
|
||||
self::assertSame(__DIR__, $this->configuration->getProxyDir());
|
||||
}
|
||||
|
||||
#[WithoutErrorHandler]
|
||||
public function testSetGetAutoGenerateProxyClasses(): void
|
||||
{
|
||||
self::assertSame(ProxyFactory::AUTOGENERATE_ALWAYS, $this->configuration->getAutoGenerateProxyClasses()); // defaults
|
||||
@@ -56,6 +63,7 @@ class ConfigurationTest extends TestCase
|
||||
self::assertSame(ProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS, $this->configuration->getAutoGenerateProxyClasses());
|
||||
}
|
||||
|
||||
#[WithoutErrorHandler]
|
||||
public function testSetGetProxyNamespace(): void
|
||||
{
|
||||
self::assertNull($this->configuration->getProxyNamespace()); // defaults
|
||||
@@ -212,4 +220,28 @@ class ConfigurationTest extends TestCase
|
||||
$this->configuration->setTypedFieldMapper($defaultTypedFieldMapper);
|
||||
self::assertSame($defaultTypedFieldMapper, $this->configuration->getTypedFieldMapper());
|
||||
}
|
||||
|
||||
#[RequiresPhp('8.4')]
|
||||
#[WithoutErrorHandler]
|
||||
public function testDisablingNativeLazyObjectsIsDeprecated(): void
|
||||
{
|
||||
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
|
||||
$this->configuration->enableNativeLazyObjects(false);
|
||||
}
|
||||
|
||||
#[RequiresPhp('<8.4')]
|
||||
public function testNotEnablingNativeLazyObjectIsFineOnPhpLowerThan84(): void
|
||||
{
|
||||
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
self::assertFalse($this->configuration->isNativeLazyObjectsEnabled());
|
||||
}
|
||||
|
||||
#[RequiresPhp('8.4')]
|
||||
#[WithoutErrorHandler]
|
||||
public function testNotEnablingNativeLazyObjectIsDeprecatedOnPhp84(): void
|
||||
{
|
||||
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
self::assertFalse($this->configuration->isNativeLazyObjectsEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@ use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser as CmsUserProxy;
|
||||
|
||||
use function assert;
|
||||
|
||||
/**
|
||||
* Test that Doctrine ORM correctly works with proxy instances exactly like with ordinary Entities
|
||||
*
|
||||
@@ -34,10 +32,6 @@ class ProxiesLikeEntitiesTest extends OrmFunctionalTestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if ($this->_em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
self::markTestSkipped('This test is not applicable when lazy proxy is enabled.');
|
||||
}
|
||||
|
||||
$this->createSchemaForModels(
|
||||
CmsUser::class,
|
||||
CmsTag::class,
|
||||
@@ -83,8 +77,7 @@ class ProxiesLikeEntitiesTest extends OrmFunctionalTestCase
|
||||
{
|
||||
$userId = $this->user->getId();
|
||||
$uninitializedProxy = $this->_em->getReference(CmsUser::class, $userId);
|
||||
assert($uninitializedProxy instanceof CmsUserProxy);
|
||||
self::assertInstanceOf(CmsUserProxy::class, $uninitializedProxy);
|
||||
$this->assertTrue($this->isUninitializedObject($uninitializedProxy));
|
||||
|
||||
$this->_em->persist($uninitializedProxy);
|
||||
$this->_em->flush();
|
||||
@@ -116,6 +109,10 @@ class ProxiesLikeEntitiesTest extends OrmFunctionalTestCase
|
||||
*/
|
||||
public function testFindWithProxyName(): void
|
||||
{
|
||||
if ($this->_em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
self::markTestSkipped('There is no such thing as a proxy class name when native lazy objects are enabled.');
|
||||
}
|
||||
|
||||
$result = $this->_em->find(CmsUserProxy::class, $this->user->getId());
|
||||
self::assertSame($this->user->getId(), $result->getId());
|
||||
$this->_em->clear();
|
||||
|
||||
@@ -14,8 +14,7 @@ use Doctrine\ORM\Mapping\Table;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
|
||||
use function get_class;
|
||||
use ReflectionClass;
|
||||
|
||||
#[Group('GH10808')]
|
||||
class GH10808Test extends OrmFunctionalTestCase
|
||||
@@ -32,10 +31,6 @@ class GH10808Test extends OrmFunctionalTestCase
|
||||
|
||||
public function testDQLDeferredEagerLoad(): void
|
||||
{
|
||||
if ($this->_em->getConfiguration()->isNativeLazyObjectsEnabled()) {
|
||||
self::markTestSkipped('Test requires lazy loading to be disabled');
|
||||
}
|
||||
|
||||
$appointment = new GH10808Appointment();
|
||||
|
||||
$this->_em->persist($appointment);
|
||||
@@ -55,14 +50,13 @@ class GH10808Test extends OrmFunctionalTestCase
|
||||
|
||||
$eagerLoadResult = $query->setHint(UnitOfWork::HINT_DEFEREAGERLOAD, false)->getSingleResult();
|
||||
|
||||
self::assertNotEquals(
|
||||
GH10808AppointmentChild::class,
|
||||
get_class($deferredLoadResult->child),
|
||||
'$deferredLoadResult->child should be a proxy',
|
||||
$reflector = new ReflectionClass(GH10808AppointmentChild::class);
|
||||
self::assertFalse(
|
||||
$this->isUninitializedObject($deferredLoadResult->child),
|
||||
'$deferredLoadResult->child should be a native lazy object',
|
||||
);
|
||||
self::assertEquals(
|
||||
GH10808AppointmentChild::class,
|
||||
get_class($eagerLoadResult->child),
|
||||
self::assertFalse(
|
||||
$this->isUninitializedObject($deferredLoadResult->child),
|
||||
'$eagerLoadResult->child should not be a proxy',
|
||||
);
|
||||
}
|
||||
|
||||
65
tests/Tests/ORM/Functional/Ticket/GH11982Test.php
Normal file
65
tests/Tests/ORM/Functional/Ticket/GH11982Test.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
|
||||
use function reset;
|
||||
|
||||
class GH11982Test extends OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->setUpEntitySchema([
|
||||
GH11982ColumnIndex::class,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Group('GH-11982')]
|
||||
public function testSchema(): void
|
||||
{
|
||||
if ($this->_em->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) {
|
||||
self::markTestSkipped('This test does not work on psql.');
|
||||
}
|
||||
|
||||
$indexes = $this->createSchemaManager()
|
||||
->introspectTable('GH11982ColumnIndex')
|
||||
->getIndexes();
|
||||
|
||||
self::assertCount(3, $indexes); // primary + 2 custom indexes
|
||||
self::assertArrayHasKey('class_idx', $indexes);
|
||||
|
||||
unset($indexes['primary']);
|
||||
unset($indexes['class_idx']);
|
||||
$unnamedIndexColumns = reset($indexes)->getColumns();
|
||||
self::assertCount(1, $unnamedIndexColumns);
|
||||
self::assertEquals('indexTrue', $unnamedIndexColumns[0]);
|
||||
}
|
||||
}
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\Index(
|
||||
name: 'class_idx',
|
||||
fields: ['classIndex'],
|
||||
flags: ['test'],
|
||||
options: ['test'],
|
||||
)]
|
||||
class GH11982ColumnIndex
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column]
|
||||
public string $noIndex;
|
||||
|
||||
#[ORM\Column(index: true)]
|
||||
public string $indexTrue;
|
||||
|
||||
#[ORM\Column]
|
||||
public string $classIndex;
|
||||
}
|
||||
143
tests/Tests/ORM/Internal/UnitOfWork/InsertBatchTest.php
Normal file
143
tests/Tests/ORM/Internal/UnitOfWork/InsertBatchTest.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Internal\UnitOfWork;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Id\IdentityGenerator;
|
||||
use Doctrine\ORM\Internal\UnitOfWork\InsertBatch;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(InsertBatch::class)]
|
||||
#[Group('#11977')]
|
||||
final class InsertBatchTest extends TestCase
|
||||
{
|
||||
private EntityManagerInterface&Stub $entityManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->entityManager = $this->createStub(EntityManagerInterface::class);
|
||||
|
||||
$entityAMetadata = new ClassMetadata(EntityA::class);
|
||||
$entityBMetadata = new ClassMetadata(EntityB::class);
|
||||
$entityCMetadata = new ClassMetadata(EntityC::class);
|
||||
|
||||
$entityAMetadata->idGenerator = new AssignedGenerator();
|
||||
$entityBMetadata->idGenerator = new AssignedGenerator();
|
||||
$entityCMetadata->idGenerator = new IdentityGenerator();
|
||||
|
||||
$this->entityManager->method('getClassMetadata')
|
||||
->willReturnMap([
|
||||
[EntityA::class, $entityAMetadata],
|
||||
[EntityB::class, $entityBMetadata],
|
||||
[EntityC::class, $entityCMetadata],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testWillProduceEmptyBatchOnNoGivenEntities(): void
|
||||
{
|
||||
self::assertEmpty(InsertBatch::batchByEntityType($this->entityManager, []));
|
||||
}
|
||||
|
||||
public function testWillBatchSameEntityOperationsInSingleBatch(): void
|
||||
{
|
||||
$batches = InsertBatch::batchByEntityType(
|
||||
$this->entityManager,
|
||||
[
|
||||
new EntityA(),
|
||||
new EntityA(),
|
||||
new EntityA(),
|
||||
],
|
||||
);
|
||||
|
||||
self::assertCount(1, $batches);
|
||||
self::assertSame(EntityA::class, $batches[0]->class->name);
|
||||
self::assertCount(3, $batches[0]->entities);
|
||||
}
|
||||
|
||||
public function testWillBatchInterleavedEntityOperationsInGroups(): void
|
||||
{
|
||||
$batches = InsertBatch::batchByEntityType(
|
||||
$this->entityManager,
|
||||
[
|
||||
new EntityA(),
|
||||
new EntityA(),
|
||||
new EntityB(),
|
||||
new EntityB(),
|
||||
new EntityA(),
|
||||
new EntityA(),
|
||||
],
|
||||
);
|
||||
|
||||
self::assertCount(3, $batches);
|
||||
self::assertSame(EntityA::class, $batches[0]->class->name);
|
||||
self::assertCount(2, $batches[0]->entities);
|
||||
self::assertSame(EntityB::class, $batches[1]->class->name);
|
||||
self::assertCount(2, $batches[1]->entities);
|
||||
self::assertSame(EntityA::class, $batches[2]->class->name);
|
||||
self::assertCount(2, $batches[2]->entities);
|
||||
}
|
||||
|
||||
public function testWillNotBatchOperationsForAGeneratedIdentifierEntity(): void
|
||||
{
|
||||
$batches = InsertBatch::batchByEntityType(
|
||||
$this->entityManager,
|
||||
[
|
||||
new EntityC(),
|
||||
new EntityC(),
|
||||
new EntityC(),
|
||||
],
|
||||
);
|
||||
|
||||
self::assertCount(3, $batches);
|
||||
self::assertSame(EntityC::class, $batches[0]->class->name);
|
||||
self::assertCount(1, $batches[0]->entities);
|
||||
self::assertSame(EntityC::class, $batches[1]->class->name);
|
||||
self::assertCount(1, $batches[1]->entities);
|
||||
self::assertSame(EntityC::class, $batches[2]->class->name);
|
||||
self::assertCount(1, $batches[2]->entities);
|
||||
}
|
||||
|
||||
public function testWillIsolateBatchesForEntitiesWithGeneratedIdentifiers(): void
|
||||
{
|
||||
$batches = InsertBatch::batchByEntityType(
|
||||
$this->entityManager,
|
||||
[
|
||||
new EntityA(),
|
||||
new EntityA(),
|
||||
new EntityC(),
|
||||
new EntityC(),
|
||||
new EntityA(),
|
||||
new EntityA(),
|
||||
],
|
||||
);
|
||||
|
||||
self::assertCount(4, $batches);
|
||||
self::assertSame(EntityA::class, $batches[0]->class->name);
|
||||
self::assertCount(2, $batches[0]->entities);
|
||||
self::assertSame(EntityC::class, $batches[1]->class->name);
|
||||
self::assertCount(1, $batches[1]->entities);
|
||||
self::assertSame(EntityC::class, $batches[2]->class->name);
|
||||
self::assertCount(1, $batches[2]->entities);
|
||||
self::assertSame(EntityA::class, $batches[3]->class->name);
|
||||
self::assertCount(2, $batches[3]->entities);
|
||||
}
|
||||
}
|
||||
|
||||
class EntityA
|
||||
{
|
||||
}
|
||||
|
||||
class EntityB
|
||||
{
|
||||
}
|
||||
|
||||
class EntityC
|
||||
{
|
||||
}
|
||||
@@ -60,6 +60,7 @@ use function array_keys;
|
||||
use function assert;
|
||||
use function class_exists;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function serialize;
|
||||
use function str_contains;
|
||||
use function str_replace;
|
||||
@@ -199,6 +200,12 @@ class ClassMetadataTest extends OrmTestCase
|
||||
// float
|
||||
$cm->mapField(['fieldName' => 'float']);
|
||||
self::assertEquals('float', $cm->getTypeOfField('float'));
|
||||
|
||||
// number, requires DBAL 4.3+
|
||||
if (defined(Types::class . '::NUMBER')) {
|
||||
$cm->mapField(['fieldName' => 'bodyHeight']);
|
||||
self::assertEquals('number', $cm->getTypeOfField('bodyHeight'));
|
||||
}
|
||||
}
|
||||
|
||||
#[TestGroup('GH10313')]
|
||||
|
||||
@@ -227,11 +227,12 @@ abstract class MappingDriverTestCase extends OrmTestCase
|
||||
#[Depends('testEntityTableNameAndInheritance')]
|
||||
public function testFieldMappings(ClassMetadata $class): ClassMetadata
|
||||
{
|
||||
self::assertEquals(4, count($class->fieldMappings));
|
||||
self::assertEquals(5, count($class->fieldMappings));
|
||||
self::assertTrue(isset($class->fieldMappings['id']));
|
||||
self::assertTrue(isset($class->fieldMappings['name']));
|
||||
self::assertTrue(isset($class->fieldMappings['email']));
|
||||
self::assertTrue(isset($class->fieldMappings['version']));
|
||||
self::assertTrue(isset($class->fieldMappings['indexed']));
|
||||
|
||||
return $class;
|
||||
}
|
||||
@@ -262,6 +263,7 @@ abstract class MappingDriverTestCase extends OrmTestCase
|
||||
self::assertEquals(50, $class->fieldMappings['name']->length);
|
||||
self::assertTrue($class->fieldMappings['name']->nullable);
|
||||
self::assertTrue($class->fieldMappings['name']->unique);
|
||||
self::assertTrue($class->fieldMappings['indexed']->index);
|
||||
|
||||
return $class;
|
||||
}
|
||||
@@ -1006,6 +1008,10 @@ class User
|
||||
#[ORM\Version]
|
||||
public $version;
|
||||
|
||||
/** @var string */
|
||||
#[ORM\Column(index: true)]
|
||||
public $indexed;
|
||||
|
||||
#[ORM\PrePersist]
|
||||
public function doStuffOnPrePersist(): void
|
||||
{
|
||||
@@ -1065,6 +1071,12 @@ class User
|
||||
$mapping = ['fieldName' => 'version', 'type' => 'integer'];
|
||||
$metadata->setVersionMapping($mapping);
|
||||
$metadata->mapField($mapping);
|
||||
$metadata->mapField([
|
||||
'fieldName' => 'indexed',
|
||||
'type' => 'string',
|
||||
'columnName' => 'indexed',
|
||||
'index' => true,
|
||||
]);
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
|
||||
$metadata->mapOneToOne(
|
||||
[
|
||||
|
||||
@@ -11,10 +11,13 @@ use Doctrine\ORM\Mapping\TypedFieldMapper;
|
||||
use Doctrine\Tests\Models\TypedProperties\UserTyped;
|
||||
use Doctrine\Tests\ORM\Mapping\TypedFieldMapper\CustomIntAsStringTypedFieldMapper;
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
use Generator;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use ReflectionClass;
|
||||
|
||||
use function defined;
|
||||
|
||||
#[Group('GH10313')]
|
||||
class TypedFieldMapperTest extends OrmTestCase
|
||||
{
|
||||
@@ -36,7 +39,7 @@ class TypedFieldMapperTest extends OrmTestCase
|
||||
/**
|
||||
* Data Provider for NamingStrategy#classToTableName
|
||||
*
|
||||
* @return array<
|
||||
* @return Generator<
|
||||
* array{
|
||||
* TypedFieldMapper,
|
||||
* ReflectionClass,
|
||||
@@ -44,28 +47,30 @@ class TypedFieldMapperTest extends OrmTestCase
|
||||
* array{fieldName: string, enumType?: string, type?: mixed}
|
||||
* }>
|
||||
*/
|
||||
public static function dataFieldToMappedField(): array
|
||||
public static function dataFieldToMappedField(): Generator
|
||||
{
|
||||
$reflectionClass = new ReflectionClass(UserTyped::class);
|
||||
|
||||
return [
|
||||
// DefaultTypedFieldMapper
|
||||
[self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'id'], ['fieldName' => 'id', 'type' => Types::INTEGER]],
|
||||
[self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'username'], ['fieldName' => 'username', 'type' => Types::STRING]],
|
||||
[self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'dateInterval'], ['fieldName' => 'dateInterval', 'type' => Types::DATEINTERVAL]],
|
||||
[self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'dateTime'], ['fieldName' => 'dateTime', 'type' => Types::DATETIME_MUTABLE]],
|
||||
[self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'dateTimeImmutable'], ['fieldName' => 'dateTimeImmutable', 'type' => Types::DATETIME_IMMUTABLE]],
|
||||
[self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'array'], ['fieldName' => 'array', 'type' => Types::JSON]],
|
||||
[self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'boolean'], ['fieldName' => 'boolean', 'type' => Types::BOOLEAN]],
|
||||
[self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'float'], ['fieldName' => 'float', 'type' => Types::FLOAT]],
|
||||
// DefaultTypedFieldMapper
|
||||
yield [self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'id'], ['fieldName' => 'id', 'type' => Types::INTEGER]];
|
||||
yield [self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'username'], ['fieldName' => 'username', 'type' => Types::STRING]];
|
||||
yield [self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'dateInterval'], ['fieldName' => 'dateInterval', 'type' => Types::DATEINTERVAL]];
|
||||
yield [self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'dateTime'], ['fieldName' => 'dateTime', 'type' => Types::DATETIME_MUTABLE]];
|
||||
yield [self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'dateTimeImmutable'], ['fieldName' => 'dateTimeImmutable', 'type' => Types::DATETIME_IMMUTABLE]];
|
||||
yield [self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'array'], ['fieldName' => 'array', 'type' => Types::JSON]];
|
||||
yield [self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'boolean'], ['fieldName' => 'boolean', 'type' => Types::BOOLEAN]];
|
||||
yield [self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'float'], ['fieldName' => 'float', 'type' => Types::FLOAT]];
|
||||
|
||||
// CustomIntAsStringTypedFieldMapper
|
||||
[self::customTypedFieldMapper(), $reflectionClass, ['fieldName' => 'id'], ['fieldName' => 'id', 'type' => Types::STRING]],
|
||||
if (defined(Types::class . '::NUMBER')) {
|
||||
yield [self::defaultTypedFieldMapper(), $reflectionClass, ['fieldName' => 'bodyHeight'], ['fieldName' => 'bodyHeight', 'type' => Types::NUMBER]];
|
||||
}
|
||||
|
||||
// ChainTypedFieldMapper
|
||||
[self::chainTypedFieldMapper(), $reflectionClass, ['fieldName' => 'id'], ['fieldName' => 'id', 'type' => Types::STRING]],
|
||||
[self::chainTypedFieldMapper(), $reflectionClass, ['fieldName' => 'username'], ['fieldName' => 'username', 'type' => Types::STRING]],
|
||||
];
|
||||
// CustomIntAsStringTypedFieldMapper
|
||||
yield [self::customTypedFieldMapper(), $reflectionClass, ['fieldName' => 'id'], ['fieldName' => 'id', 'type' => Types::STRING]];
|
||||
|
||||
// ChainTypedFieldMapper
|
||||
yield [self::chainTypedFieldMapper(), $reflectionClass, ['fieldName' => 'id'], ['fieldName' => 'id', 'type' => Types::STRING]];
|
||||
yield [self::chainTypedFieldMapper(), $reflectionClass, ['fieldName' => 'username'], ['fieldName' => 'username', 'type' => Types::STRING]];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -183,7 +183,7 @@ class XmlMappingDriverTest extends MappingDriverTestCase
|
||||
[
|
||||
User::class,
|
||||
'cms_users',
|
||||
['name', 'email', 'version', 'id'],
|
||||
['name', 'email', 'version', 'indexed', 'id'],
|
||||
['address', 'phonenumbers', 'groups'],
|
||||
],
|
||||
[
|
||||
|
||||
@@ -56,6 +56,8 @@
|
||||
|
||||
<field name="version" type="integer" version="true" />
|
||||
|
||||
<field name="indexed" type="string" index="true" />
|
||||
|
||||
<one-to-one field="address" target-entity="Address" inversed-by="user">
|
||||
<cascade><cascade-remove /></cascade>
|
||||
<join-column name="address_id" referenced-column-name="id" on-delete="CASCADE" />
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM;
|
||||
|
||||
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
|
||||
use Doctrine\ORM\Configuration;
|
||||
use Doctrine\ORM\Mapping as MappingNamespace;
|
||||
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
|
||||
@@ -12,6 +13,7 @@ use Doctrine\ORM\ORMSetup;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use PHPUnit\Framework\Attributes\RequiresSetting;
|
||||
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionProperty;
|
||||
use Symfony\Component\Cache\Adapter\AbstractAdapter;
|
||||
@@ -20,10 +22,19 @@ use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
|
||||
use function sys_get_temp_dir;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
class ORMSetupTest extends TestCase
|
||||
{
|
||||
use VerifyDeprecations;
|
||||
|
||||
#[WithoutErrorHandler]
|
||||
public function testAttributeConfiguration(): void
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
}
|
||||
|
||||
$config = ORMSetup::createAttributeMetadataConfiguration([], true);
|
||||
|
||||
self::assertInstanceOf(Configuration::class, $config);
|
||||
@@ -32,8 +43,21 @@ class ORMSetupTest extends TestCase
|
||||
self::assertInstanceOf(AttributeDriver::class, $config->getMetadataDriverImpl());
|
||||
}
|
||||
|
||||
public function testAttributeConfig(): void
|
||||
{
|
||||
$config = ORMSetup::createAttributeMetadataConfig([], true);
|
||||
|
||||
self::assertInstanceOf(Configuration::class, $config);
|
||||
self::assertInstanceOf(AttributeDriver::class, $config->getMetadataDriverImpl());
|
||||
}
|
||||
|
||||
#[WithoutErrorHandler]
|
||||
public function testXMLConfiguration(): void
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
}
|
||||
|
||||
$config = ORMSetup::createXMLMetadataConfiguration([], true);
|
||||
|
||||
self::assertInstanceOf(Configuration::class, $config);
|
||||
@@ -44,14 +68,18 @@ class ORMSetupTest extends TestCase
|
||||
{
|
||||
$this->expectNotToPerformAssertions();
|
||||
|
||||
ORMSetup::createXMLMetadataConfiguration(paths: [], isXsdValidationEnabled: false);
|
||||
ORMSetup::createXMLMetadataConfig(paths: [], isXsdValidationEnabled: false);
|
||||
}
|
||||
|
||||
#[RequiresPhpExtension('apcu')]
|
||||
#[RequiresSetting('apc.enable_cli', '1')]
|
||||
#[RequiresSetting('apc.enabled', '1')]
|
||||
public function testCacheNamespaceShouldBeGeneratedForApcu(): void
|
||||
public function testCacheNamespaceShouldBeGeneratedForApcuWhenUsingLegacyConstructor(): void
|
||||
{
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/12005');
|
||||
}
|
||||
|
||||
$config = ORMSetup::createConfiguration(false, '/foo');
|
||||
$cache = $config->getMetadataCache();
|
||||
|
||||
@@ -61,7 +89,22 @@ class ORMSetupTest extends TestCase
|
||||
self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf:', $namespaceProperty->getValue($cache));
|
||||
}
|
||||
|
||||
#[RequiresPhpExtension('apcu')]
|
||||
#[RequiresSetting('apc.enable_cli', '1')]
|
||||
#[RequiresSetting('apc.enabled', '1')]
|
||||
public function testCacheNamespaceShouldBeGeneratedForApcu(): void
|
||||
{
|
||||
$config = ORMSetup::createConfig(false, '/foo');
|
||||
$cache = $config->getMetadataCache();
|
||||
|
||||
$namespaceProperty = new ReflectionProperty(AbstractAdapter::class, 'namespace');
|
||||
|
||||
self::assertInstanceOf(ApcuAdapter::class, $cache);
|
||||
self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf:', $namespaceProperty->getValue($cache));
|
||||
}
|
||||
|
||||
#[Group('DDC-1350')]
|
||||
#[WithoutErrorHandler]
|
||||
public function testConfigureProxyDir(): void
|
||||
{
|
||||
$config = ORMSetup::createAttributeMetadataConfiguration([], true, '/foo');
|
||||
@@ -72,7 +115,7 @@ class ORMSetupTest extends TestCase
|
||||
public function testConfigureCache(): void
|
||||
{
|
||||
$cache = new ArrayAdapter();
|
||||
$config = ORMSetup::createAttributeMetadataConfiguration([], true, null, $cache);
|
||||
$config = ORMSetup::createAttributeMetadataConfig([], true, null, $cache);
|
||||
|
||||
self::assertSame($cache, $config->getResultCache());
|
||||
self::assertSame($cache, $config->getQueryCache());
|
||||
@@ -83,7 +126,7 @@ class ORMSetupTest extends TestCase
|
||||
public function testConfigureCacheCustomInstance(): void
|
||||
{
|
||||
$cache = new ArrayAdapter();
|
||||
$config = ORMSetup::createConfiguration(true, null, $cache);
|
||||
$config = ORMSetup::createConfig(true, null, $cache);
|
||||
|
||||
self::assertSame($cache, $config->getResultCache());
|
||||
self::assertSame($cache, $config->getQueryCache());
|
||||
|
||||
@@ -11,7 +11,9 @@ use Doctrine\Tests\Models\Cache\AttractionInfo;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandCompletionTester;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
@@ -77,4 +79,37 @@ class MappingDescribeCommandTest extends OrmFunctionalTestCase
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $input
|
||||
* @param string[] $expectedSuggestions
|
||||
*/
|
||||
#[DataProvider('provideCompletionSuggestions')]
|
||||
public function testComplete(array $input, array $expectedSuggestions): void
|
||||
{
|
||||
$this->useModelSet('cache');
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$completionTester = new CommandCompletionTester(new MappingDescribeCommand(new SingleManagerProvider($this->_em)));
|
||||
|
||||
$suggestions = $completionTester->complete($input);
|
||||
|
||||
foreach ($expectedSuggestions as $expected) {
|
||||
self::assertContains($expected, $suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return iterable<string, array{string[], string[]}> */
|
||||
public static function provideCompletionSuggestions(): iterable
|
||||
{
|
||||
yield 'entityName' => [
|
||||
[''],
|
||||
[
|
||||
'Doctrine\\\\Tests\\\\Models\\\\Cache\\\\Restaurant',
|
||||
'Doctrine\\\\Tests\\\\Models\\\\Cache\\\\Beach',
|
||||
'Doctrine\\\\Tests\\\\Models\\\\Cache\\\\Bar',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ use Doctrine\Tests\Models\CMS\CmsPhonenumber;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
use Doctrine\Tests\Models\Forum\ForumAvatar;
|
||||
use Doctrine\Tests\Models\Forum\ForumUser;
|
||||
use Doctrine\Tests\Models\MixedToOneIdentity\Country;
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
use Exception as BaseException;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
@@ -143,6 +144,25 @@ class UnitOfWorkTest extends OrmTestCase
|
||||
self::assertIsNumeric($user->id);
|
||||
}
|
||||
|
||||
#[Group('#11977')]
|
||||
public function testMultipleInsertsAreBatchedInThePersister(): void
|
||||
{
|
||||
$userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(Country::class));
|
||||
$this->_unitOfWork->setEntityPersister(Country::class, $userPersister);
|
||||
|
||||
$country1 = new Country();
|
||||
$country1->country = 'Italy';
|
||||
$country2 = new Country();
|
||||
$country2->country = 'Germany';
|
||||
|
||||
$this->_unitOfWork->persist($country1);
|
||||
$this->_unitOfWork->persist($country2);
|
||||
$this->_unitOfWork->commit();
|
||||
|
||||
self::assertCount(2, $userPersister->getInserts());
|
||||
self::assertSame(1, $userPersister->countOfExecuteInsertCalls());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a scenario where a save() operation is cascaded from a ForumUser
|
||||
* to its associated ForumAvatar, both entities using IDENTITY id generation.
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Doctrine\Tests\Proxy;
|
||||
|
||||
use Doctrine\ORM\Proxy\Autoloader;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function class_exists;
|
||||
@@ -31,6 +32,7 @@ class AutoloaderTest extends TestCase
|
||||
|
||||
/** @param class-string $className */
|
||||
#[DataProvider('dataResolveFile')]
|
||||
#[WithoutErrorHandler]
|
||||
public function testResolveFile(
|
||||
string $proxyDir,
|
||||
string $proxyNamespace,
|
||||
@@ -41,6 +43,7 @@ class AutoloaderTest extends TestCase
|
||||
self::assertEquals($expectedProxyFile, $actualProxyFile);
|
||||
}
|
||||
|
||||
#[WithoutErrorHandler]
|
||||
public function testAutoload(): void
|
||||
{
|
||||
if (file_exists(sys_get_temp_dir() . '/AutoloaderTestClass.php')) {
|
||||
|
||||
@@ -100,14 +100,14 @@ class TestUtil
|
||||
$enableNativeLazyObjects = true;
|
||||
}
|
||||
|
||||
$configuration->setProxyDir(__DIR__ . '/Proxies');
|
||||
$configuration->setProxyNamespace('Doctrine\Tests\Proxies');
|
||||
|
||||
if (PHP_VERSION_ID >= 80400 && $enableNativeLazyObjects) {
|
||||
$configuration->enableNativeLazyObjects(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$configuration->setProxyDir(__DIR__ . '/Proxies');
|
||||
$configuration->setProxyNamespace('Doctrine\Tests\Proxies');
|
||||
}
|
||||
|
||||
private static function initializeDatabase(): void
|
||||
|
||||
Reference in New Issue
Block a user