update example
[m6w6/ext-propro] / src / php_propro_api.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_API_H
14 #define PHP_PROPRO_API_H
15
16 #include "php_propro.h"
17
18 /**
19 * The internal property proxy.
20 *
21 * Container for the object/array holding the proxied property.
22 */
23 struct php_property_proxy {
24 /** The reference to the container holding the property */
25 zval container;
26 /** The name of the proxied property */
27 zend_string *member;
28 };
29 typedef struct php_property_proxy php_property_proxy_t;
30
31 /**
32 * The userland object.
33 *
34 * Return an object instance of php\\PropertyProxy to make your C-struct
35 * member accessible by reference from PHP userland.
36 *
37 * Example:
38 * \code{.c}
39 * static zval *my_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
40 * {
41 * zval *return_value;
42 * zend_string *member_name = zval_get_string(member);
43 * my_prophandler_t *handler = my_get_prophandler(member_name);
44 *
45 * if (!handler || type == BP_VAR_R || type == BP_VAR_IS) {
46 * return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
47 *
48 * if (handler) {
49 * handler->read(object, return_value);
50 * }
51 * } else {
52 * php_property_proxy_t *proxy;
53 * php_property_proxy_object_t *proxy_obj;
54 *
55 * proxy = php_property_proxy_init(object, member_name);
56 * proxy_obj = php_property_proxy_object_new_ex(NULL, proxy);
57 *
58 * ZVAL_OBJ(tmp, &proxy_obj->zo);
59 * return_value = tmp;
60 * }
61 *
62 * zend_string_release(member_name);
63 *
64 * return return_value;
65 * }
66 * \endcode
67 */
68 struct php_property_proxy_object {
69 /** The actual property proxy */
70 php_property_proxy_t *proxy;
71 /** Any parent property proxy object */
72 zval parent;
73 /** The std zend_object */
74 zend_object zo;
75 };
76 typedef struct php_property_proxy_object php_property_proxy_object_t;
77
78 /**
79 * Create a property proxy
80 *
81 * The property proxy will forward reads and writes to itself to the
82 * proxied property with name \a member_str of \a container.
83 *
84 * @param container the container holding the property
85 * @param member the name of the proxied property
86 * @return a new property proxy
87 */
88 PHP_PROPRO_API php_property_proxy_t *php_property_proxy_init(zval *container,
89 zend_string *member);
90
91 /**
92 * Destroy and free a property proxy.
93 *
94 * The destruction of the property proxy object calls this.
95 *
96 * @param proxy a pointer to the allocated property proxy
97 */
98 PHP_PROPRO_API void php_property_proxy_free(php_property_proxy_t **proxy);
99
100 /**
101 * Get the zend_class_entry of php\\PropertyProxy
102 * @return the class entry pointer
103 */
104 PHP_PROPRO_API zend_class_entry *php_property_proxy_get_class_entry(void);
105
106 /**
107 * Instantiate a new php\\PropertyProxy
108 * @param ce the property proxy or derived class entry
109 * @return the zend object
110 */
111 PHP_PROPRO_API zend_object *php_property_proxy_object_new(zend_class_entry *ce);
112
113 /**
114 * Instantiate a new php\\PropertyProxy with \a proxy
115 * @param ce the property proxy or derived class entry
116 * @param proxy the internal property proxy
117 * @return the property proxy
118 */
119 PHP_PROPRO_API php_property_proxy_object_t *php_property_proxy_object_new_ex(
120 zend_class_entry *ce, php_property_proxy_t *proxy);
121
122 #endif /* PHP_PROPRO_API_H */
123
124
125 /*
126 * Local variables:
127 * tab-width: 4
128 * c-basic-offset: 4
129 * End:
130 * vim600: noet sw=4 ts=4 fdm=marker
131 * vim<600: noet sw=4 ts=4
132 */