فهرست منبع

Merge pull request #127 from alcaeus/javascript-tostring

Read code and scope from Javascript objects
Andreas 9 سال پیش
والد
کامیت
444f17d183
7فایلهای تغییر یافته به همراه25 افزوده شده و 17 حذف شده
  1. 2 2
      .travis.yml
  2. 15 0
      CHANGELOG-1.1.md
  3. 0 6
      README.md
  4. 0 5
      UPGRADE-1.1.md
  5. 1 0
      composer.json
  6. 5 2
      lib/Mongo/MongoCode.php
  7. 2 2
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoCodeTest.php

+ 2 - 2
.travis.yml

@@ -7,12 +7,12 @@ php:
   - 7.0
 
 env:
-  - DRIVER_VERSION=stable
+  - DRIVER_VERSION=1.2.0alpha1
 
 matrix:
   include:
     - php: 5.6
-      env: DRIVER_VERSION=stable LEGACY_DRIVER_VERSION=stable
+      env: DRIVER_VERSION=1.2.0alpha1 LEGACY_DRIVER_VERSION=stable
 
 addons:
   apt:

+ 15 - 0
CHANGELOG-1.1.md

@@ -0,0 +1,15 @@
+CHANGELOG
+=========
+
+This changelog references the relevant changes done in minor version updates.
+
+1.1.0-BETA1 (xxxx-xx-xx)
+------------------
+
+All issues and pull requests under this release may be found under the
+[1.1.0](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.1.0)
+milestone.
+
+ * [#127](https://github.com/alcaeus/mongo-php-adapter/pull/127) reads the `code`
+ and `scope` properties of `MongoDB\BSON\Javascript` objects when converting them
+ to `MongoCode` objects.

+ 0 - 6
README.md

@@ -131,9 +131,3 @@ unserializing them.
  fields always return 0 for compatibility to MongoCursor. The `firstBatchAt` and
  `firstBatchNumReturned` fields will contain the same value, which is the internal
  position of the iterator.
-
-## Types
-
- - Return values containing objects of the [MongoDB\BSON\Javascript](https://secure.php.net/manual/en/class.mongodb-bson-javascript.php)
- class cannot be converted to full [MongoCode](https://secure.php.net/manual/en/class.mongocode.php)
- objects because there are no accessors for the code and scope properties.

+ 0 - 5
UPGRADE-1.1.md

@@ -1,5 +0,0 @@
-PGRADE from 1.0 to 1.1
-=======================
-
-Pull requests completed for the 1.1.0 release:
-

+ 1 - 0
composer.json

@@ -11,6 +11,7 @@
     "require": {
         "php": "^5.5 || ^7.0",
         "ext-hash": "*",
+        "ext-mongodb": "^1.2.0",
         "mongodb/mongodb": "^1.0.1"
     },
     "require-dev": {

+ 5 - 2
lib/Mongo/MongoCode.php

@@ -13,6 +13,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+use Alcaeus\MongoDbAdapter\TypeConverter;
+
 if (class_exists('MongoCode', false)) {
     return;
 }
@@ -37,8 +39,9 @@ class MongoCode implements \Alcaeus\MongoDbAdapter\TypeInterface
     public function __construct($code, array $scope = [])
     {
         if ($code instanceof \MongoDB\BSON\Javascript) {
-            // @todo Use properties from object once they are accessible
-            $code = '';
+            $javascript = $code;
+            $code = $javascript->getCode();
+            $scope = TypeConverter::toLegacy($javascript->getScope());
         }
 
         $this->code = $code;

+ 2 - 2
tests/Alcaeus/MongoDbAdapter/Mongo/MongoCodeTest.php

@@ -39,7 +39,7 @@ class MongoCodeTest extends TestCase
         $bsonCode = new \MongoDB\BSON\Javascript('code', ['scope' => 'bleh']);
         $code = new \MongoCode($bsonCode);
 
-        $this->assertAttributeSame('', 'code', $code);
-        $this->assertAttributeSame([], 'scope', $code);
+        $this->assertAttributeSame('code', 'code', $code);
+        $this->assertAttributeSame(['scope' => 'bleh'], 'scope', $code);
     }
 }