Skip to content

Commit faa8e05

Browse files
committed
Merge pull request #62
2 parents a1ebdcc + b3234e7 commit faa8e05

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/BSON/Binary.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,23 @@ PHP_METHOD(Binary, __construct)
6969
intern->subtype = subtype;
7070
}
7171
/* }}} */
72-
/* {{{ proto void Binary::getSubType()
72+
/* {{{ proto string Binary::getData()
73+
*/
74+
PHP_METHOD(Binary, getData)
75+
{
76+
php_phongo_binary_t *intern;
77+
78+
79+
intern = (php_phongo_binary_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
80+
81+
if (zend_parse_parameters_none() == FAILURE) {
82+
return;
83+
}
84+
85+
RETURN_STRINGL(intern->data, intern->data_len, 1);
86+
}
87+
/* }}} */
88+
/* {{{ proto integer Binary::getSubType()
7389
*/
7490
PHP_METHOD(Binary, getSubType)
7591
{
@@ -94,12 +110,16 @@ ZEND_BEGIN_ARG_INFO_EX(ai_Binary___construct, 0, 0, 2)
94110
ZEND_ARG_INFO(0, subtype)
95111
ZEND_END_ARG_INFO();
96112

113+
ZEND_BEGIN_ARG_INFO_EX(ai_Binary_getData, 0, 0, 0)
114+
ZEND_END_ARG_INFO();
115+
97116
ZEND_BEGIN_ARG_INFO_EX(ai_Binary_getSubType, 0, 0, 0)
98117
ZEND_END_ARG_INFO();
99118

100119

101120
static zend_function_entry php_phongo_binary_me[] = {
102121
PHP_ME(Binary, __construct, ai_Binary___construct, ZEND_ACC_PUBLIC)
122+
PHP_ME(Binary, getData, ai_Binary_getData, ZEND_ACC_PUBLIC)
103123
PHP_ME(Binary, getSubType, ai_Binary_getSubType, ZEND_ACC_PUBLIC)
104124
PHP_FE_END
105125
};

tests/bson/bson-binary-001.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $types = array(
2121
$tests = array();
2222
foreach($types as $type) {
2323
$binary = new $classname("random binary data", $type);
24+
var_dump($binary->getData() == "random binary data");
2425
var_dump($binary->getSubType() == $type);
2526
$tests[] = array("binary" => $binary);
2627
}
@@ -41,6 +42,7 @@ foreach($tests as $n => $test) {
4142
var_dump((object)$test == (object)$testagain);
4243
}
4344

45+
$binary->getData(2);
4446
$binary->getSubType(2);
4547
?>
4648
===DONE===
@@ -54,6 +56,14 @@ bool(true)
5456
bool(true)
5557
bool(true)
5658
bool(true)
59+
bool(true)
60+
bool(true)
61+
bool(true)
62+
bool(true)
63+
bool(true)
64+
bool(true)
65+
bool(true)
66+
bool(true)
5767
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
5868
Test#0 { "binary" : { "$type" : "00", "$binary" : "cmFuZG9tIGJpbmFyeSBkYXRh" } }
5969
string(73) "{ "binary" : { "$type" : "00", "$binary" : "cmFuZG9tIGJpbmFyeSBkYXRh" } }"
@@ -88,5 +98,7 @@ string(73) "{ "binary" : { "$type" : "85", "$binary" : "cmFuZG9tIGJpbmFyeSBkYXRh
8898
string(73) "{ "binary" : { "$type" : "85", "$binary" : "cmFuZG9tIGJpbmFyeSBkYXRh" } }"
8999
bool(true)
90100

101+
Warning: %s\Binary::getData() expects exactly 0 parameters, 1 given in %s on line %d
102+
91103
Warning: %s\Binary::getSubType() expects exactly 0 parameters, 1 given in %s on line %d
92104
===DONE===

0 commit comments

Comments
 (0)