diff --git a/src/EncryptionBehavior.php b/src/EncryptionBehavior.php index 1854efb..95b721c 100644 --- a/src/EncryptionBehavior.php +++ b/src/EncryptionBehavior.php @@ -46,29 +46,15 @@ public function tableMapFilter(&$script) { public function objectFilter(&$script) { $table = $this->getTable(); - $aggregateColumn = $table->getColumn($this->getParameter('column_name')); - $columnPhpName = $aggregateColumn->getPhpName(); - // Modify the setter to include encryption - $setterLocation = strpos($script, "set$columnPhpName"); - - $start = strpos($script, "(", $setterLocation) + 1; - $length = strpos($script, ")", $setterLocation) - $start; - $variableName = substr($script, $start, $length); - - $insertionStart = strpos($script, "{", $setterLocation) + 1; - $script = substr_replace($script, $this->encryptVariable($variableName), $insertionStart, 0); - - // Modify the getter to include decryption - $getterLocation = strpos($script, "get$columnPhpName"); + foreach ($this->getEncryptedColumnNames() as $columnName) { + $aggregateColumn = $table->getColumn($columnName); + $columnPhpName = $aggregateColumn->getPhpName(); - $start = strpos($script, "return", $getterLocation) + 7; - $length = strpos($script, ";", $getterLocation) - $start; - $variableName = substr($script, $start, $length); + $this->modifySetterWithEncryption($script, $columnPhpName); + $this->modifyGetterWithDecryption($script, $columnPhpName); - $insertionStart = strpos($script, "return", $getterLocation); - $insertionLength = strpos($script, ";", $insertionStart) - $insertionStart + 1; - $script = substr_replace($script, $this->decryptVariable($variableName), $insertionStart, $insertionLength); + } } protected function getEncryptedColumnNames() { @@ -86,6 +72,17 @@ protected function makeEncryptedColumnsDeclaration($columnPhpName) { EOT; } + protected function modifySetterWithEncryption(&$script, $columnPhpName) { + $setterLocation = strpos($script, "set$columnPhpName"); + + $start = strpos($script, "(", $setterLocation) + 1; + $length = strpos($script, ")", $setterLocation) - $start; + $variableName = substr($script, $start, $length); + + $insertionStart = strpos($script, "{", $setterLocation) + 1; + $script = substr_replace($script, $this->encryptVariable($variableName), $insertionStart, 0); + } + protected function encryptVariable($variableName) { return <<decryptVariable($variableName), $insertionStart, $insertionLength); + } + protected function decryptVariable($variableName) { return <<