1 #include "../../common.h"
2 #include "../parameters.h"
3 #include "../arginfo.h"
4 #include "../objects/php_pair.h"
5 #include "../handlers/php_pair_handlers.h"
6 #include "php_pair_ce.h"
7
8 #define METHOD(name) PHP_METHOD(Pair, name)
9
10 zend_class_entry *php_ds_pair_ce;
11
METHOD(__construct)12 METHOD(__construct)
13 {
14 PARSE_OPTIONAL_ZVAL_OPTIONAL_ZVAL(key, value);
15 {
16 php_ds_pair_t *pair = THIS_DS_PAIR();
17
18 if (key) {
19 php_ds_pair_set_key(pair, key);
20 }
21
22 if (value) {
23 php_ds_pair_set_value(pair, value);
24 }
25 }
26 }
27
METHOD(copy)28 METHOD(copy)
29 {
30 PARSE_NONE;
31 RETURN_DS_PAIR(php_ds_pair_create_clone(THIS_DS_PAIR()));
32 }
33
METHOD(toArray)34 METHOD(toArray)
35 {
36 PARSE_NONE;
37 php_ds_pair_to_array(THIS_DS_PAIR(), return_value);
38 }
39
METHOD(jsonSerialize)40 METHOD(jsonSerialize)
41 {
42 PARSE_NONE;
43 php_ds_pair_to_array(THIS_DS_PAIR(), return_value);
44 }
45
php_ds_register_pair()46 void php_ds_register_pair()
47 {
48 zend_class_entry ce;
49
50 zend_function_entry methods[] = {
51 PHP_DS_ME(Pair, __construct)
52 PHP_DS_ME(Pair, copy)
53 PHP_DS_ME(Pair, jsonSerialize)
54 PHP_DS_ME(Pair, toArray)
55 PHP_FE_END
56 };
57
58 INIT_CLASS_ENTRY(ce, PHP_DS_NS(Pair), methods);
59 php_ds_pair_ce = zend_register_internal_class(&ce);
60
61 php_ds_pair_ce->ce_flags |= ZEND_ACC_FINAL;
62 php_ds_pair_ce->create_object = php_ds_pair_create_object;
63 php_ds_pair_ce->serialize = php_ds_pair_serialize;
64 php_ds_pair_ce->unserialize = php_ds_pair_unserialize;
65
66 zend_declare_property_null(php_ds_pair_ce, STR_AND_LEN("key"), ZEND_ACC_PUBLIC);
67 zend_declare_property_null(php_ds_pair_ce, STR_AND_LEN("value"), ZEND_ACC_PUBLIC);
68
69 zend_class_implements(php_ds_pair_ce, 1, php_json_serializable_ce);
70 php_ds_register_pair_handlers();
71 }
72