From 8f113fefbc904072fd8f3b0b77d1f6475aea1801 Mon Sep 17 00:00:00 2001 From: Robert Broen Date: Sat, 3 Apr 2021 22:54:23 +0200 Subject: [PATCH 1/2] Merged from somecoding --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b5386e1..519a6bb 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": "^7.2 || ^7.3", + "php": " ~7.2 || 8.0.*", "ext-sodium": "*", "doctrine/annotations": "^1.6", "doctrine/orm": "^2.6", From e27f12d232fc7dad7f8d0239f52a84ac3acb4cf6 Mon Sep 17 00:00:00 2001 From: Robert Broen Date: Sat, 3 Apr 2021 22:58:33 +0200 Subject: [PATCH 2/2] Update hashes when value has changed --- README.md | 2 +- src/Subscriber/HashingSubscriber.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf599c0..10d08df 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ When using Mezzio, you will want to add the ConfigProvider to your `config/confi \Keet\Encrypt\ConfigProvider::class, ``` -When declaring the path to your entities, be sure to pass the path(s) as an array. +When declaring the path to your entities (likely the file with `App\ConfigProvider`), be sure to pass the path(s) as an array. ``` 'my_entity' => [ 'class' => AnnotationDriver::class, diff --git a/src/Subscriber/HashingSubscriber.php b/src/Subscriber/HashingSubscriber.php index 7504f26..6f8b2d2 100644 --- a/src/Subscriber/HashingSubscriber.php +++ b/src/Subscriber/HashingSubscriber.php @@ -223,7 +223,15 @@ private function getHashableFields(object $entity, EntityManager $em) 'nullable' => $meta->getFieldMapping($refProperty->getName())['nullable'], ]; } else if ($arrayKeyExists) { - $refProperty->setValue($entity, $entityChangeSet[$refProperty->getName()][0]); + // If the hashed value does not match the new value, then use a new hash, else use the old hash + $oldHashedValue = $entityChangeSet[$refProperty->getName()][0]; + $newNonHashedValue = $entityChangeSet[$refProperty->getName()][1]; + $valueIsChanged = $this->getHashor()->verify($newNonHashedValue, $oldHashedValue) === false; + if ($valueIsChanged) { + $refProperty->setValue($entity, $this->getHashor()->hash($newNonHashedValue)); + } else { + $refProperty->setValue($entity, $entityChangeSet[$refProperty->getName()][0]); + } } } }