diff --git a/src/EncryptionBehavior.php b/src/EncryptionBehavior.php index 967de91..f295b35 100644 --- a/src/EncryptionBehavior.php +++ b/src/EncryptionBehavior.php @@ -127,7 +127,11 @@ protected function modifyGetterWithDecryption(&$script, $columnPhpName) { protected function decryptVariable($variableName) { return <<decryptStream($variableName); + \$fieldValue = $variableName; + if (is_resource(\$fieldValue) && get_resource_type(\$fieldValue) === "stream") { + \$fieldValue = \UWDOEM\Encryption\Cipher::getInstance()->decryptStream(\$fieldValue); + } + return \$fieldValue; EOT; } diff --git a/tests/BehaviorTest.php b/tests/BehaviorTest.php index 0a06952..eb4f2c7 100644 --- a/tests/BehaviorTest.php +++ b/tests/BehaviorTest.php @@ -28,7 +28,11 @@ public function setVarBinaryColumn1($v) public function getVarBinaryColumn1() { // Decrypt the variable, per \UWDOEM\Encryption\EncryptionBehavior. - $this->test_column = \UWDOEM\Encryption\Cipher::getInstance()->decryptStream($this->test_column); + $fieldValue = $this->test_column; + if (is_resource($fieldValue) && get_resource_type($fieldValue) === "stream") { + $fieldValue = \UWDOEM\Encryption\Cipher::getInstance()->decryptStream($fieldValue); + } + return $fieldValue; } public function setVarBinaryColumn1($v)