Skip to content

Commit

Permalink
Extract AssociationMapping in its own DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Jan 21, 2023
1 parent 8c4ffc1 commit 62ce4df
Show file tree
Hide file tree
Showing 42 changed files with 821 additions and 548 deletions.
17 changes: 8 additions & 9 deletions lib/Doctrine/ORM/Cache/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\ORM\Cache\Persister\Collection\CachedCollectionPersister;
use Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\Collection\CollectionPersister;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
Expand All @@ -22,12 +23,12 @@ interface CacheFactory
*/
public function buildCachedEntityPersister(EntityManagerInterface $em, EntityPersister $persister, ClassMetadata $metadata): CachedEntityPersister;

/**
* Build a collection persister for the given relation mapping.
*
* @param mixed[] $mapping The association mapping.
*/
public function buildCachedCollectionPersister(EntityManagerInterface $em, CollectionPersister $persister, array $mapping): CachedCollectionPersister;
/** Build a collection persister for the given relation mapping. */
public function buildCachedCollectionPersister(
EntityManagerInterface $em,
CollectionPersister $persister,
AssociationMapping $mapping,
): CachedCollectionPersister;

/**
* Build a query cache based on the given region name
Expand All @@ -41,10 +42,8 @@ public function buildEntityHydrator(EntityManagerInterface $em, ClassMetadata $m

/**
* Build a collection hydrator
*
* @param mixed[] $mapping The association mapping.
*/
public function buildCollectionHydrator(EntityManagerInterface $em, array $mapping): CollectionHydrator;
public function buildCollectionHydrator(EntityManagerInterface $em, AssociationMapping $mapping): CollectionHydrator;

/**
* Build a cache region
Expand Down
16 changes: 7 additions & 9 deletions lib/Doctrine/ORM/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\ORM\Cache\Region\FileLockRegion;
use Doctrine\ORM\Cache\Region\UpdateTimestampCache;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\Collection\CollectionPersister;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
Expand Down Expand Up @@ -87,11 +88,11 @@ public function buildCachedEntityPersister(EntityManagerInterface $em, EntityPer
throw new InvalidArgumentException(sprintf('Unrecognized access strategy type [%s]', $usage));
}

/**
* {@inheritdoc}
*/
public function buildCachedCollectionPersister(EntityManagerInterface $em, CollectionPersister $persister, array $mapping): CachedCollectionPersister
{
public function buildCachedCollectionPersister(
EntityManagerInterface $em,
CollectionPersister $persister,
AssociationMapping $mapping,
): CachedCollectionPersister {
$usage = $mapping['cache']['usage'];
$region = $this->getRegion($mapping['cache']);

Expand Down Expand Up @@ -127,10 +128,7 @@ public function buildQueryCache(EntityManagerInterface $em, string|null $regionN
);
}

/**
* {@inheritdoc}
*/
public function buildCollectionHydrator(EntityManagerInterface $em, array $mapping): CollectionHydrator
public function buildCollectionHydrator(EntityManagerInterface $em, AssociationMapping $mapping): CollectionHydrator
{
return new DefaultCollectionHydrator($em);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/Doctrine/ORM/Cache/DefaultQueryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\ORM\Cache\Logging\CacheLogger;
use Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Query;
Expand Down Expand Up @@ -296,12 +297,10 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, mixed $result, ar
}

/**
* @param array<string,mixed> $assoc
*
* @return mixed[]|null
* @psalm-return array{targetEntity: class-string, type: mixed, list?: array[], identifier?: array}|null
*/
private function storeAssociationCache(QueryCacheKey $key, array $assoc, mixed $assocValue): array|null
private function storeAssociationCache(QueryCacheKey $key, AssociationMapping $assoc, mixed $assocValue): array|null
{
$assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
$assocMetadata = $assocPersister->getClassMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister;
use Doctrine\ORM\Cache\Region;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\PersistentCollection;
Expand All @@ -37,12 +38,11 @@ abstract class AbstractCollectionPersister implements CachedCollectionPersister
protected CollectionHydrator $hydrator;
protected CacheLogger|null $cacheLogger;

/** @param mixed[] $association The association mapping. */
public function __construct(
protected CollectionPersister $persister,
protected Region $region,
EntityManagerInterface $em,
protected array $association,
protected AssociationMapping $association,
) {
$configuration = $em->getConfiguration();
$cacheConfig = $configuration->getSecondLevelCacheConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
use Doctrine\ORM\Cache\CollectionCacheKey;
use Doctrine\ORM\Cache\ConcurrentRegion;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Persisters\Collection\CollectionPersister;

use function spl_object_id;

class ReadWriteCachedCollectionPersister extends AbstractCollectionPersister
{
/** @param mixed[] $association The association mapping. */
public function __construct(CollectionPersister $persister, ConcurrentRegion $region, EntityManagerInterface $em, array $association)
{
public function __construct(
CollectionPersister $persister,
ConcurrentRegion $region,
EntityManagerInterface $em,
AssociationMapping $association,
) {
parent::__construct($persister, $region, $em, $association);
}

Expand Down
27 changes: 11 additions & 16 deletions lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\ORM\Cache\TimestampCacheKey;
use Doctrine\ORM\Cache\TimestampRegion;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\PersistentCollection;
Expand Down Expand Up @@ -86,7 +87,7 @@ public function getInserts(): array

public function getSelectSQL(
array|Criteria $criteria,
array|null $assoc = null,
AssociationMapping|null $assoc = null,
LockMode|int|null $lockMode = null,
int|null $limit = null,
int|null $offset = null,
Expand All @@ -113,7 +114,7 @@ public function getResultSetMapping(): ResultSetMapping
public function getSelectConditionStatementSQL(
string $field,
mixed $value,
array|null $assoc = null,
AssociationMapping|null $assoc = null,
string|null $comparison = null,
): string {
return $this->persister->getSelectConditionStatementSQL($field, $value, $assoc, $comparison);
Expand Down Expand Up @@ -241,7 +242,7 @@ public function getClassMetadata(): ClassMetadata
* {@inheritdoc}
*/
public function getManyToManyCollection(
array $assoc,
AssociationMapping $assoc,
object $sourceEntity,
int|null $offset = null,
int|null $limit = null,
Expand All @@ -253,7 +254,7 @@ public function getManyToManyCollection(
* {@inheritdoc}
*/
public function getOneToManyCollection(
array $assoc,
AssociationMapping $assoc,
object $sourceEntity,
int|null $offset = null,
int|null $limit = null,
Expand Down Expand Up @@ -282,7 +283,7 @@ public function executeInserts(): array
public function load(
array $criteria,
object|null $entity = null,
array|null $assoc = null,
AssociationMapping|null $assoc = null,
array $hints = [],
LockMode|int|null $lockMode = null,
int|null $limit = null,
Expand Down Expand Up @@ -455,7 +456,7 @@ public function loadCriteria(Criteria $criteria): array
* {@inheritdoc}
*/
public function loadManyToManyCollection(
array $assoc,
AssociationMapping $assoc,
object $sourceEntity,
PersistentCollection $collection,
): array {
Expand Down Expand Up @@ -485,11 +486,8 @@ public function loadManyToManyCollection(
return $list;
}

/**
* {@inheritdoc}
*/
public function loadOneToManyCollection(
array $assoc,
AssociationMapping $assoc,
object $sourceEntity,
PersistentCollection $collection,
): mixed {
Expand Down Expand Up @@ -522,7 +520,7 @@ public function loadOneToManyCollection(
/**
* {@inheritdoc}
*/
public function loadOneToOneEntity(array $assoc, object $sourceEntity, array $identifier = []): object|null
public function loadOneToOneEntity(AssociationMapping $assoc, object $sourceEntity, array $identifier = []): object|null
{
return $this->persister->loadOneToOneEntity($assoc, $sourceEntity, $identifier);
}
Expand All @@ -543,11 +541,8 @@ public function refresh(array $id, object $entity, LockMode|int|null $lockMode =
$this->persister->refresh($id, $entity, $lockMode);
}

/**
* @param array<string, mixed> $association
* @param array<string, mixed> $ownerId
*/
protected function buildCollectionCacheKey(array $association, array $ownerId): CollectionCacheKey
/** @param array<string, mixed> $ownerId */
protected function buildCollectionCacheKey(AssociationMapping $association, array $ownerId): CollectionCacheKey
{
$metadata = $this->metadataFactory->getMetadataFor($association['sourceEntity']);
assert($metadata instanceof ClassMetadata);
Expand Down
20 changes: 7 additions & 13 deletions lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,24 @@ public function getSequenceName(array $definition, ClassMetadata $class, Abstrac
return $definition['sequenceName'];
}

/**
* {@inheritdoc}
*/
public function getJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
public function getJoinColumnName(JoinColumnData $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
{
return $joinColumn['name'];
}

/**
* {@inheritdoc}
*/
public function getReferencedJoinColumnName(
array $joinColumn,
JoinColumnData $joinColumn,
ClassMetadata $class,
AbstractPlatform $platform,
): string {
return $joinColumn['referencedColumnName'];
}

/**
* {@inheritdoc}
*/
public function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform): string
{
public function getJoinTableName(
AssociationMapping $association,
ClassMetadata $class,
AbstractPlatform $platform,
): string {
return $association['joinTable']['name'];
}

Expand Down
Loading

0 comments on commit 62ce4df

Please sign in to comment.