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
7039bd7a
Commit
7039bd7a
authored
Jan 19, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #96
parents
35aa9509
c094f990
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
0 deletions
+50
-0
BSONArray.php
src/Model/BSONArray.php
+16
-0
BSONDocument.php
src/Model/BSONDocument.php
+16
-0
BSONArrayTest.php
tests/Model/BSONArrayTest.php
+9
-0
BSONDocumentTest.php
tests/Model/BSONDocumentTest.php
+9
-0
No files found.
src/Model/BSONArray.php
View file @
7039bd7a
...
...
@@ -16,6 +16,22 @@ use ArrayObject;
*/
class
BSONArray
extends
ArrayObject
implements
Serializable
,
Unserializable
{
/**
* Factory method for var_export().
*
* @see http://php.net/oop5.magic#object.set-state
* @see http://php.net/var-export
* @param array $properties
* @return self
*/
public
static
function
__set_state
(
array
$properties
)
{
$array
=
new
static
;
$array
->
exchangeArray
(
$properties
);
return
$array
;
}
/**
* Serialize the array to BSON.
*
...
...
src/Model/BSONDocument.php
View file @
7039bd7a
...
...
@@ -29,6 +29,22 @@ class BSONDocument extends ArrayObject implements Serializable, Unserializable
parent
::
__construct
(
$input
,
$flags
,
$iterator_class
);
}
/**
* Factory method for var_export().
*
* @see http://php.net/oop5.magic#object.set-state
* @see http://php.net/var-export
* @param array $properties
* @return self
*/
public
static
function
__set_state
(
array
$properties
)
{
$document
=
new
static
;
$document
->
exchangeArray
(
$properties
);
return
$document
;
}
/**
* Serialize the document to BSON.
*
...
...
tests/Model/BSONArrayTest.php
View file @
7039bd7a
...
...
@@ -14,4 +14,13 @@ class BSONArrayTest extends TestCase
$this
->
assertSame
(
$data
,
$array
->
getArrayCopy
());
$this
->
assertSame
([
'foo'
,
'bar'
],
$array
->
bsonSerialize
());
}
public
function
testSetState
()
{
$data
=
[
'foo'
,
'bar'
];
$array
=
BSONArray
::
__set_state
(
$data
);
$this
->
assertInstanceOf
(
'MongoDB\Model\BSONArray'
,
$array
);
$this
->
assertSame
(
$data
,
$array
->
getArrayCopy
());
}
}
tests/Model/BSONDocumentTest.php
View file @
7039bd7a
...
...
@@ -22,4 +22,13 @@ class BSONDocumentTest extends TestCase
$this
->
assertSame
(
$data
,
$document
->
getArrayCopy
());
$this
->
assertEquals
((
object
)
[
0
=>
'foo'
,
2
=>
'bar'
],
$document
->
bsonSerialize
());
}
public
function
testSetState
()
{
$data
=
[
'foo'
=>
'bar'
];
$document
=
BSONDocument
::
__set_state
(
$data
);
$this
->
assertInstanceOf
(
'MongoDB\Model\BSONDocument'
,
$document
);
$this
->
assertSame
(
$data
,
$document
->
getArrayCopy
());
}
}
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