Skip to content

Loading…

bug fixes #18

Closed
wants to merge 2 commits into from

1 participant

@mgrandi

Fixed some classes not being mapped in bootstrap.php

fixed binary data not printing out when you print an object that you get from the database with a BinaryData property

mgrandi added some commits
@mgrandi mgrandi fixed bootstrap.php to map the classes Boolean, Regex, BinaryData, In…
…teger32 and Integer64
146e665
@mgrandi mgrandi 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
410b2ee
@mgrandi

whoops, it seems i used tabs instead of spaces in bootstrap.php so i'll make another pullrequest and close this one. sorry i'm new at this xD

@mgrandi mgrandi closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 31, 2011
  1. @mgrandi
Commits on Jun 1, 2011
  1. @mgrandi

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

    mgrandi committed
    … 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
Showing with 28 additions and 2 deletions.
  1. +6 −1 src/bootstrap.php
  2. +7 −1 src/morph/Object.php
  3. +15 −0 src/morph/property/BinaryData.php
View
7 src/bootstrap.php
@@ -41,6 +41,11 @@ class MorphAutoloader
'morph\\property\\ComposeOne' => 'phar://Morph/property/ComposeOne.php',
'morph\\property\\String' => 'phar://Morph/property/String.php',
'morph\\property\\Generic' => 'phar://Morph/property/Generic.php',
+ 'morph\\property\\Boolean' => 'phar://Morph/property/Boolean.php',
+ 'morph\\property\\BinaryData' => 'phar://Morph/property/BinaryData.php',
+ 'morph\\property\\Integer32' => 'phar://Morph/property/Integer32.php',
+ 'morph\\property\\Integer64' => 'phar://Morph/property/Integer64.php',
+ 'morph\\property\\Regex' => 'phar://Morph/property/Regex.php',
'morph\\query\\Property' => 'phar://Morph/query/Property.php',
'morph\\format\\Collection' => 'phar://Morph/format/Collection.php',
'morph\\exception\\ObjectNotFound' => 'phar://Morph/exception/ObjectNotFound.php',
@@ -67,4 +72,4 @@ public static function load($className)
//register the autoloader
spl_autoload_register(array('MorphAutoloader', 'load'));
-__HALT_COMPILER();
+__HALT_COMPILER();
View
8 src/morph/Object.php
@@ -286,13 +286,19 @@ public function delete()
*/
public function __toString()
{
+ // create the array that we will be encoding and returning
+ // also put inside the array the mongodb ID and the 'state'
$data = array(
'Id' => $this->id(),
'State' => $this->state()
);
+
+ // iterate through all the properties this object has and print them out
foreach ($this->propertySet as $name => $property) {
+
$data[$name] = (string)$property;
- }
+ }
+
return \json_encode($data);
}
View
15 src/morph/property/BinaryData.php
@@ -86,4 +86,19 @@ public function __setRawValue($value)
return $this;
}
+
+ /**
+ * Returns the base64 encoding of the binary data
+ *
+ * @return String
+ */
+ public function __toString()
+ {
+
+ // we return the base64 encoding of the binary data because
+ // json does not have a native way to represent binary data
+ return base64_encode($this->value);
+
+ }
+
}
Something went wrong with that request. Please try again.