Skip to content

Commit

Permalink
Merge pull request #4 from rbroen/feature/update-hashes-when-hashed-v…
Browse files Browse the repository at this point in the history
…alue-changes

Feature/update hashes when hashed value changes
  • Loading branch information
Dwarfex committed Apr 5, 2021
2 parents 30fa1c0 + e27f12d commit d7ebbc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion src/Subscriber/HashingSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}
}
Expand Down

0 comments on commit d7ebbc9

Please sign in to comment.