-
Notifications
You must be signed in to change notification settings - Fork 19
IBX-11179: Resolve PHP 8.4 lazy proxy incompatibility #707
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
Open
wiewiurdp
wants to merge
7
commits into
4.6
Choose a base branch
from
IBX-11179-PHP-8.4-certification-entity-manager-not-lazy
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
846cd93
Remove lazy loading for Doctrine EntityManager
4f41311
Refactor entity manager to use SiteAccessAwareEntityManager for PHP 8…
a9a7717
Refactor SiteAccessAwareEntityManager to remove deprecated methods an…
2b2748c
Fixed type hint for getExpressionBuilder method in SiteAccessAwareEnt…
8a12b61
Refactor find method in SiteAccessAwareEntityManager to remove unused…
2e4a786
Implement reset functionality in SiteAccessAwareEntityManager and upd…
70acf0b
Made code compatibile with older php versions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
308 changes: 308 additions & 0 deletions
308
src/lib/Persistence/Doctrine/SiteAccessAwareEntityManager.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,308 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Core\Persistence\Doctrine; | ||
|
|
||
| use Doctrine\DBAL\Connection; | ||
| use Doctrine\ORM\Cache; | ||
| use Doctrine\ORM\Configuration; | ||
| use Doctrine\ORM\EntityManagerInterface; | ||
| use Doctrine\ORM\EntityRepository; | ||
| use Doctrine\ORM\Internal\Hydration\AbstractHydrator; | ||
| use Doctrine\ORM\Mapping\ClassMetadata; | ||
| use Doctrine\ORM\Mapping\ClassMetadataFactory; | ||
| use Doctrine\ORM\NativeQuery; | ||
| use Doctrine\ORM\Proxy\ProxyFactory; | ||
| use Doctrine\ORM\Query; | ||
| use Doctrine\ORM\Query\Expr; | ||
| use Doctrine\ORM\Query\FilterCollection; | ||
| use Doctrine\ORM\Query\ResultSetMapping; | ||
| use Doctrine\ORM\QueryBuilder; | ||
| use Doctrine\ORM\UnitOfWork; | ||
| use Ibexa\Bundle\Core\Entity\EntityManagerFactory; | ||
| use Ibexa\Contracts\Core\MVC\EventSubscriber\ConfigScopeChangeSubscriber; | ||
| use Ibexa\Core\MVC\Symfony\Event\ScopeChangeEvent; | ||
| use Symfony\Contracts\Service\ResetInterface; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| final class SiteAccessAwareEntityManager implements EntityManagerInterface, ConfigScopeChangeSubscriber, ResetInterface | ||
| { | ||
| private EntityManagerFactory $entityManagerFactory; | ||
|
|
||
| private ?EntityManagerInterface $resolvedEntityManager = null; | ||
|
|
||
| public function __construct(EntityManagerFactory $entityManagerFactory) | ||
konradoboza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| $this->entityManagerFactory = $entityManagerFactory; | ||
| } | ||
|
|
||
| public function onConfigScopeChange(ScopeChangeEvent $event): void | ||
| { | ||
| $this->resolvedEntityManager = null; | ||
| } | ||
|
|
||
| public function reset(): void | ||
| { | ||
| $this->resolvedEntityManager = null; | ||
| } | ||
|
|
||
| private function getWrapped(): EntityManagerInterface | ||
| { | ||
| return $this->resolvedEntityManager ??= $this->entityManagerFactory->getEntityManager(); | ||
| } | ||
Steveb-p marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public function getConnection(): Connection | ||
| { | ||
| return $this->getWrapped()->getConnection(); | ||
| } | ||
|
|
||
| public function getExpressionBuilder(): Expr | ||
| { | ||
| return $this->getWrapped()->getExpressionBuilder(); | ||
| } | ||
|
|
||
| public function beginTransaction(): void | ||
| { | ||
| $this->getWrapped()->beginTransaction(); | ||
| } | ||
|
|
||
| public function transactional($func) | ||
| { | ||
| return $this->getWrapped()->transactional($func); | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function wrapInTransaction(callable $func) | ||
| { | ||
| return $this->getWrapped()->wrapInTransaction($func); | ||
| } | ||
|
|
||
| public function commit(): void | ||
| { | ||
| $this->getWrapped()->commit(); | ||
| } | ||
|
|
||
| public function rollback(): void | ||
| { | ||
| $this->getWrapped()->rollback(); | ||
| } | ||
|
|
||
| public function createQuery($dql = ''): Query | ||
| { | ||
| return $this->getWrapped()->createQuery($dql); | ||
| } | ||
|
|
||
| public function createNamedQuery($name): Query | ||
| { | ||
| return $this->getWrapped()->createNamedQuery($name); | ||
| } | ||
|
|
||
| public function createNativeQuery($sql, ResultSetMapping $rsm): NativeQuery | ||
| { | ||
| return $this->getWrapped()->createNativeQuery($sql, $rsm); | ||
| } | ||
|
|
||
| public function createNamedNativeQuery($name): NativeQuery | ||
| { | ||
| return $this->getWrapped()->createNamedNativeQuery($name); | ||
| } | ||
|
|
||
| public function createQueryBuilder(): QueryBuilder | ||
| { | ||
| return $this->getWrapped()->createQueryBuilder(); | ||
| } | ||
|
|
||
| /** | ||
| * @template T of object | ||
| * | ||
| * @param class-string<T> $entityName | ||
| * | ||
| * @return T|null | ||
| */ | ||
| public function getReference($entityName, $id): ?object | ||
| { | ||
| return $this->getWrapped()->getReference($entityName, $id); | ||
| } | ||
|
|
||
| /** | ||
| * @template T of object | ||
| * | ||
| * @param class-string<T> $entityName | ||
| * | ||
| * @return T|null | ||
| */ | ||
| public function getPartialReference($entityName, $identifier): ?object | ||
| { | ||
| return $this->getWrapped()->getPartialReference($entityName, $identifier); | ||
| } | ||
|
|
||
| public function close(): void | ||
| { | ||
| $this->getWrapped()->close(); | ||
| } | ||
|
|
||
| /** | ||
| * @template T of object | ||
| * | ||
| * @param T $entity | ||
| * @param bool $deep | ||
| * | ||
| * @return T | ||
| */ | ||
| public function copy($entity, $deep = false): object | ||
| { | ||
| /** @var T */ | ||
| return $this->getWrapped()->copy($entity, $deep); | ||
| } | ||
|
|
||
| public function lock($entity, $lockMode, $lockVersion = null): void | ||
| { | ||
| $this->getWrapped()->lock($entity, $lockMode, $lockVersion); | ||
| } | ||
|
|
||
| public function getEventManager(): \Doctrine\Common\EventManager | ||
| { | ||
| return $this->getWrapped()->getEventManager(); | ||
| } | ||
|
|
||
| public function getConfiguration(): Configuration | ||
| { | ||
| return $this->getWrapped()->getConfiguration(); | ||
| } | ||
|
|
||
| public function isOpen(): bool | ||
| { | ||
| return $this->getWrapped()->isOpen(); | ||
| } | ||
|
|
||
| public function getUnitOfWork(): UnitOfWork | ||
| { | ||
| return $this->getWrapped()->getUnitOfWork(); | ||
| } | ||
|
|
||
| public function getHydrator($hydrationMode): AbstractHydrator | ||
| { | ||
| return $this->getWrapped()->getHydrator($hydrationMode); | ||
| } | ||
|
|
||
| public function newHydrator($hydrationMode): AbstractHydrator | ||
| { | ||
| return $this->getWrapped()->newHydrator($hydrationMode); | ||
| } | ||
|
|
||
| public function getProxyFactory(): ProxyFactory | ||
| { | ||
| return $this->getWrapped()->getProxyFactory(); | ||
| } | ||
|
|
||
| public function getFilters(): FilterCollection | ||
| { | ||
| return $this->getWrapped()->getFilters(); | ||
| } | ||
|
|
||
| public function isFiltersStateClean(): bool | ||
| { | ||
| return $this->getWrapped()->isFiltersStateClean(); | ||
| } | ||
|
|
||
| public function hasFilters(): bool | ||
| { | ||
| return $this->getWrapped()->hasFilters(); | ||
| } | ||
|
|
||
| public function getCache(): ?Cache | ||
| { | ||
| return $this->getWrapped()->getCache(); | ||
| } | ||
|
|
||
| public function find($className, $id): ?object | ||
| { | ||
| return $this->getWrapped()->find($className, $id); | ||
| } | ||
|
|
||
| public function persist(object $object): void | ||
| { | ||
| $this->getWrapped()->persist($object); | ||
| } | ||
|
|
||
| public function remove(object $object): void | ||
| { | ||
| $this->getWrapped()->remove($object); | ||
| } | ||
|
|
||
| public function clear(): void | ||
| { | ||
| $this->getWrapped()->clear(); | ||
| } | ||
|
|
||
| public function detach(object $object): void | ||
| { | ||
| $this->getWrapped()->detach($object); | ||
| } | ||
|
|
||
| public function refresh(object $object, ?int $lockMode = null): void | ||
| { | ||
| $this->getWrapped()->refresh($object, $lockMode); | ||
| } | ||
|
|
||
| public function flush(): void | ||
| { | ||
| $this->getWrapped()->flush(); | ||
| } | ||
|
|
||
| /** | ||
| * @template T of object | ||
| * | ||
| * @param class-string<T> $className | ||
| * | ||
| * @return EntityRepository<T> | ||
| */ | ||
| public function getRepository($className): EntityRepository | ||
| { | ||
| return $this->getWrapped()->getRepository($className); | ||
| } | ||
|
|
||
| /** | ||
| * @template T of object | ||
| * | ||
| * @param class-string<T> $className | ||
| * | ||
| * @return ClassMetadata<T> | ||
| */ | ||
| public function getClassMetadata($className): ClassMetadata | ||
| { | ||
| return $this->getWrapped()->getClassMetadata($className); | ||
| } | ||
|
|
||
| public function getMetadataFactory(): ClassMetadataFactory | ||
| { | ||
| return $this->getWrapped()->getMetadataFactory(); | ||
| } | ||
|
|
||
| public function initializeObject(object $obj): void | ||
| { | ||
| $this->getWrapped()->initializeObject($obj); | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $value | ||
| */ | ||
| public function isUninitializedObject($value): bool | ||
| { | ||
| return $this->getWrapped()->isUninitializedObject($value); | ||
| } | ||
|
|
||
| public function contains(object $object): bool | ||
| { | ||
| return $this->getWrapped()->contains($object); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also have
decorates:here?Regardless: doesn't that approach leave us with some technical debt we need to reassess later while upgrading dependencies late? I wonder how
Doctrinethemselves have dealt with providing support for PHP8.4. Have you checked that? First idea is the one we initially have - bumping the dependency version. However, maybe there is a specific PHP8.4-compatibility-related part we might be able to utilize for the time being.POV ping @alongosz @Steveb-p.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should NOT decorate the primary Doctrine Entity Manager.
We only expect it to "overwrite" the default behavior specifically when we ask for
ibexa.doctrine.orm.entity_managerservice.