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 */
29 typedef struct php_property_proxy php_property_proxy_t
;
32 * The userland object.
34 * Return an object instance of php\\PropertyProxy to make your C-struct
35 * member accessible by reference from PHP userland.
39 * static zval *my_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
42 * zend_string *member_name = zval_get_string(member);
43 * my_prophandler_t *handler = my_get_prophandler(member_name);
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);
49 * handler->read(object, tmp);
51 * zval_ptr_dtor(return_value);
52 * ZVAL_COPY_VALUE(return_value, tmp);
55 * return_value = php_property_proxy_zval(object, member_name);
58 * zend_string_release(member_name);
60 * return return_value;
64 struct php_property_proxy_object
{
65 /** The actual property proxy */
66 php_property_proxy_t
*proxy
;
67 /** Any parent property proxy object */
69 /** The std zend_object */
72 typedef struct php_property_proxy_object php_property_proxy_object_t
;
75 * Create a property proxy
77 * The property proxy will forward reads and writes to itself to the
78 * proxied property with name \a member_str of \a container.
80 * @param container the container holding the property
81 * @param member the name of the proxied property
82 * @return a new property proxy
84 PHP_PROPRO_API php_property_proxy_t
*php_property_proxy_init(zval
*container
,
88 * Destroy and free a property proxy.
90 * The destruction of the property proxy object calls this.
92 * @param proxy a pointer to the allocated property proxy
94 PHP_PROPRO_API
void php_property_proxy_free(php_property_proxy_t
**proxy
);
97 * Get the zend_class_entry of php\\PropertyProxy
98 * @return the class entry pointer
100 PHP_PROPRO_API zend_class_entry
*php_property_proxy_get_class_entry(void);
103 * Instantiate a new php\\PropertyProxy
104 * @param ce the property proxy or derived class entry
105 * @return the zend object
107 PHP_PROPRO_API zend_object
*php_property_proxy_object_new(zend_class_entry
*ce
);
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
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
);
118 #endif /* PHP_PROPRO_API_H */
126 * vim600: noet sw=4 ts=4 fdm=marker
127 * vim<600: noet sw=4 ts=4