Skip to content

Commit 3fa8cc8

Browse files
committed
PHPC-119 && PHPC-49: Create PHP interfaces for BSON (un-)serialization
1 parent aed68e0 commit 3fa8cc8

File tree

5 files changed

+181
-0
lines changed

5 files changed

+181
-0
lines changed

config.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ if test "$PHONGO" != "no"; then
140140
";
141141
PHONGO_BSON_CLASSES="\
142142
src/BSON/Type.c \
143+
src/BSON/Unserializable.c \
144+
src/BSON/Serializable.c \
143145
src/BSON/Binary.c \
144146
src/BSON/Javascript.c \
145147
src/BSON/MaxKey.c \

php_phongo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,8 @@ PHP_MINIT_FUNCTION(phongo)
14531453
PHP_MINIT(DuplicateKeyException)(INIT_FUNC_ARGS_PASSTHRU);
14541454

14551455
PHP_MINIT(Type)(INIT_FUNC_ARGS_PASSTHRU);
1456+
PHP_MINIT(Serializable)(INIT_FUNC_ARGS_PASSTHRU);
1457+
PHP_MINIT(Unserializable)(INIT_FUNC_ARGS_PASSTHRU);
14561458
PHP_MINIT(Binary)(INIT_FUNC_ARGS_PASSTHRU);
14571459
PHP_MINIT(Javascript)(INIT_FUNC_ARGS_PASSTHRU);
14581460
PHP_MINIT(MaxKey)(INIT_FUNC_ARGS_PASSTHRU);

php_phongo_classes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ PHP_MINIT_FUNCTION(DuplicateKeyException);
239239
PHP_MINIT_FUNCTION(WriteException);
240240

241241
PHP_MINIT_FUNCTION(Type);
242+
PHP_MINIT_FUNCTION(Unserializable);
243+
PHP_MINIT_FUNCTION(Serializable);
242244
PHP_MINIT_FUNCTION(Binary);
243245
PHP_MINIT_FUNCTION(Javascript);
244246
PHP_MINIT_FUNCTION(MaxKey);

src/BSON/Serializable.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
+---------------------------------------------------------------------------+
3+
| PHP Driver for MongoDB |
4+
+---------------------------------------------------------------------------+
5+
| Copyright 2013-2014 MongoDB, Inc. |
6+
| |
7+
| Licensed under the Apache License, Version 2.0 (the "License"); |
8+
| you may not use this file except in compliance with the License. |
9+
| You may obtain a copy of the License at |
10+
| |
11+
| http://www.apache.org/licenses/LICENSE-2.0 |
12+
| |
13+
| Unless required by applicable law or agreed to in writing, software |
14+
| distributed under the License is distributed on an "AS IS" BASIS, |
15+
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16+
| See the License for the specific language governing permissions and |
17+
| limitations under the License. |
18+
+---------------------------------------------------------------------------+
19+
| Copyright (c) 2014, MongoDB, Inc. |
20+
+---------------------------------------------------------------------------+
21+
*/
22+
23+
#ifdef HAVE_CONFIG_H
24+
# include "config.h"
25+
#endif
26+
27+
/* External libs */
28+
#include <bson.h>
29+
#include <mongoc.h>
30+
31+
/* PHP Core stuff */
32+
#include <php.h>
33+
#include <php_ini.h>
34+
#include <ext/standard/info.h>
35+
#include <Zend/zend_interfaces.h>
36+
#include <ext/spl/spl_iterators.h>
37+
/* Our Compatability header */
38+
#include "php_compat_53.h"
39+
40+
/* Our stuffz */
41+
#include "php_phongo.h"
42+
#include "php_bson.h"
43+
44+
45+
PHONGO_API zend_class_entry *php_phongo_serializable_ce;
46+
47+
48+
49+
/* {{{ BSON\Serializable */
50+
51+
ZEND_BEGIN_ARG_INFO_EX(ai_serializable_bsonserialize, 0, 0, 0)
52+
ZEND_END_ARG_INFO();
53+
54+
55+
static zend_function_entry php_phongo_serializable_me[] = {
56+
ZEND_ABSTRACT_ME(Serializable, bsonSerialize, ai_serializable_bsonserialize)
57+
PHP_FE_END
58+
};
59+
60+
/* }}} */
61+
62+
63+
64+
/* {{{ PHP_MINIT_FUNCTION */
65+
PHP_MINIT_FUNCTION(Serializable)
66+
{
67+
(void)type;
68+
(void)module_number;
69+
zend_class_entry ce;
70+
71+
INIT_NS_CLASS_ENTRY(ce, "BSON", "Serializable", php_phongo_serializable_me);
72+
php_phongo_serializable_ce = zend_register_internal_interface(&ce TSRMLS_CC);
73+
74+
return SUCCESS;
75+
}
76+
/* }}} */
77+
78+
79+
80+
/*
81+
* Local variables:
82+
* tab-width: 4
83+
* c-basic-offset: 4
84+
* End:
85+
* vim600: noet sw=4 ts=4 fdm=marker
86+
* vim<600: noet sw=4 ts=4
87+
*/

src/BSON/Unserializable.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
+---------------------------------------------------------------------------+
3+
| PHP Driver for MongoDB |
4+
+---------------------------------------------------------------------------+
5+
| Copyright 2013-2014 MongoDB, Inc. |
6+
| |
7+
| Licensed under the Apache License, Version 2.0 (the "License"); |
8+
| you may not use this file except in compliance with the License. |
9+
| You may obtain a copy of the License at |
10+
| |
11+
| http://www.apache.org/licenses/LICENSE-2.0 |
12+
| |
13+
| Unless required by applicable law or agreed to in writing, software |
14+
| distributed under the License is distributed on an "AS IS" BASIS, |
15+
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16+
| See the License for the specific language governing permissions and |
17+
| limitations under the License. |
18+
+---------------------------------------------------------------------------+
19+
| Copyright (c) 2014, MongoDB, Inc. |
20+
+---------------------------------------------------------------------------+
21+
*/
22+
23+
#ifdef HAVE_CONFIG_H
24+
# include "config.h"
25+
#endif
26+
27+
/* External libs */
28+
#include <bson.h>
29+
#include <mongoc.h>
30+
31+
/* PHP Core stuff */
32+
#include <php.h>
33+
#include <php_ini.h>
34+
#include <ext/standard/info.h>
35+
#include <Zend/zend_interfaces.h>
36+
#include <ext/spl/spl_iterators.h>
37+
/* Our Compatability header */
38+
#include "php_compat_53.h"
39+
40+
/* Our stuffz */
41+
#include "php_phongo.h"
42+
#include "php_bson.h"
43+
44+
45+
PHONGO_API zend_class_entry *php_phongo_unserializable_ce;
46+
47+
48+
49+
/* {{{ BSON\Unserializable */
50+
51+
ZEND_BEGIN_ARG_INFO_EX(ai_unserializable_bsonunserialize, 0, 0, 1)
52+
ZEND_ARG_ARRAY_INFO(0, data, 0)
53+
ZEND_END_ARG_INFO();
54+
55+
56+
static zend_function_entry php_phongo_unserializable_me[] = {
57+
ZEND_ABSTRACT_ME(Unserializable, bsonUnserialize, ai_unserializable_bsonunserialize)
58+
PHP_FE_END
59+
};
60+
61+
/* }}} */
62+
63+
64+
65+
/* {{{ PHP_MINIT_FUNCTION */
66+
PHP_MINIT_FUNCTION(Unserializable)
67+
{
68+
(void)type;
69+
(void)module_number;
70+
zend_class_entry ce;
71+
72+
INIT_NS_CLASS_ENTRY(ce, "BSON", "Unserializable", php_phongo_unserializable_me);
73+
php_phongo_unserializable_ce = zend_register_internal_interface(&ce TSRMLS_CC);
74+
75+
return SUCCESS;
76+
}
77+
/* }}} */
78+
79+
80+
81+
/*
82+
* Local variables:
83+
* tab-width: 4
84+
* c-basic-offset: 4
85+
* End:
86+
* vim600: noet sw=4 ts=4 fdm=marker
87+
* vim<600: noet sw=4 ts=4
88+
*/

0 commit comments

Comments
 (0)