diff --git a/src/EncryptionBehavior.php b/src/EncryptionBehavior.php index fc8083c..1854efb 100644 --- a/src/EncryptionBehavior.php +++ b/src/EncryptionBehavior.php @@ -20,31 +20,26 @@ public function allowMultiple() { public function tableMapFilter(&$script) { $table = $this->getTable(); - $aggregateColumn = $table->getColumn($this->getParameter('column_name')); - $columnPhpName = $aggregateColumn->getPhpName(); - - $encryptedColumnsDeclarationLocation = strpos($script, "ENCRYPTED_COLUMNS"); - // If there is not yet an encrypted column declared in this map... - if ($encryptedColumnsDeclarationLocation === False) { + foreach ($this->getEncryptedColumnNames() as $columnName) { + $column = $table->getColumn($columnName); + $columnPhpName = $column->getPhpName(); - // Insert after the CLASS_NAME declaration - $insertLocation = strpos($script, ";", strpos($script, "const CLASS_NAME")) + 1; + $encryptedColumnsDeclarationLocation = strpos($script, "ENCRYPTED_COLUMNS"); - $insertContent = <<makeEncryptedColumnsDeclaration($columnPhpName); - /** - * Those columns encrypted by UWDOEM/Encryption - */ - const ENCRYPTED_COLUMNS = '$columnPhpName'; -EOT; - + } else { + // If there is already an encrypted column declared in this map... + $insertLocation = strpos($script, "'", $encryptedColumnsDeclarationLocation) + 1; + $insertContent = "$columnPhpName "; + } $script = substr_replace($script, $insertContent, $insertLocation, 0); - // If there is already an encrypted column declared in this map... - } else { - $insertLocation = strpos($script, "'", $encryptedColumnsDeclarationLocation) + 1; - $script = substr_replace($script, "$columnPhpName ", $insertLocation, 0); } } @@ -76,6 +71,21 @@ public function objectFilter(&$script) { $script = substr_replace($script, $this->decryptVariable($variableName), $insertionStart, $insertionLength); } + protected function getEncryptedColumnNames() { + return [$this->getParameter('column_name')]; + } + + protected function makeEncryptedColumnsDeclaration($columnPhpName) { + return <<