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]); + } } } }