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

Add native types to EntityHydrator #9396

Merged
merged 1 commit into from
Jan 19, 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
35 changes: 8 additions & 27 deletions lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,20 @@
*/
class DefaultEntityHydrator implements EntityHydrator
{
/** @var EntityManagerInterface */
private $em;

/** @var UnitOfWork */
private $uow;

/**
* The IdentifierFlattener used for manipulating identifiers
*
* @var IdentifierFlattener
*/
private $identifierFlattener;
private UnitOfWork $uow;
private IdentifierFlattener $identifierFlattener;

/** @var array<string,mixed> */
private static $hints = [Query::HINT_CACHE_ENABLED => true];
private static array $hints = [Query::HINT_CACHE_ENABLED => true];

/**
* @param EntityManagerInterface $em The entity manager.
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
public function __construct(
private EntityManagerInterface $em
) {
$this->uow = $em->getUnitOfWork();
$this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory());
}

/**
* {@inheritdoc}
*/
public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $entity)
public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, object $entity): EntityCacheEntry
{
$data = $this->uow->getOriginalEntityData($entity);
$data = array_merge($data, $metadata->getIdentifierValues($entity)); // why update has no identifier values ?
Expand Down Expand Up @@ -139,10 +123,7 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $e
return new EntityCacheEntry($metadata->name, $data);
}

/**
* {@inheritdoc}
*/
public function loadCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, EntityCacheEntry $entry, $entity = null)
public function loadCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, EntityCacheEntry $entry, ?object $entity = null): ?object
{
$data = $entry->data;
$hints = self::$hints;
Expand Down
8 changes: 2 additions & 6 deletions lib/Doctrine/ORM/Cache/EntityHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@ interface EntityHydrator
* @param ClassMetadata $metadata The entity metadata.
* @param EntityCacheKey $key The entity cache key.
* @param object $entity The entity.
*
* @return EntityCacheEntry
*/
public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $entity);
public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, object $entity): EntityCacheEntry;

/**
* @param ClassMetadata $metadata The entity metadata.
* @param EntityCacheKey $key The entity cache key.
* @param EntityCacheEntry $entry The entity cache entry.
* @param object|null $entity The entity to load the cache into. If not specified, a new entity is created.
*
* @return object|null
*/
public function loadCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, EntityCacheEntry $entry, $entity = null);
public function loadCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, EntityCacheEntry $entry, ?object $entity = null): ?object;
}
11 changes: 4 additions & 7 deletions tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Doctrine\ORM\Cache\EntityCacheEntry;
use Doctrine\ORM\Cache\EntityCacheKey;
use Doctrine\ORM\Cache\EntityHydrator;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Tests\Mocks\EntityManagerMock;
use Doctrine\Tests\Models\Cache\Country;
use Doctrine\Tests\Models\Cache\State;
use Doctrine\Tests\OrmTestCase;
Expand All @@ -21,11 +21,8 @@
*/
class DefaultEntityHydratorTest extends OrmTestCase
{
/** @var EntityHydrator */
private $structure;

/** @var EntityManagerInterface */
private $em;
private DefaultEntityHydrator $structure;
private EntityManagerMock $em;

protected function setUp(): void
{
Expand All @@ -37,7 +34,7 @@ protected function setUp(): void

public function testImplementsEntityEntryStructure(): void
{
self::assertInstanceOf('\Doctrine\ORM\Cache\EntityHydrator', $this->structure);
self::assertInstanceOf(EntityHydrator::class, $this->structure);
}

public function testCreateEntity(): void
Expand Down