From 12916806c38f427864d20df0ffcb27137d0608dc Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Tue, 9 Dec 2025 17:42:32 +0100 Subject: [PATCH 1/8] Added configurable user entity class support in UniqueEntityDtoValidator - the validator now uses the user_entity_class setting instead of hardcoded AnzuUser::class reference, allowing for custom user entity implementations --- src/DependencyInjection/AnzuSystemsCommonExtension.php | 5 +++++ src/Resources/config/services.php | 1 + src/Validator/Constraints/UniqueEntityDtoValidator.php | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/DependencyInjection/AnzuSystemsCommonExtension.php b/src/DependencyInjection/AnzuSystemsCommonExtension.php index c7da607..710a90d 100644 --- a/src/DependencyInjection/AnzuSystemsCommonExtension.php +++ b/src/DependencyInjection/AnzuSystemsCommonExtension.php @@ -81,6 +81,7 @@ use AnzuSystems\CommonBundle\Serializer\Handler\Handlers\ValueObjectHandler; use AnzuSystems\CommonBundle\Serializer\Service\BsonConverter; use AnzuSystems\CommonBundle\Util\ResourceLocker; +use AnzuSystems\CommonBundle\Validator\Constraints\UniqueEntityDtoValidator; use AnzuSystems\CommonBundle\Validator\Validator; use AnzuSystems\SerializerBundle\Metadata\MetadataRegistry; use AnzuSystems\SerializerBundle\Serializer; @@ -265,6 +266,10 @@ private function loadSettings(ContainerBuilder $container): void ->getDefinition(CurrentAnzuUserProvider::class) ->replaceArgument('$userEntityClass', $settings['user_entity_class']); + $container + ->getDefinition(UniqueEntityDtoValidator::class) + ->replaceArgument('$userEntityClass', $settings['user_entity_class']); + if ($settings['send_context_id_with_response']) { $container->register(ContextIdOnResponseListener::class) ->addTag('kernel.event_listener', ['event' => KernelEvents::RESPONSE]) diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index e194e02..1b16529 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -162,6 +162,7 @@ $services->set(UniqueEntityDtoValidator::class) ->arg('$propertyAccessor', service(PropertyAccessorInterface::class)) ->arg('$entityManager', service(EntityManagerInterface::class)) + ->arg('$userEntityClass', null) ->tag('validator.constraint_validator') ; diff --git a/src/Validator/Constraints/UniqueEntityDtoValidator.php b/src/Validator/Constraints/UniqueEntityDtoValidator.php index 793d920..bdb6498 100644 --- a/src/Validator/Constraints/UniqueEntityDtoValidator.php +++ b/src/Validator/Constraints/UniqueEntityDtoValidator.php @@ -4,6 +4,7 @@ namespace AnzuSystems\CommonBundle\Validator\Constraints; +use AnzuSystems\Contracts\Entity\AnzuUser; use AnzuSystems\Contracts\Entity\Interfaces\BaseIdentifiableInterface; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; @@ -16,6 +17,7 @@ final class UniqueEntityDtoValidator extends ConstraintValidator public function __construct( private readonly PropertyAccessorInterface $propertyAccessor, private readonly EntityManagerInterface $entityManager, + private readonly string $userEntityClass, ) { } @@ -31,13 +33,18 @@ public function validate(mixed $value, Constraint $constraint): void throw new UnexpectedTypeException($constraint->entity, BaseIdentifiableInterface::class); } + $entityClass = $constraint->entity; + if ($entityClass === AnzuUser::class) { + $entityClass = $this->userEntityClass; + } + $fieldsNames = $constraint->fields; $fields = []; foreach ($fieldsNames as $fieldName) { $fields[$fieldName] = $this->propertyAccessor->getValue($value, $fieldName); } /** @var BaseIdentifiableInterface|null $existingEntity */ - $existingEntity = $this->entityManager->getRepository($constraint->entity)->findOneBy($fields); + $existingEntity = $this->entityManager->getRepository($entityClass)->findOneBy($fields); if (null === $existingEntity) { return; } From 2a1454eb732ecc993a498556570e148e6c7d2edc Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Tue, 9 Dec 2025 17:53:09 +0100 Subject: [PATCH 2/8] psalm fix --- src/Validator/Constraints/UniqueEntityDtoValidator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Validator/Constraints/UniqueEntityDtoValidator.php b/src/Validator/Constraints/UniqueEntityDtoValidator.php index bdb6498..1427021 100644 --- a/src/Validator/Constraints/UniqueEntityDtoValidator.php +++ b/src/Validator/Constraints/UniqueEntityDtoValidator.php @@ -33,8 +33,10 @@ public function validate(mixed $value, Constraint $constraint): void throw new UnexpectedTypeException($constraint->entity, BaseIdentifiableInterface::class); } + /** @var class-string $entityClass */ $entityClass = $constraint->entity; if ($entityClass === AnzuUser::class) { + /** @var class-string $entityClass */ $entityClass = $this->userEntityClass; } From 8b1baf7b31c986a8b068cb3ab2ad3a1578f45ff9 Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Tue, 9 Dec 2025 18:25:09 +0100 Subject: [PATCH 3/8] fixed symfony/monolog-bundle deprecation: Add mongodb handler and deprecate mongo --- src/DependencyInjection/AnzuSystemsCommonExtension.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DependencyInjection/AnzuSystemsCommonExtension.php b/src/DependencyInjection/AnzuSystemsCommonExtension.php index 710a90d..74eae20 100644 --- a/src/DependencyInjection/AnzuSystemsCommonExtension.php +++ b/src/DependencyInjection/AnzuSystemsCommonExtension.php @@ -154,20 +154,20 @@ public function prepend(ContainerBuilder $container): void 'id' => 'anzu_systems_common.logs.audit_log_messenger_handler', ], 'journal_sync' => [ - 'type' => 'mongo', + 'type' => 'mongodb', 'channels' => 'journal_sync', 'level' => 'debug', - 'mongo' => [ + 'mongodb' => [ 'id' => 'anzu_systems_common.logs.journal_log_client', 'database' => $logs['journal']['mongo']['database'], 'collection' => $logs['journal']['mongo']['collection'], ], ], 'audit_sync' => [ - 'type' => 'mongo', + 'type' => 'mongodb', 'channels' => 'audit_sync', 'level' => 'debug', - 'mongo' => [ + 'mongodb' => [ 'id' => 'anzu_systems_common.logs.audit_log_client', 'database' => $logs['audit']['mongo']['database'], 'collection' => $logs['audit']['mongo']['collection'], From f2f1fb4dd13adf5c23590614e1f3770c25823e05 Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Tue, 9 Dec 2025 18:26:42 +0100 Subject: [PATCH 4/8] min pckg req --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 998e612..81ee6b4 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "symfony/http-kernel": "^6.0|^7.0", "symfony/lock": "^6.0|^7.0", "symfony/messenger": "^6.0|^7.0", - "symfony/monolog-bundle": ">=3.7", + "symfony/monolog-bundle": ">=3.9", "symfony/polyfill-uuid": "^1.23", "symfony/runtime": "^6.0|^7.0", "symfony/security-bundle": "^6.0|^7.0", From c96e58a6237981943fd661f6f5e0bf5c406499df Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Tue, 9 Dec 2025 18:49:44 +0100 Subject: [PATCH 5/8] fixed symfony/monolog-bundle deprecation: Add mongodb handler and deprecate mongo --- .github/workflows/php.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5c2505c..39311b8 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -50,9 +50,9 @@ jobs: uses: actions/cache@v3 with: path: vendor - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-php-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: | - ${{ runner.os }}-composer- + ${{ runner.os }}-php-${{ matrix.php-version }}-composer- - name: Install dependencies run: composer install --prefer-dist --no-progress --no-ansi --no-interaction --no-scripts From 76eb854a5d4e02198950b05b8970fb070f9f2524 Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Tue, 9 Dec 2025 18:56:07 +0100 Subject: [PATCH 6/8] enabled lazy ghost objects --- tests/config/packages/doctrine.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/config/packages/doctrine.yaml b/tests/config/packages/doctrine.yaml index f515fec..85bdee8 100644 --- a/tests/config/packages/doctrine.yaml +++ b/tests/config/packages/doctrine.yaml @@ -7,6 +7,7 @@ doctrine: auto_generate_proxy_classes: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: false + enable_lazy_ghost_objects: true mappings: App: dir: '%kernel.project_dir%/tests/data/Entity' From 5aba68a8cb82ee6a79857dfa2c3b0fcdfbf9654a Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Tue, 9 Dec 2025 19:02:04 +0100 Subject: [PATCH 7/8] add requirement for symfony/var-exporter --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 81ee6b4..de0f01b 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "symfony/security-bundle": "^6.0|^7.0", "symfony/uid": "^6.0|^7.0", "symfony/validator": "^6.0|^7.0", + "symfony/var-exporter": "^6.4|^7.0", "symfony/yaml": "^6.0|^7.0" }, "require-dev": { From ec5cdb5d6eb9ea049e1f096128b2d84d789389fa Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Tue, 9 Dec 2025 19:05:42 +0100 Subject: [PATCH 8/8] rollback --- .github/workflows/php.yml | 4 ++-- tests/config/packages/doctrine.yaml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 39311b8..5c2505c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -50,9 +50,9 @@ jobs: uses: actions/cache@v3 with: path: vendor - key: ${{ runner.os }}-php-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: | - ${{ runner.os }}-php-${{ matrix.php-version }}-composer- + ${{ runner.os }}-composer- - name: Install dependencies run: composer install --prefer-dist --no-progress --no-ansi --no-interaction --no-scripts diff --git a/tests/config/packages/doctrine.yaml b/tests/config/packages/doctrine.yaml index 85bdee8..f515fec 100644 --- a/tests/config/packages/doctrine.yaml +++ b/tests/config/packages/doctrine.yaml @@ -7,7 +7,6 @@ doctrine: auto_generate_proxy_classes: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: false - enable_lazy_ghost_objects: true mappings: App: dir: '%kernel.project_dir%/tests/data/Entity'