Skip to content

Commit

Permalink
Merge pull request #11010 from greg0ire/3.0.x
Browse files Browse the repository at this point in the history
Merge 2.17.x up into 3.0.x
  • Loading branch information
greg0ire authored Oct 14, 2023
2 parents e997c66 + 8693fa7 commit 3c34265
Show file tree
Hide file tree
Showing 25 changed files with 464 additions and 33 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,11 @@ Use `toIterable()` instead.

# Upgrade to 2.17

## Undeprecate `Doctrine\ORM\Proxy\Autoloader`

It will be a full-fledged class, no longer extending
`Doctrine\Common\Proxy\Autoloader` in 3.0.x.

## Deprecated: reliance on the non-optimal defaults that come with the `AUTO` identifier generation strategy

When the `AUTO` identifier generation strategy was introduced, the best
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/advanced-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ means that you have to register a special autoloader for these classes:
.. code-block:: php
<?php
use Doctrine\Common\Proxy\Autoloader;
use Doctrine\ORM\Proxy\Autoloader;
$proxyDir = "/path/to/proxies";
$proxyNamespace = "MyProxies";
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use BackedEnum;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\ParameterType;
Expand All @@ -17,6 +16,7 @@
use Doctrine\ORM\Cache\TimestampCacheKey;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\ResultSetMapping;
Expand Down Expand Up @@ -379,7 +379,7 @@ public function processParameterValue(mixed $value): mixed
}

try {
$class = ClassUtils::getClass($value);
$class = DefaultProxyClassNameResolver::getClass($value);
$value = $this->em->getUnitOfWork()->getSingleIdentifierValue($value);

if ($value === null) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Cache/DefaultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Doctrine\ORM\Cache;

use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Cache;
use Doctrine\ORM\Cache\Persister\CachedPersister;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\ORMInvalidArgumentException;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
use Doctrine\ORM\UnitOfWork;

use function is_array;
Expand Down Expand Up @@ -233,7 +233,7 @@ private function buildCollectionCacheKey(
private function toIdentifierArray(ClassMetadata $metadata, mixed $identifier): array
{
if (is_object($identifier)) {
$class = ClassUtils::getClass($identifier);
$class = DefaultProxyClassNameResolver::getClass($identifier);
if ($this->em->getMetadataFactory()->hasMetadataFor($class)) {
$identifier = $this->uow->getSingleIdentifierValue($identifier)
?? throw ORMInvalidArgumentException::invalidIdentifierBindingEntity($class);
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Doctrine\ORM\Cache;

use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
use Doctrine\ORM\Query;
use Doctrine\ORM\UnitOfWork;
use Doctrine\ORM\Utility\IdentifierFlattener;
Expand Down Expand Up @@ -97,7 +97,7 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, ob
}

if (! isset($assoc->id)) {
$targetClass = ClassUtils::getClass($data[$name]);
$targetClass = DefaultProxyClassNameResolver::getClass($data[$name]);
$targetId = $this->uow->getEntityIdentifier($data[$name]);
$data[$name] = new AssociationCacheEntry($targetClass, $targetId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Cache\CollectionCacheKey;
use Doctrine\ORM\Cache\CollectionHydrator;
use Doctrine\ORM\Cache\Logging\CacheLogger;
Expand All @@ -18,6 +17,7 @@
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Persisters\Collection\CollectionPersister;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
use Doctrine\ORM\UnitOfWork;

use function array_values;
Expand Down Expand Up @@ -105,7 +105,7 @@ public function storeCollectionCache(CollectionCacheKey $key, Collection|array $
}

$class = $this->targetEntity;
$className = ClassUtils::getClass($elements[$index]);
$className = DefaultProxyClassNameResolver::getClass($elements[$index]);

if ($className !== $this->targetEntity->name) {
$class = $this->metadataFactory->getMetadataFor($className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Doctrine\ORM\Cache\Persister\Collection;

use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Cache\Exception\CannotUpdateReadOnlyCollection;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;

class ReadOnlyCachedCollectionPersister extends NonStrictReadWriteCachedCollectionPersister
{
public function update(PersistentCollection $collection): void
{
if ($collection->isDirty() && $collection->getSnapshot()) {
throw CannotUpdateReadOnlyCollection::fromEntityAndField(
ClassUtils::getClass($collection->getOwner()),
DefaultProxyClassNameResolver::getClass($collection->getOwner()),
$this->association->fieldName,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\ORM\Cache\Persister\Entity;

use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Cache;
use Doctrine\ORM\Cache\CollectionCacheKey;
Expand All @@ -23,6 +22,7 @@
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\UnitOfWork;

Expand Down Expand Up @@ -147,7 +147,7 @@ public function getEntityHydrator(): EntityHydrator
public function storeEntityCache(object $entity, EntityCacheKey $key): bool
{
$class = $this->class;
$className = ClassUtils::getClass($entity);
$className = DefaultProxyClassNameResolver::getClass($entity);

if ($className !== $this->class->name) {
$class = $this->metadataFactory->getMetadataFor($className);
Expand Down Expand Up @@ -394,7 +394,7 @@ public function loadById(array $identifier, object|null $entity = null): object|
}

$class = $this->class;
$className = ClassUtils::getClass($entity);
$className = DefaultProxyClassNameResolver::getClass($entity);

if ($className !== $this->class->name) {
$class = $this->metadataFactory->getMetadataFor($className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Doctrine\ORM\Cache\Persister\Entity;

use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Cache\Exception\CannotUpdateReadOnlyEntity;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;

/**
* Specific read-only region entity persister
Expand All @@ -14,6 +14,6 @@ class ReadOnlyCachedEntityPersister extends NonStrictReadWriteCachedEntityPersis
{
public function update(object $entity): void
{
throw CannotUpdateReadOnlyEntity::fromEntity(ClassUtils::getClass($entity));
throw CannotUpdateReadOnlyEntity::fromEntity(DefaultProxyClassNameResolver::getClass($entity));
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use BackedEnum;
use DateTimeInterface;
use Doctrine\Common\EventManager;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Exception\EntityManagerClosed;
Expand All @@ -19,6 +18,7 @@
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\FilterCollection;
Expand Down Expand Up @@ -281,7 +281,7 @@ public function find($className, mixed $id, LockMode|int|null $lockMode = null,

foreach ($id as $i => $value) {
if (is_object($value)) {
$className = ClassUtils::getClass($value);
$className = DefaultProxyClassNameResolver::getClass($value);
if ($this->metadataFactory->hasMetadataFor($className)) {
$id[$i] = $this->unitOfWork->getSingleIdentifierValue($value);

Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\ORM\Id\SequenceGenerator;
use Doctrine\ORM\Mapping\Exception\InvalidCustomGenerator;
use Doctrine\ORM\Mapping\Exception\UnknownGeneratorType;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\Persistence\Mapping\ClassMetadata as ClassMetadataInterface;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
Expand Down Expand Up @@ -61,6 +62,8 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory

public function setEntityManager(EntityManagerInterface $em): void
{
parent::setProxyClassNameResolver(new DefaultProxyClassNameResolver());

$this->em = $em;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ORM/Mapping/Driver/AttributeReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public function getPropertyAttribute(ReflectionProperty $property, string $attri
));
}

return $this->getPropertyAttributes($property)[$attributeName]
?? ($this->isRepeatable($attributeName) ? new RepeatableAttributeCollection() : null);
return $this->getPropertyAttributes($property)[$attributeName] ?? null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use BackedEnum;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Expr\Comparison;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\LockMode;
Expand All @@ -31,6 +30,7 @@
use Doctrine\ORM\Persisters\Exception\UnrecognizedField;
use Doctrine\ORM\Persisters\SqlExpressionVisitor;
use Doctrine\ORM\Persisters\SqlValueVisitor;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\ResultSetMapping;
Expand Down Expand Up @@ -1940,7 +1940,7 @@ private function getIndividualValue(mixed $value): array
return [$value->value];
}

$valueClass = ClassUtils::getClass($value);
$valueClass = DefaultProxyClassNameResolver::getClass($value);

if ($this->em->getMetadataFactory()->isTransient($valueClass)) {
return [$value];
Expand Down
40 changes: 40 additions & 0 deletions lib/Doctrine/ORM/Proxy/DefaultProxyClassNameResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Proxy;

use Doctrine\Persistence\Mapping\ProxyClassNameResolver;
use Doctrine\Persistence\Proxy;

use function get_class;
use function strrpos;
use function substr;

/**
* Class-related functionality for objects that might or not be proxy objects
* at the moment.
*/
final class DefaultProxyClassNameResolver implements ProxyClassNameResolver
{
public function resolveClassName(string $className): string
{
$pos = strrpos($className, '\\' . Proxy::MARKER . '\\');

if ($pos === false) {
return $className;
}

return substr($className, $pos + Proxy::MARKER_LENGTH + 2);
}

/**
* @param object $object
*
* @return class-string
*/
public static function getClass($object): string
{
return (new self())->resolveClassName(get_class($object));
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\ORM\Tools\Console\Command;

use Doctrine\Common\Util\Debug;
use Doctrine\ORM\Tools\Debug;
use LogicException;
use RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -111,7 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$resultSet = $query->execute([], constant($hydrationMode));

$ui->text(Debug::dump($resultSet, (int) $input->getOption('depth'), true, false));
$ui->text(Debug::dump($resultSet, (int) $input->getOption('depth')));

return 0;
}
Expand Down
Loading

0 comments on commit 3c34265

Please sign in to comment.