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 +--------------------------------------------------------------------+
13 #ifndef PHP_PROPRO_API_H
14 #define PHP_PROPRO_API_H
16 #include "php_propro.h"
19 * The internal property proxy.
21 * Container for the object/array holding the proxied property.
23 struct php_property_proxy
{
24 /** The container holding the property */
26 /** The name of the proxied property */
28 /** The length of the name */
31 typedef struct php_property_proxy php_property_proxy_t
;
34 * The userland object.
36 * Return an object instance of php\\PropertyProxy to make your C-struct
37 * member accessible by reference from PHP userland.
41 * static zval *my_read_prop(zval *object, zval *member, int type, zend_literal *key TSRMLS_DC)
43 * my_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
44 * my_prophandler_t *handler;
45 * zval *return_value, *copy = my_cast(IS_STRING, member);
47 * if (SUCCESS == my_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
48 * ALLOC_ZVAL(return_value);
49 * Z_SET_REFCOUNT_P(return_value, 0);
50 * Z_UNSET_ISREF_P(return_value);
52 * if (type == BP_VAR_R) {
53 * handler->read(obj, return_value TSRMLS_CC);
56 * // This is the interesting part
58 * php_property_proxy_t *proxy;
59 * zend_object_value proxy_ov;
60 * zend_class_entry *proxy_ce;
62 * proxy = php_property_proxy_init(object, Z_STRVAL_P(copy), Z_STRLEN_P(copy) TSRMLS_CC);
63 * proxy_ce = php_property_proxy_get_class_entry();
64 * proxy_ov = php_property_proxy_object_new_ex(proxy_ce, proxy, NULL TSRMLS_CC);
65 * RETVAL_OBJVAL(proxy_ov, 0);
68 * zend_object_handlers *oh = zend_get_std_object_handlers();
69 * return_value = oh->read_property(object, member, type, key TSRMLS_CC);
72 * zval_ptr_dtor(©);
74 * return return_value;
78 struct php_property_proxy_object
{
79 /** The std zend_object */
81 /** The object value for easy zval creation */
83 /** The actual property proxy */
84 php_property_proxy_t
*proxy
;
85 /** A reference to any parent property proxy object */
86 struct php_property_proxy_object
*parent
;
88 typedef struct php_property_proxy_object php_property_proxy_object_t
;
91 * Create a property proxy
93 * The property proxy will forward reads and writes to itself to the
94 * proxied property with name \a member_str of \a container.
96 * @param container the container holding the property
97 * @param member_str the name of the proxied property
98 * @param member_len the length of the name
99 * @return a new property proxy
101 PHP_PROPRO_API php_property_proxy_t
*php_property_proxy_init(zval
*container
,
102 const char *member_str
, size_t member_len TSRMLS_DC
);
105 * Destroy and free a property proxy.
107 * The destruction of the property proxy object calls this.
109 * @param proxy a pointer to the allocated property proxy
111 PHP_PROPRO_API
void php_property_proxy_free(php_property_proxy_t
**proxy
);
114 * Get the zend_class_entry of php\\PropertyProxy
115 * @return the class entry pointer
117 PHP_PROPRO_API zend_class_entry
*php_property_proxy_get_class_entry(void);
120 * Instantiate a new php\\PropertyProxy
121 * @param ce the property proxy or derived class entry
122 * @return the zval object value
124 PHP_PROPRO_API zend_object_value
php_property_proxy_object_new(
125 zend_class_entry
*ce TSRMLS_DC
);
128 * Instantiate a new php\\PropertyProxy with \a proxy
129 * @param ce the property proxy or derived class entry
130 * @param proxy the internal property proxy
131 * @param ptr a pointer to store the resulting property proxy object
132 * @return the zval object value
134 PHP_PROPRO_API zend_object_value
php_property_proxy_object_new_ex(
135 zend_class_entry
*ce
, php_property_proxy_t
*proxy
,
136 php_property_proxy_object_t
**ptr TSRMLS_DC
);
138 #endif /* PHP_PROPRO_API_H */
146 * vim600: noet sw=4 ts=4 fdm=marker
147 * vim<600: noet sw=4 ts=4