瀏覽代碼

Merge branch '1.0.x'

* 1.0.x:
  Add release date for 1.0.6
  Update changelog
  Add implementation of JsonSerializable to MongoId
Andreas Braun 9 年之前
父節點
當前提交
2d345fd33e
共有 3 個文件被更改,包括 25 次插入3 次删除
  1. 11 2
      CHANGELOG-1.0.md
  2. 11 1
      lib/Mongo/MongoId.php
  3. 3 0
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoIdTest.php

+ 11 - 2
CHANGELOG-1.0.md

@@ -3,15 +3,24 @@ CHANGELOG
 
 This changelog references the relevant changes done in minor version updates.
 
-1.0.6 (xxxx-xx-xx)
+1.0.7 (xxxx-xx-xx)
 ------------------
 
 All issues and pull requests under this release may be found under the
-[1.0.6](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.0.5)
+[1.0.7](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.0.7)
+milestone.
+
+1.0.6 (2016-10-07)
+------------------
+
+All issues and pull requests under this release may be found under the
+[1.0.6](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.0.6)
 milestone.
 
  * [#126](https://github.com/alcaeus/mongo-php-adapter/pull/126) fixes a class
  name that was improperly capitalized.
+ * [#130](https://github.com/alcaeus/mongo-php-adapter/pull/130) fixes JSON
+ serialization of `MongoId` objects.
 
 1.0.5 (2016-07-03)
 ------------------

+ 11 - 1
lib/Mongo/MongoId.php

@@ -20,7 +20,7 @@ if (class_exists('MongoId', false)) {
 use Alcaeus\MongoDbAdapter\TypeInterface;
 use MongoDB\BSON\ObjectID;
 
-class MongoId implements Serializable, TypeInterface
+class MongoId implements Serializable, TypeInterface, JsonSerializable
 {
     /*
      * @var ObjectID
@@ -201,6 +201,16 @@ class MongoId implements Serializable, TypeInterface
     }
 
     /**
+     * @return stdClass
+     */
+    public function jsonSerialize()
+    {
+        $object = new stdClass();
+        $object->{'$id'} = (string) $this->objectID;
+        return $object;
+    }
+
+    /**
      * @param $id
      * @throws MongoException
      */

+ 3 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoIdTest.php

@@ -24,6 +24,9 @@ class MongoIdTest extends TestCase
         $unserialized = unserialize($serialized);
         $this->assertInstanceOf('MongoId', $unserialized);
         $this->assertSame($stringId, (string) $unserialized);
+
+        $json = json_encode($id);
+        $this->assertSame(sprintf('{"$id":"%s"}', $stringId), $json);
     }
 
     public function testCreateWithString()