Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
afb74871
Commit
afb74871
authored
Dec 28, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-74: Model classes for BSON array and document
parent
23e8e8e4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
0 deletions
+83
-0
BSONArray.php
src/Model/BSONArray.php
+43
-0
BSONDocument.php
src/Model/BSONDocument.php
+40
-0
No files found.
src/Model/BSONArray.php
0 → 100644
View file @
afb74871
<?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
);
}
}
src/Model/BSONDocument.php
0 → 100644
View file @
afb74871
<?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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment