Skip to content

Commit

Permalink
Merge pull request doctrine#8662 from greg0ire/2.9.x
Browse files Browse the repository at this point in the history
Merge 2.8.x into 2.9.x
  • Loading branch information
greg0ire authored Apr 29, 2021
2 parents b0826fd + f296fee commit dacdcf2
Show file tree
Hide file tree
Showing 24 changed files with 81 additions and 311 deletions.
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
/tools export-ignore
/docs export-ignore
/.github export-ignore
.doctrine-project.json export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.gitmodules export-ignore
.travis.yml export-ignore
build.properties export-ignore
build.properties.dev export-ignore
build.xml export-ignore
Expand All @@ -15,4 +14,6 @@ run-all.sh export-ignore
phpcs.xml.dist export-ignore
phpbench.json export-ignore
phpstan.neon export-ignore
phpstan-baseline.neon export-ignore
psalm.xml export-ignore
psalm-baseline.xml export-ignore
4 changes: 2 additions & 2 deletions docs/en/reference/batch-processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ with the batching strategy that was already used for bulk inserts:
foreach ($q->toIterable() as $user) {
$user->increaseCredit();
$user->calculateNewBonuses();
++$i;
if (($i % $batchSize) === 0) {
$em->flush(); // Executes all updates.
$em->clear(); // Detaches all objects from Doctrine!
}
++$i;
}
$em->flush();
Expand Down Expand Up @@ -147,11 +147,11 @@ The following example shows how to do this:
$q = $em->createQuery('select u from MyProject\Model\User u');
foreach($q->toIterable() as $row) {
$em->remove($row);
++$i;
if (($i % $batchSize) === 0) {
$em->flush(); // Executes all deletions.
$em->clear(); // Detaches all objects from Doctrine!
}
++$i;
}
$em->flush();
Expand Down
13 changes: 7 additions & 6 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ abstract class AbstractQuery
*/
protected $_hydrationMode = self::HYDRATE_OBJECT;

/** @var QueryCacheProfile */
/** @var QueryCacheProfile|null */
protected $_queryCacheProfile;

/**
Expand Down Expand Up @@ -287,7 +287,7 @@ abstract public function getSQL();
/**
* Retrieves the associated EntityManager of this Query instance.
*
* @return EntityManager
* @return EntityManagerInterface
*/
public function getEntityManager()
{
Expand Down Expand Up @@ -588,6 +588,7 @@ public function setResultCacheProfile(?QueryCacheProfile $profile = null)
*/
public function setResultCacheDriver($resultCacheDriver = null)
{
/** @phpstan-ignore-next-line */
if ($resultCacheDriver !== null && ! ($resultCacheDriver instanceof \Doctrine\Common\Cache\Cache)) {
throw ORMException::invalidResultCacheDriver();
}
Expand Down Expand Up @@ -718,7 +719,7 @@ public function getExpireResultCache()
}

/**
* @return QueryCacheProfile
* @return QueryCacheProfile|null
*/
public function getQueryCacheProfile()
{
Expand Down Expand Up @@ -978,8 +979,8 @@ public function iterate($parameters = null, $hydrationMode = null)
* Executes the query and returns an iterable that can be used to incrementally
* iterate over the result.
*
* @param ArrayCollection|mixed[] $parameters The query parameters.
* @param string|int|null $hydrationMode The hydration mode to use.
* @param ArrayCollection|array|mixed[] $parameters The query parameters.
* @param string|int|null $hydrationMode The hydration mode to use.
* @psalm-param ArrayCollection<int, Parameter>|mixed[] $parameters
*
* @return iterable<mixed>
Expand Down Expand Up @@ -1045,7 +1046,7 @@ private function executeIgnoreQueryCache($parameters = null, $hydrationMode = nu
$this->setParameters($parameters);
}

$setCacheEntry = static function (): void {
$setCacheEntry = static function ($data): void {
};

if ($this->_hydrationCacheProfile !== null) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Cache/CollectionHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
interface CollectionHydrator
{
/**
* @param ClassMetadata $metadata The entity metadata.
* @param CollectionCacheKey $key The cached collection key.
* @param mixed[]|Collection $collection The collection.
* @param ClassMetadata $metadata The entity metadata.
* @param CollectionCacheKey $key The cached collection key.
* @param array|mixed[]|Collection $collection The collection.
*
* @return CollectionCacheEntry
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/DefaultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DefaultCache implements Cache
/** @var QueryCache[] */
private $queryCaches = [];

/** @var QueryCache */
/** @var QueryCache|null */
private $defaultQueryCache;

public function __construct(EntityManagerInterface $em)
Expand Down
10 changes: 9 additions & 1 deletion lib/Doctrine/ORM/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public function buildCachedEntityPersister(EntityManagerInterface $em, EntityPer
}

if ($usage === ClassMetadata::CACHE_USAGE_READ_WRITE) {
if (! $region instanceof ConcurrentRegion) {
throw new InvalidArgumentException(sprintf('Unable to use access strategy type of [%s] without a ConcurrentRegion', $usage));
}

return new ReadWriteCachedEntityPersister($persister, $region, $em, $metadata);
}

Expand All @@ -142,6 +146,10 @@ public function buildCachedCollectionPersister(EntityManagerInterface $em, Colle
}

if ($usage === ClassMetadata::CACHE_USAGE_READ_WRITE) {
if (! $region instanceof ConcurrentRegion) {
throw new InvalidArgumentException(sprintf('Unable to use access strategy type of [%s] without a ConcurrentRegion', $usage));
}

return new ReadWriteCachedCollectionPersister($persister, $region, $em, $mapping);
}

Expand Down Expand Up @@ -209,7 +217,7 @@ public function getRegion(array $cache)
}

$directory = $this->fileLockRegionDirectory . DIRECTORY_SEPARATOR . $cache['region'];
$region = new FileLockRegion($region, $directory, $this->regionsConfig->getLockLifetime($cache['region']));
$region = new FileLockRegion($region, $directory, (string) $this->regionsConfig->getLockLifetime($cache['region']));
}

return $this->regions[$cache['region']] = $region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract class AbstractCollectionPersister implements CachedCollectionPersister
/** @var CollectionHydrator */
protected $hydrator;

/** @var CacheLogger */
/** @var CacheLogger|null */
protected $cacheLogger;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function loadCollectionCache(PersistentCollection $collection, Collection
/**
* Stores a collection into cache
*
* @param mixed[]|Collection $elements
* @param array|mixed[]|Collection $elements
*
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
/** @var Cache */
protected $cache;

/** @var CacheLogger */
/** @var CacheLogger|null */
protected $cacheLogger;

/** @var string */
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Cache/Region/FileLockRegion.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class FileLockRegion implements ConcurrentRegion
/** @var string */
private $directory;

/** @psalm-var int */
/** @psalm-var numeric-string */
private $lockLifetime;

/**
* @param string $directory
* @param int $lockLifetime
* @param string $directory
* @param numeric-string $lockLifetime
*
* @throws InvalidArgumentException
*/
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/EntityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* EntityManager interface
*
* @method Mapping\ClassMetadata getClassMetadata($className)
* @method Mapping\ClassMetadataFactory getMetadataFactory()
*/
interface EntityManagerInterface extends ObjectManager
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Proxy\Proxy;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Proxy\Proxy;
use Doctrine\ORM\Query;
use Doctrine\ORM\UnitOfWork;
use PDO;
Expand Down Expand Up @@ -432,7 +432,7 @@ protected function hydrateRowData(array $row, array &$result)
// PATH B: Single-valued association
$reflFieldValue = $reflField->getValue($parentObject);

if (! $reflFieldValue || isset($this->_hints[Query::HINT_REFRESH]) || ($reflFieldValue instanceof Proxy && ! $reflFieldValue->__isInitialized__)) {
if (! $reflFieldValue || isset($this->_hints[Query::HINT_REFRESH]) || ($reflFieldValue instanceof Proxy && ! $reflFieldValue->__isInitialized())) {
// we only need to take action if this value is null,
// we refresh the entity or its an uninitialized proxy.
if (isset($nonemptyComponents[$dqlAlias])) {
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
* metadata mapping information of a class which describes how a class should be mapped
* to a relational database.
*
* @method ClassMetadata[] getAllMetadata()
* @method ClassMetadata[] getLoadedMetadata()
* @method ClassMetadata getMetadataFor($className)
*/
class ClassMetadataFactory extends AbstractClassMetadataFactory
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Persisters/Entity/EntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function load(
* @param object|null $entity The entity to load the data into. If not specified, a new entity is created.
* @psalm-param array<string, mixed> $identifier The entity identifier.
*
* @return object The loaded and managed entity instance or NULL if the entity can not be found.
* @return object|null The loaded and managed entity instance or NULL if the entity can not be found.
*
* @todo Check parameters
*/
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/Query/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\AST\AggregateExpression;
Expand Down Expand Up @@ -191,7 +192,7 @@ class Parser
/**
* The EntityManager.
*
* @var EntityManager
* @var EntityManagerInterface
*/
private $em;

Expand Down Expand Up @@ -294,7 +295,7 @@ public function getParserResult()
/**
* Gets the EntityManager used by the parser.
*
* @return EntityManager
* @return EntityManagerInterface
*/
public function getEntityManager()
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\QuoteStrategy;
Expand Down Expand Up @@ -107,7 +107,7 @@ class SqlWalker implements TreeWalker
/** @var ParserResult */
private $parserResult;

/** @var EntityManager */
/** @var EntityManagerInterface */
private $em;

/** @var Connection */
Expand Down Expand Up @@ -228,7 +228,7 @@ public function getConnection()
/**
* Gets the EntityManager used by the walker.
*
* @return EntityManager
* @return EntityManagerInterface
*/
public function getEntityManager()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\QuoteStrategy;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\Query;
Expand Down Expand Up @@ -81,7 +81,7 @@ class LimitSubqueryOutputWalker extends SqlWalker
/** @var int */
private $maxResults;

/** @var EntityManager */
/** @var EntityManagerInterface */
private $em;

/**
Expand Down
14 changes: 7 additions & 7 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\EventManager;
use Doctrine\Common\Proxy\Proxy;
use Doctrine\DBAL\LockMode;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Cache\Persister\CachedPersister;
Expand All @@ -46,7 +47,6 @@
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use Doctrine\ORM\Persisters\Entity\JoinedSubclassPersister;
use Doctrine\ORM\Persisters\Entity\SingleTablePersister;
use Doctrine\ORM\Proxy\Proxy;
use Doctrine\ORM\Utility\IdentifierFlattener;
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
use Doctrine\Persistence\NotifyPropertyChanged;
Expand Down Expand Up @@ -557,7 +557,7 @@ private function computeSingleEntityChangeSet($entity): void
}

// Ignore uninitialized proxy objects
if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
return;
}

Expand Down Expand Up @@ -864,7 +864,7 @@ public function computeChangeSets()

foreach ($entitiesToProcess as $entity) {
// Ignore uninitialized proxy objects
if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
continue;
}

Expand All @@ -889,7 +889,7 @@ public function computeChangeSets()
*/
private function computeAssociationChanges(array $assoc, $value): void
{
if ($value instanceof Proxy && ! $value->__isInitialized__) {
if ($value instanceof Proxy && ! $value->__isInitialized()) {
return;
}

Expand Down Expand Up @@ -2405,7 +2405,7 @@ static function ($assoc) {
$entitiesToCascade = [];

foreach ($associationMappings as $assoc) {
if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
$entity->__load();
}

Expand Down Expand Up @@ -2463,7 +2463,7 @@ public function lock($entity, int $lockMode, $lockVersion = null): void
return;
}

if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
$entity->__load();
}

Expand Down Expand Up @@ -2816,7 +2816,7 @@ public function createEntity($className, array $data, &$hints = [])
isset($hints[self::HINT_DEFEREAGERLOAD]) &&
! $targetClass->isIdentifierComposite &&
$newValue instanceof Proxy &&
$newValue->__isInitialized__ === false
$newValue->__isInitialized() === false
) {
$this->eagerLoadingEntities[$targetClass->rootEntityName][$relatedIdHash] = current($associatedId);
}
Expand Down
Loading

0 comments on commit dacdcf2

Please sign in to comment.