Commit 4abff17e authored by Karamel's avatar Karamel
Browse files

Handle base64 encoding of Image data directly in toStruct.

parent ec052383
......@@ -152,4 +152,30 @@ class Image extends DoctrineModel
public function getImage() { return $this->image; }
public function setImage($image) { $this->image = $image; }
public function toStruct() {
// Handle base64 encoding of binary image
$struct = parent::toStruct();
switch (gettype($struct['image'])) {
case 'resource':
$struct['image'] = stream_get_contents($struct['image']);
break;
default:
// already a binary string
}
$struct['image'] = base64_encode($struct['image']);
return $struct;
}
public static function fromStruct($struct, $dao, $embedded = false) {
// Convert incoming base64 data into binary before reading
$newStruct = ['model' => $struct['model'],
'modelId' => $struct['modelId'],
'mimeType' => $struct['mimeType'],
'image' => base64_decode($struct['image'])];
if (isset($struct['id'])) {
$newStruct['id'] = $struct['id'];
}
return parent::fromStruct($newStruct, $dao, $embedded);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment