Skip to content

Commit

Permalink
Merge pull request #5 from BboyKeen/master
Browse files Browse the repository at this point in the history
Add support for embedded entities
  • Loading branch information
ambta committed Apr 4, 2016
2 parents 675f0c0 + 17dc145 commit 448401e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Subscribers/DoctrineEncryptSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ public function processFields($entity, $isEncryptOperation = true) {
//Foreach property in the reflection class
foreach ($properties as $refProperty) {

if ($this->annReader->getPropertyAnnotation($refProperty, 'Doctrine\ORM\Mapping\Embedded')) {
$this->handleEmbeddedAnnotation($entity, $refProperty, $isEncryptOperation);
continue;
}
/**
* If followed standards, method name is getPropertyName, the propertyName is lowerCamelCase
* So just uppercase first character of the property, later on get and set{$methodName} wil be used
Expand Down Expand Up @@ -297,6 +301,30 @@ public function processFields($entity, $isEncryptOperation = true) {
return null;
}

private function handleEmbeddedAnnotation($entity, $embeddedProperty, $isEncryptOperation = true)
{
$reflectionClass = new ReflectionClass($entity);
$propName = $embeddedProperty->getName();
$methodName = ucfirst($propName);

if ($embeddedProperty->isPublic()) {
$embeddedEntity = $embeddedProperty->getValue();
} else {
if ($reflectionClass->hasMethod($getter = 'get' . $methodName) && $reflectionClass->hasMethod($setter = 'set' . $methodName)) {

//Get the information (value) of the property
try {
$embeddedEntity = $entity->$getter();
} catch(\Exception $e) {
$embeddedEntity = null;
}
}
}
if ($embeddedEntity) {
$this->processFields($embeddedEntity, $isEncryptOperation);
}
}

/**
* Recursive function to get an associative array of class properties
* including inherited ones from extended classes
Expand Down

0 comments on commit 448401e

Please sign in to comment.