doctrine/mongodb-odm — Issue #237: Type::convertToPHPValue($value) doesn't actually get called
Author: housebolt
Created: 2012-01-20 08:48:57+00:00
State: open

Recently creating a custom type I ran across an issue regarding type conversions. I created a type that ciphers plain text, but I need to be able to decrypt the data after it's been pulled from the database. Turns out that convertToPHPValue() never actually gets called. This is different from the Doctrine ORM because I know that it definitely gets called for ORM types.

```php
/**
* Ciphered data type
*/
class CipheredStringType extends Type {

protected $cipher;

public function convertToDatabaseValue($value) {
return $value !== null ? $this->getCipher()->encrypt((string) $value) : null;
}

//This never actually gets called, so I get the encrypted text after database pull
public function convertToPHPValue($value) {
return $value !== null ? $this->getCipher()->decrypt((string) $value) : null;
}

public function getCipher() {
//Cipher created here
}

}
```
I know there are other ways to handle this but it would be nice if I could do it transparently via a type. This is confusing for new people to the Doctrine ODM because the documentation implies that convertToPHPValue() will actually get called at some point in the process.