Merge branch 'v1.0.x'
[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 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, tmp);
50 *
51 * zval_ptr_dtor(return_value);
52 * ZVAL_COPY_VALUE(return_value, tmp);
53 * }
54 * } else {
55 * return_value = php_property_proxy_zval(object, member_name);
56 * }
57 *
58 * zend_string_release(member_name);
59 *
60 * return return_value;
61 * }
62 * \endcode
63 */
64 struct php_property_proxy_object {
65 /** The actual property proxy */
66 php_property_proxy_t *proxy;
67 /** Any parent property proxy object */
68 zval parent;
69 /** The std zend_object */
70 zend_object zo;
71 };
72 typedef struct php_property_proxy_object php_property_proxy_object_t;
73
74 /**
75 * Create a property proxy
76 *
77 * The property proxy will forward reads and writes to itself to the
78 * proxied property with name \a member_str of \a container.
79 *
80 * @param container the container holding the property
81 * @param member the name of the proxied property
82 * @return a new property proxy
83 */
84 PHP_PROPRO_API php_property_proxy_t *php_property_proxy_init(zval *container,
85 zend_string *member);
86
87 /**
88 * Destroy and free a property proxy.
89 *
90 * The destruction of the property proxy object calls this.
91 *
92 * @param proxy a pointer to the allocated property proxy
93 */
94 PHP_PROPRO_API void php_property_proxy_free(php_property_proxy_t **proxy);
95
96 /**
97 * Get the zend_class_entry of php\\PropertyProxy
98 * @return the class entry pointer
99 */
100 PHP_PROPRO_API zend_class_entry *php_property_proxy_get_class_entry(void);
101
102 /**
103 * Instantiate a new php\\PropertyProxy
104 * @param ce the property proxy or derived class entry
105 * @return the zend object
106 */
107 PHP_PROPRO_API zend_object *php_property_proxy_object_new(zend_class_entry *ce);
108
109 /**
110 * Instantiate a new php\\PropertyProxy with \a proxy
111 * @param ce the property proxy or derived class entry
112 * @param proxy the internal property proxy
113 * @return the property proxy
114 */
115 PHP_PROPRO_API php_property_proxy_object_t *php_property_proxy_object_new_ex(
116 zend_class_entry *ce, php_property_proxy_t *proxy);
117
118 #endif /* PHP_PROPRO_API_H */
119
120
121 /*
122 * Local variables:
123 * tab-width: 4
124 * c-basic-offset: 4
125 * End:
126 * vim600: noet sw=4 ts=4 fdm=marker
127 * vim<600: noet sw=4 ts=4
128 */