Skip to content

Commit 46a0849

Browse files
committed
Merge pull request #350
2 parents ba167a3 + 67bd17c commit 46a0849

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

src/BSON/Binary.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ PHP_METHOD(Binary, __set_state)
131131
}
132132
/* }}} */
133133

134+
/* {{{ proto string Binary::__toString()
135+
Return the Binary's data string. */
136+
PHP_METHOD(Binary, __toString)
137+
{
138+
php_phongo_binary_t *intern;
139+
140+
if (zend_parse_parameters_none() == FAILURE) {
141+
return;
142+
}
143+
144+
intern = Z_BINARY_OBJ_P(getThis());
145+
146+
PHONGO_RETURN_STRINGL(intern->data, intern->data_len);
147+
}
148+
/* }}} */
149+
134150
/* {{{ proto void Binary::__wakeup()
135151
*/
136152
PHP_METHOD(Binary, __wakeup)
@@ -201,6 +217,7 @@ ZEND_END_ARG_INFO()
201217
static zend_function_entry php_phongo_binary_me[] = {
202218
PHP_ME(Binary, __construct, ai_Binary___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
203219
PHP_ME(Binary, __set_state, ai_Binary___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
220+
PHP_ME(Binary, __toString, ai_Binary_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
204221
PHP_ME(Binary, __wakeup, ai_Binary_void, ZEND_ACC_PUBLIC)
205222
PHP_ME(Binary, getData, ai_Binary_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
206223
PHP_ME(Binary, getType, ai_Binary_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)

src/BSON/Javascript.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ PHP_METHOD(Javascript, __set_state)
146146
}
147147
/* }}} */
148148

149+
/* {{{ proto string Javascript::__toString()
150+
Return the Javascript's code string. */
151+
PHP_METHOD(Javascript, __toString)
152+
{
153+
php_phongo_javascript_t *intern;
154+
155+
if (zend_parse_parameters_none() == FAILURE) {
156+
return;
157+
}
158+
159+
intern = Z_JAVASCRIPT_OBJ_P(getThis());
160+
161+
PHONGO_RETURN_STRINGL(intern->code, intern->code_len);
162+
}
163+
/* }}} */
164+
149165
/* {{{ proto void Javascript::__wakeup()
150166
*/
151167
PHP_METHOD(Javascript, __wakeup)
@@ -181,6 +197,7 @@ ZEND_END_ARG_INFO()
181197
static zend_function_entry php_phongo_javascript_me[] = {
182198
PHP_ME(Javascript, __construct, ai_Javascript___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
183199
PHP_ME(Javascript, __set_state, ai_Javascript___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
200+
PHP_ME(Javascript, __toString, ai_Javascript_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
184201
PHP_ME(Javascript, __wakeup, ai_Javascript_void, ZEND_ACC_PUBLIC)
185202
PHP_FE_END
186203
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
MongoDB\BSON\Binary::__toString()
3+
--FILE--
4+
<?php
5+
6+
$binary = new MongoDB\BSON\Binary('foobar', MongoDB\BSON\Binary::TYPE_GENERIC);
7+
var_dump((string) $binary);
8+
9+
?>
10+
===DONE===
11+
<?php exit(0); ?>
12+
--EXPECTF--
13+
string(6) "foobar"
14+
===DONE===
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
MongoDB\BSON\Javascript::__toString()
3+
--FILE--
4+
<?php
5+
6+
$js = new MongoDB\BSON\Javascript('function foo() { return 1; }');
7+
var_dump((string) $js);
8+
9+
$js = new MongoDB\BSON\Javascript('function foo() { return bar; }', ['bar' => 1]);
10+
var_dump((string) $js);
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECTF--
16+
string(28) "function foo() { return 1; }"
17+
string(30) "function foo() { return bar; }"
18+
===DONE===

0 commit comments

Comments
 (0)