Merge branch 'master' into phpng
[m6w6/ext-propro] / php_propro.h
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: propro |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2013 Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifndef PHP_PROPRO_H
14 #define PHP_PROPRO_H
15
16 #ifndef DOXYGEN
17
18 extern zend_module_entry propro_module_entry;
19 #define phpext_propro_ptr &propro_module_entry
20
21 #define PHP_PROPRO_VERSION "2.0.0dev"
22
23 #ifdef PHP_WIN32
24 # define PHP_PROPRO_API __declspec(dllexport)
25 #elif defined(__GNUC__) && __GNUC__ >= 4
26 # define PHP_PROPRO_API extern __attribute__ ((visibility("default")))
27 #else
28 # define PHP_PROPRO_API extern
29 #endif
30
31 #ifdef ZTS
32 # include <TSRM/TSRM.h>
33 #endif
34
35 #define PHP_PROPRO_PTR(zo) (void*)(((char*)(zo))-(zo)->handlers->offset)
36
37 #endif /* DOXYGEN */
38
39 /**
40 * The internal property proxy.
41 *
42 * Container for the object/array holding the proxied property.
43 */
44 struct php_property_proxy {
45 /** The container holding the property */
46 zval container;
47 /** The name of the proxied property */
48 zend_string *member;
49 };
50 typedef struct php_property_proxy php_property_proxy_t;
51
52 /**
53 * The userland object.
54 *
55 * Return an object instance of php\\PropertyProxy to make your C-struct
56 * member accessible by reference from PHP userland.
57 *
58 * Example:
59 * ~~~~~~~~~~{.c}
60 * static zval *my_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
61 * {
62 * zval *return_value;
63 * zend_string *member_name = zval_get_string(member);
64 * my_prophandler_t *handler = my_get_prophandler(member_name);
65 *
66 * if (!handler || type == BP_VAR_R || type == BP_VAR_IS) {
67 * return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
68 *
69 * if (handler) {
70 * handler->read(object, tmp);
71 *
72 * zval_ptr_dtor(return_value);
73 * ZVAL_COPY_VALUE(return_value, tmp);
74 * }
75 * } else {
76 * return_value = php_property_proxy_zval(object, member_name);
77 * }
78 *
79 * zend_string_release(member_name);
80 *
81 * return return_value;
82 * }
83 * ~~~~~~~~~~
84 */
85 struct php_property_proxy_object {
86 /** The actual property proxy */
87 php_property_proxy_t *proxy;
88 /** Any parent property proxy object */
89 zval parent;
90 /** The std zend_object */
91 zend_object zo;
92 };
93 typedef struct php_property_proxy_object php_property_proxy_object_t;
94
95 PHP_PROPRO_API php_property_proxy_object_t *php_property_proxy_object_new_ex(
96 zend_class_entry *ce, php_property_proxy_t *proxy);
97
98 PHP_PROPRO_API zend_object *php_property_proxy_object_new(zend_class_entry *ce);
99
100 /**
101 * Create a property proxy
102 *
103 * The property proxy will forward reads and writes to itself to the
104 * proxied property with name \a member_str of \a container.
105 *
106 * @param container the container holding the property
107 * @param member the name of the proxied property
108 * @return a new property proxy
109 */
110 PHP_PROPRO_API php_property_proxy_t *php_property_proxy_init(zval *container,
111 zend_string *member);
112
113 /**
114 * Destroy and free a property proxy.
115 *
116 * The destruction of the property proxy object calls this.
117 *
118 * @param proxy a pointer to the allocated property proxy
119 */
120 PHP_PROPRO_API void php_property_proxy_free(php_property_proxy_t **proxy);
121
122 /**
123 * Get the zend_class_entry of php\\PropertyProxy
124 * @return the class entry pointer
125 */
126 PHP_PROPRO_API zend_class_entry *php_property_proxy_get_class_entry(void);
127
128 #endif /* PHP_PROPRO_H */
129
130
131 /*
132 * Local variables:
133 * tab-width: 4
134 * c-basic-offset: 4
135 * End:
136 * vim600: noet sw=4 ts=4 fdm=marker
137 * vim<600: noet sw=4 ts=4
138 */