diff --git a/rdb/Connection.php b/rdb/Connection.php index dcfdf63..be75e1b 100644 --- a/rdb/Connection.php +++ b/rdb/Connection.php @@ -227,7 +227,7 @@ public function run(Query $query, $options = array(), &$profile = '') // Grab PHP-RQL specific options $toNativeOptions = array(); - foreach (array('binaryFormat', 'timeFormat') as $opt) { + foreach (array('binaryFormat', 'timeFormat', 'documentFormat') as $opt) { if (isset($options) && isset($options[$opt])) { $toNativeOptions[$opt] = $options[$opt]; unset($options[$opt]); @@ -271,7 +271,6 @@ public function run(Query $query, $options = array(), &$profile = '') } else { return $this->createCursorFromResponse($response, $token, $response['n'], $toNativeOptions); } - } public function continueQuery($token) diff --git a/rdb/Datum/ObjectDatum.php b/rdb/Datum/ObjectDatum.php index 7e241ad..983948d 100644 --- a/rdb/Datum/ObjectDatum.php +++ b/rdb/Datum/ObjectDatum.php @@ -48,7 +48,11 @@ public function setValue($val) public function toNative($opts) { - $native = new \ArrayObject(); + if (isset($opts['documentFormat']) && $opts['documentFormat'] == 'array') { + $native = array(); + } else { + $native = new \ArrayObject(); + } foreach ($this->getValue() as $key => $val) { $native[$key] = $val->toNative($opts); } diff --git a/rdb/DatumConverter.php b/rdb/DatumConverter.php index 055e3a9..eb67ada 100644 --- a/rdb/DatumConverter.php +++ b/rdb/DatumConverter.php @@ -158,7 +158,6 @@ public function canEncodeAsJson($v) } return false; - } public function wrapImplicitVar(Query $q) diff --git a/tests/Functional/DocumentTest.php b/tests/Functional/DocumentTest.php new file mode 100644 index 0000000..32f966a --- /dev/null +++ b/tests/Functional/DocumentTest.php @@ -0,0 +1,47 @@ +conn = $this->getConnection(); + $this->data = $this->useDataset('Heroes'); + $this->data->populate(); + } + + public function tearDown() + { + $this->data->truncate(); + } + + public function testDocumentDefault() + { + $res = $this->db()->table('marvel') + ->get('Iron Man') + ->run($this->conn); + + $this->assertInstanceOf('ArrayObject', $res); + } + + public function testDocumentArrayObject() + { + $res = $this->db()->table('marvel') + ->get('Iron Man') + ->run($this->conn, array('documentFormat' => 'ArrayObject')); + + $this->assertInstanceOf('ArrayObject', $res); + } + + public function testDocumentNativeArray() + { + $res = $this->db()->table('marvel') + ->get('Iron Man') + ->run($this->conn, array('documentFormat' => 'array')); + + $this->assertInternalType('array', $res); + } +}