-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace MongoDB\Model; | ||
|
||
use MongoDB\BSON\Serializable; | ||
use MongoDB\BSON\Unserializable; | ||
use ArrayObject; | ||
|
||
/** | ||
* Model class for a BSON array. | ||
* | ||
* The internal data will be filtered through array_values() during BSON | ||
* serialization to ensure that it becomes a BSON array. | ||
* | ||
* @api | ||
*/ | ||
class BSONArray extends ArrayObject implements Serializable, Unserializable | ||
{ | ||
/** | ||
* Serialize the array to BSON. | ||
* | ||
* The array data will be numerically reindexed to ensure that it is stored | ||
* as a BSON array. | ||
* | ||
* @see http://php.net/mongodb-bson-serializable.bsonserialize | ||
* @return array | ||
*/ | ||
public function bsonSerialize() | ||
{ | ||
return array_values($this->getArrayCopy()); | ||
} | ||
|
||
/** | ||
* Unserialize the document to BSON. | ||
* | ||
* @see http://php.net/mongodb-bson-unserializable.bsonunserialize | ||
* @param array $data Array data | ||
*/ | ||
public function bsonUnserialize(array $data) | ||
{ | ||
self::__construct($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace MongoDB\Model; | ||
|
||
use MongoDB\BSON\Serializable; | ||
use MongoDB\BSON\Unserializable; | ||
use ArrayObject; | ||
|
||
/** | ||
* Model class for a BSON document. | ||
* | ||
* The internal data will be cast to an object during BSON serialization to | ||
* ensure that it becomes a BSON document. | ||
* | ||
* @api | ||
*/ | ||
class BSONDocument extends ArrayObject implements Serializable, Unserializable | ||
{ | ||
/** | ||
* Serialize the document to BSON. | ||
* | ||
* @see http://php.net/mongodb-bson-serializable.bsonserialize | ||
* @return object | ||
*/ | ||
public function bsonSerialize() | ||
{ | ||
return (object) $this->getArrayCopy(); | ||
} | ||
|
||
/** | ||
* Unserialize the document to BSON. | ||
* | ||
* @see http://php.net/mongodb-bson-unserializable.bsonunserialize | ||
* @param array $data Array data | ||
*/ | ||
public function bsonUnserialize(array $data) | ||
{ | ||
self::__construct($data, ArrayObject::ARRAY_AS_PROPS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters