Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a __toString method to BinaryData.php so it prints out a base64…

… encoded version of the binary data, because before json_encode was throwing a 'invalid utf8 argument' when you tried to print out a binary data property
  • Loading branch information...
commit 410b2ee5b601110e33e6a5220ce23163308b72ee 1 parent 146e665
Mark Grandi authored

Showing 2 changed files with 22 additions and 1 deletion. Show diff stats Hide diff stats

  1. +7 1 src/morph/Object.php
  2. +15 0 src/morph/property/BinaryData.php
8 src/morph/Object.php
@@ -286,13 +286,19 @@ public function delete()
286 286 */
287 287 public function __toString()
288 288 {
  289 + // create the array that we will be encoding and returning
  290 + // also put inside the array the mongodb ID and the 'state'
289 291 $data = array(
290 292 'Id' => $this->id(),
291 293 'State' => $this->state()
292 294 );
  295 +
  296 + // iterate through all the properties this object has and print them out
293 297 foreach ($this->propertySet as $name => $property) {
  298 +
294 299 $data[$name] = (string)$property;
295   - }
  300 + }
  301 +
296 302 return \json_encode($data);
297 303 }
298 304
15 src/morph/property/BinaryData.php
@@ -86,4 +86,19 @@ public function __setRawValue($value)
86 86 return $this;
87 87 }
88 88
  89 +
  90 + /**
  91 + * Returns the base64 encoding of the binary data
  92 + *
  93 + * @return String
  94 + */
  95 + public function __toString()
  96 + {
  97 +
  98 + // we return the base64 encoding of the binary data because
  99 + // json does not have a native way to represent binary data
  100 + return base64_encode($this->value);
  101 +
  102 + }
  103 +
89 104 }

0 comments on commit 410b2ee

Please sign in to comment.
Something went wrong with that request. Please try again.