Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DBAL 4 compatibility #9950

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Result;
use Doctrine\ORM\Cache\Logging\CacheLogger;
use Doctrine\ORM\Cache\QueryCacheKey;
Expand Down Expand Up @@ -327,15 +328,15 @@ public function setParameters(ArrayCollection|array $parameters): static
/**
* Sets a query parameter.
*
* @param string|int $key The parameter position or name.
* @param mixed $value The parameter value.
* @param string|int|null $type The parameter type. If specified, the given value will be run through
* the type conversion of this type. This is usually not needed for
* strings and numeric types.
* @param string|int $key The parameter position or name.
* @param mixed $value The parameter value.
* @param ParameterType|string|int|null $type The parameter type. If specified, the given value will be run through
* the type conversion of this type. This is usually not needed for
* strings and numeric types.
*
* @return $this
*/
public function setParameter(string|int $key, mixed $value, string|int|null $type = null): static
public function setParameter(string|int $key, mixed $value, ParameterType|string|int|null $type = null): static
{
$existingParameter = $this->getParameter($key);

Expand Down
81 changes: 61 additions & 20 deletions lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Cache;
use Doctrine\ORM\Cache\CollectionCacheKey;
use Doctrine\ORM\Cache\EntityCacheKey;
Expand Down Expand Up @@ -83,8 +84,14 @@ public function getInserts(): array
return $this->persister->getInserts();
}

public function getSelectSQL(array|Criteria $criteria, ?array $assoc = null, ?int $lockMode = null, ?int $limit = null, ?int $offset = null, ?array $orderBy = null): string
{
public function getSelectSQL(
array|Criteria $criteria,
?array $assoc = null,
LockMode|int|null $lockMode = null,
?int $limit = null,
?int $offset = null,
?array $orderBy = null
): string {
return $this->persister->getSelectSQL($criteria, $assoc, $lockMode, $limit, $offset, $orderBy);
}

Expand All @@ -103,8 +110,12 @@ public function getResultSetMapping(): ResultSetMapping
return $this->persister->getResultSetMapping();
}

public function getSelectConditionStatementSQL(string $field, mixed $value, ?array $assoc = null, ?string $comparison = null): string
{
public function getSelectConditionStatementSQL(
string $field,
mixed $value,
?array $assoc = null,
?string $comparison = null
): string {
return $this->persister->getSelectConditionStatementSQL($field, $value, $assoc, $comparison);
}

Expand Down Expand Up @@ -191,8 +202,13 @@ private function storeJoinedAssociations(object $entity): void
* @param string[]|Criteria $criteria
* @param string[] $orderBy
*/
protected function getHash(string $query, array|Criteria $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): string
{
protected function getHash(
string $query,
array|Criteria $criteria,
?array $orderBy = null,
?int $limit = null,
?int $offset = null
): string {
[$params] = $criteria instanceof Criteria
? $this->persister->expandCriteriaParameters($criteria)
: $this->persister->expandParameters($criteria);
Expand Down Expand Up @@ -224,16 +240,24 @@ public function getClassMetadata(): ClassMetadata
/**
* {@inheritdoc}
*/
public function getManyToManyCollection(array $assoc, object $sourceEntity, ?int $offset = null, ?int $limit = null): array
{
public function getManyToManyCollection(
array $assoc,
object $sourceEntity,
?int $offset = null,
?int $limit = null
): array {
return $this->persister->getManyToManyCollection($assoc, $sourceEntity, $offset, $limit);
}

/**
* {@inheritdoc}
*/
public function getOneToManyCollection(array $assoc, object $sourceEntity, ?int $offset = null, ?int $limit = null): array
{
public function getOneToManyCollection(
array $assoc,
object $sourceEntity,
?int $offset = null,
?int $limit = null
): array {
return $this->persister->getOneToManyCollection($assoc, $sourceEntity, $offset, $limit);
}

Expand All @@ -255,8 +279,15 @@ public function executeInserts(): array
/**
* {@inheritdoc}
*/
public function load(array $criteria, ?object $entity = null, ?array $assoc = null, array $hints = [], ?int $lockMode = null, ?int $limit = null, ?array $orderBy = null): ?object
{
public function load(
array $criteria,
?object $entity = null,
?array $assoc = null,
array $hints = [],
LockMode|int|null $lockMode = null,
?int $limit = null,
?array $orderBy = null
): ?object {
if ($entity !== null || $assoc !== null || $hints !== [] || $lockMode !== null) {
return $this->persister->load($criteria, $entity, $assoc, $hints, $lockMode, $limit, $orderBy);
}
Expand Down Expand Up @@ -295,8 +326,12 @@ public function load(array $criteria, ?object $entity = null, ?array $assoc = nu
/**
* {@inheritdoc}
*/
public function loadAll(array $criteria = [], ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
{
public function loadAll(
array $criteria = [],
?array $orderBy = null,
?int $limit = null,
?int $offset = null
): array {
$query = $this->persister->getSelectSQL($criteria, null, null, $limit, $offset, $orderBy);
$hash = $this->getHash($query, $criteria);
$rsm = $this->getResultSetMapping();
Expand Down Expand Up @@ -419,8 +454,11 @@ public function loadCriteria(Criteria $criteria): array
/**
* {@inheritdoc}
*/
public function loadManyToManyCollection(array $assoc, object $sourceEntity, PersistentCollection $collection): array
{
public function loadManyToManyCollection(
array $assoc,
object $sourceEntity,
PersistentCollection $collection
): array {
$persister = $this->uow->getCollectionPersister($assoc);
$hasCache = ($persister instanceof CachedPersister);

Expand Down Expand Up @@ -450,8 +488,11 @@ public function loadManyToManyCollection(array $assoc, object $sourceEntity, Per
/**
* {@inheritdoc}
*/
public function loadOneToManyCollection(array $assoc, object $sourceEntity, PersistentCollection $collection): mixed
{
public function loadOneToManyCollection(
array $assoc,
object $sourceEntity,
PersistentCollection $collection
): mixed {
$persister = $this->uow->getCollectionPersister($assoc);
$hasCache = ($persister instanceof CachedPersister);

Expand Down Expand Up @@ -489,15 +530,15 @@ public function loadOneToOneEntity(array $assoc, object $sourceEntity, array $id
/**
* {@inheritdoc}
*/
public function lock(array $criteria, int $lockMode): void
public function lock(array $criteria, LockMode|int $lockMode): void
{
$this->persister->lock($criteria, $lockMode);
}

/**
* {@inheritdoc}
*/
public function refresh(array $id, object $entity, ?int $lockMode = null): void
public function refresh(array $id, object $entity, LockMode|int|null $lockMode = null): void
{
$this->persister->refresh($id, $entity, $lockMode);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Cache;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -119,12 +120,12 @@ public function close(): void
/**
* {@inheritdoc}
*/
public function lock(object $entity, int $lockMode, $lockVersion = null): void
public function lock(object $entity, LockMode|int $lockMode, $lockVersion = null): void
{
$this->wrapped->lock($entity, $lockMode, $lockVersion);
}

public function find(string $className, mixed $id, ?int $lockMode = null, ?int $lockVersion = null): ?object
public function find(string $className, mixed $id, LockMode|int|null $lockMode = null, ?int $lockVersion = null): ?object
{
return $this->wrapped->find($className, $id, $lockMode, $lockVersion);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function flush(): void
/**
* {@inheritdoc}
*/
public function find($className, mixed $id, ?int $lockMode = null, ?int $lockVersion = null): ?object
public function find($className, mixed $id, LockMode|int|null $lockMode = null, ?int $lockVersion = null): ?object
{
$class = $this->metadataFactory->getMetadataFor(ltrim($className, '\\'));

Expand Down Expand Up @@ -520,7 +520,7 @@ public function detach(object $object): void
/**
* {@inheritDoc}
*/
public function lock(object $entity, int $lockMode, $lockVersion = null): void
public function lock(object $entity, LockMode|int $lockMode, $lockVersion = null): void
{
$this->unitOfWork->lock($entity, $lockMode, $lockVersion);
}
Expand Down Expand Up @@ -689,7 +689,7 @@ public function hasFilters(): bool
* @throws OptimisticLockException
* @throws TransactionRequiredException
*/
private function checkLockRequirements(int $lockMode, ClassMetadata $class): void
private function checkLockRequirements(LockMode|int $lockMode, ClassMetadata $class): void
{
switch ($lockMode) {
case LockMode::OPTIMISTIC:
Expand Down
18 changes: 9 additions & 9 deletions lib/Doctrine/ORM/EntityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ public function createQueryBuilder(): QueryBuilder;
/**
* Finds an Entity by its identifier.
*
* @param string $className The class name of the entity to find.
* @param mixed $id The identity of the entity to find.
* @param int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* during the search.
* @param int|null $lockVersion The version of the entity to find when using
* optimistic locking.
* @param string $className The class name of the entity to find.
* @param mixed $id The identity of the entity to find.
* @param LockMode|int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* during the search.
* @param int|null $lockVersion The version of the entity to find when using
* optimistic locking.
* @psalm-param class-string<T> $className
* @psalm-param LockMode::*|null $lockMode
*
Expand All @@ -130,7 +130,7 @@ public function createQueryBuilder(): QueryBuilder;
*
* @template T of object
*/
public function find(string $className, mixed $id, ?int $lockMode = null, ?int $lockVersion = null): ?object;
public function find(string $className, mixed $id, LockMode|int|null $lockMode = null, ?int $lockVersion = null): ?object;

/**
* Gets a reference to the entity identified by the given type and identifier
Expand Down Expand Up @@ -189,7 +189,7 @@ public function close(): void;
* @throws OptimisticLockException
* @throws PessimisticLockException
*/
public function lock(object $entity, int $lockMode, $lockVersion = null): void;
public function lock(object $entity, LockMode|int $lockMode, $lockVersion = null): void;

/**
* Gets the EventManager used by the EntityManager.
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ public function createResultSetMappingBuilder(string $alias): ResultSetMappingBu
/**
* Finds an entity by its primary key / identifier.
*
* @param int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* during the search.
* @param LockMode|int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* during the search.
* @psalm-param LockMode::*|null $lockMode
*
* @return object|null The entity instance or NULL if the entity can not be found.
* @psalm-return ?T
*/
public function find(mixed $id, ?int $lockMode = null, ?int $lockVersion = null): ?object
public function find(mixed $id, LockMode|int|null $lockMode = null, ?int $lockVersion = null): ?object
{
return $this->em->find($this->entityName, $id, $lockMode, $lockVersion);
}
Expand Down
10 changes: 9 additions & 1 deletion lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use BadMethodCallException;
use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Persisters\SqlValueVisitor;
Expand Down Expand Up @@ -86,7 +87,14 @@ public function get(PersistentCollection $collection, mixed $index): mixed
? $mapping['inversedBy']
: $mapping['mappedBy'];

return $persister->load([$mappedKey => $collection->getOwner(), $mapping['indexBy'] => $index], null, $mapping, [], 0, 1);
return $persister->load(
[$mappedKey => $collection->getOwner(), $mapping['indexBy'] => $index],
null,
$mapping,
[],
LockMode::NONE,
1
);
}

public function count(PersistentCollection $collection): int
Expand Down
Loading