I am using a Doctrine2 type to encrypt database values. The type converts the PHP value internally to and from a database value by encrypting and decrypting it. This works perfectly due to the Doctrine2 types.
The encryption is stored as a base64 encoded string. Every encrypted string is prefixed by a fixed defined prefix. This means the database field contains both encrypted and decrypted values (this is required by external requirements), recognized by the prefix.
My wish is the following:
Assume I have an entity. I want to force the encryption or decryption of all properties of an entity using Doctrine. I do this by forcing the database value within the type to be stored in the encrypted or decrypted form.
However, when I call the method EntityManager::computeChangeSets, the none of the properties of the entity is marked as changed. Of course the actual data (the PHP values) are not changed. However, the database values do (are supposed to) change.
How to accomplish this?
Some code of the Doctrine type:
<?php
use Doctrine\DBAL\Types\Type;
class EncryptedType extends Type {
private static $forceDecrypt = false;
// Encryption stuff, like encrypt () and decrypt ()
public function convertToPHPValue($value, AbstractPlatform $platform) {
if ($value === null) {
return null;
}
return $this -> decrypt($value, false);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform) {
if ($value === null) {
return null;
}
if (self::$forceDecrypt) {
return (string) $value;
}
return $this -> encrypt((string) $value, false);
}
}
I have removed all unneeded code.