2 +--------------------------------------------------------------------+
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 +--------------------------------------------------------------------+
18 extern zend_module_entry propro_module_entry
;
19 #define phpext_propro_ptr &propro_module_entry
21 #define PHP_PROPRO_VERSION "2.0.0dev"
24 # define PHP_PROPRO_API __declspec(dllexport)
25 #elif defined(__GNUC__) && __GNUC__ >= 4
26 # define PHP_PROPRO_API extern __attribute__ ((visibility("default")))
28 # define PHP_PROPRO_API extern
32 # include <TSRM/TSRM.h>
38 * The internal property proxy.
40 * Container for the object/array holding the proxied property.
42 struct php_property_proxy
{
43 /** The container holding the property */
45 /** The name of the proxied property */
48 typedef struct php_property_proxy php_property_proxy_t
;
51 * The userland object.
53 * Return an object instance of php\\PropertyProxy to make your C-struct
54 * member accessible by reference from PHP userland.
58 * static zval *my_read_prop(zval *object, zval *member, int type, zend_literal *key TSRMLS_DC)
60 * my_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
61 * my_prophandler_t *handler;
62 * zval *return_value, *copy = my_cast(IS_STRING, member);
64 * if (SUCCESS == my_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
65 * ALLOC_ZVAL(return_value);
66 * Z_SET_REFCOUNT_P(return_value, 0);
67 * Z_UNSET_ISREF_P(return_value);
69 * if (type == BP_VAR_R) {
70 * handler->read(obj, return_value TSRMLS_CC);
73 * // This is the interesting part
75 * php_property_proxy_t *proxy;
76 * zend_object_value proxy_ov;
77 * zend_class_entry *proxy_ce;
79 * proxy = php_property_proxy_init(object, Z_STRVAL_P(copy), Z_STRLEN_P(copy) TSRMLS_CC);
80 * proxy_ce = php_property_proxy_get_class_entry();
81 * proxy_ov = php_property_proxy_object_new_ex(proxy_ce, proxy, NULL TSRMLS_CC);
82 * RETVAL_OBJVAL(proxy_ov, 0);
85 * zend_object_handlers *oh = zend_get_std_object_handlers();
86 * return_value = oh->read_property(object, member, type, key TSRMLS_CC);
89 * zval_ptr_dtor(©);
91 * return return_value;
95 struct php_property_proxy_object
{
96 /** The std zend_object */
98 /** The actual property proxy */
99 php_property_proxy_t
*proxy
;
100 /** Any parent property proxy object */
103 typedef struct php_property_proxy_object php_property_proxy_object_t
;
106 * Create a property proxy
108 * The property proxy will forward reads and writes to itself to the
109 * proxied property with name \a member_str of \a container.
111 * @param container the container holding the property
112 * @param member the name of the proxied property
113 * @return a new property proxy
115 PHP_PROPRO_API php_property_proxy_t
*php_property_proxy_init(zval
*container
,
116 zend_string
*member TSRMLS_DC
);
119 * Destroy and free a property proxy.
121 * The destruction of the property proxy object calls this.
123 * @param proxy a pointer to the allocated property proxy
125 PHP_PROPRO_API
void php_property_proxy_free(php_property_proxy_t
**proxy
);
128 * Get the zend_class_entry of php\\PropertyProxy
129 * @return the class entry pointer
131 PHP_PROPRO_API zend_class_entry
*php_property_proxy_get_class_entry(void);
133 #endif /* PHP_PROPRO_H */
141 * vim600: noet sw=4 ts=4 fdm=marker
142 * vim<600: noet sw=4 ts=4