flush
[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 #if PHP_VERSION_ID >= 70000
36 # define PHPNG
37 #endif
38
39 #endif
40
41 /**
42 * The internal property proxy.
43 *
44 * Container for the object/array holding the proxied property.
45 */
46 struct php_property_proxy {
47 /** The container holding the property */
48 zval container;
49 /** The name of the proxied property */
50 zend_string *member;
51 };
52 typedef struct php_property_proxy php_property_proxy_t;
53
54 /**
55 * The userland object.
56 *
57 * Return an object instance of php\\PropertyProxy to make your C-struct
58 * member accessible by reference from PHP userland.
59 *
60 * Example:
61 * ~~~~~~~~~~{.c}
62 * static zval *my_read_prop(zval *object, zval *member, int type, zend_literal *key TSRMLS_DC)
63 * {
64 * my_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
65 * my_prophandler_t *handler;
66 * zval *return_value, *copy = my_cast(IS_STRING, member);
67 *
68 * if (SUCCESS == my_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
69 * ALLOC_ZVAL(return_value);
70 * Z_SET_REFCOUNT_P(return_value, 0);
71 * Z_UNSET_ISREF_P(return_value);
72 *
73 * if (type == BP_VAR_R) {
74 * handler->read(obj, return_value TSRMLS_CC);
75 * } else {
76 * //
77 * // This is the interesting part
78 * //
79 * php_property_proxy_t *proxy;
80 * zend_object_value proxy_ov;
81 * zend_class_entry *proxy_ce;
82 *
83 * proxy = php_property_proxy_init(object, Z_STRVAL_P(copy), Z_STRLEN_P(copy) TSRMLS_CC);
84 * proxy_ce = php_property_proxy_get_class_entry();
85 * proxy_ov = php_property_proxy_object_new_ex(proxy_ce, proxy, NULL TSRMLS_CC);
86 * RETVAL_OBJVAL(proxy_ov, 0);
87 * }
88 * } else {
89 * zend_object_handlers *oh = zend_get_std_object_handlers();
90 * return_value = oh->read_property(object, member, type, key TSRMLS_CC);
91 * }
92 *
93 * zval_ptr_dtor(&copy);
94 *
95 * return return_value;
96 * }
97 * ~~~~~~~~~~
98 */
99 struct php_property_proxy_object {
100 /** The std zend_object */
101 zend_object zo;
102 /** The actual property proxy */
103 php_property_proxy_t *proxy;
104 /** Any parent property proxy object */
105 zval parent;
106 };
107 typedef struct php_property_proxy_object php_property_proxy_object_t;
108
109 /**
110 * Create a property proxy
111 *
112 * The property proxy will forward reads and writes to itself to the
113 * proxied property with name \a member_str of \a container.
114 *
115 * @param container the container holding the property
116 * @param member the name of the proxied property
117 * @return a new property proxy
118 */
119 PHP_PROPRO_API php_property_proxy_t *php_property_proxy_init(zval *container,
120 zend_string *member TSRMLS_DC);
121
122 /**
123 * Destroy and free a property proxy.
124 *
125 * The destruction of the property proxy object calls this.
126 *
127 * @param proxy a pointer to the allocated property proxy
128 */
129 PHP_PROPRO_API void php_property_proxy_free(php_property_proxy_t **proxy);
130
131 /**
132 * Get the zend_class_entry of php\\PropertyProxy
133 * @return the class entry pointer
134 */
135 PHP_PROPRO_API zend_class_entry *php_property_proxy_get_class_entry(void);
136
137 #endif /* PHP_PROPRO_H */
138
139
140 /*
141 * Local variables:
142 * tab-width: 4
143 * c-basic-offset: 4
144 * End:
145 * vim600: noet sw=4 ts=4 fdm=marker
146 * vim<600: noet sw=4 ts=4
147 */