@@ -3,10 +3,11 @@ use crate::{
3
3
sys:: {
4
4
self , phper_get_this, phper_init_class_entry_ex, phper_z_strval_p, phper_zval_get_type,
5
5
phper_zval_stringl, zend_class_entry, zend_declare_property_bool,
6
- zend_declare_property_null, zend_declare_property_stringl, zend_execute_data, zend_long,
7
- zend_parse_parameters, zend_read_property, zend_register_internal_class,
8
- zend_throw_exception, zval, IS_DOUBLE , IS_FALSE , IS_LONG , IS_NULL , IS_TRUE ,
9
- ZEND_RESULT_CODE_SUCCESS ,
6
+ zend_declare_property_long, zend_declare_property_null, zend_declare_property_stringl,
7
+ zend_execute_data, zend_long, zend_parse_parameters, zend_read_property,
8
+ zend_register_internal_class, zend_throw_exception, zend_update_property_bool,
9
+ zend_update_property_long, zend_update_property_null, zend_update_property_stringl, zval,
10
+ IS_DOUBLE , IS_FALSE , IS_LONG , IS_NULL , IS_TRUE , ZEND_RESULT_CODE_SUCCESS ,
10
11
} ,
11
12
zend:: { api:: FunctionEntries , compile:: Visibility , exceptions:: Throwable } ,
12
13
} ;
@@ -57,16 +58,24 @@ impl ClassEntry {
57
58
pub fn declare_property (
58
59
& self ,
59
60
name : impl AsRef < str > ,
60
- value : impl DeclareProperty ,
61
+ value : impl HandleProperty ,
61
62
access_type : Visibility ,
62
63
) -> bool {
63
64
unsafe {
64
- let name = name. as_ref ( ) ;
65
- value. declare_property ( self . get ( ) , name, access_type as c_int )
65
+ value. declare_property ( self . get ( ) , name. as_ref ( ) , access_type as c_int )
66
66
== ZEND_RESULT_CODE_SUCCESS
67
67
}
68
68
}
69
69
70
+ pub fn update_property (
71
+ & self ,
72
+ object : * mut zval ,
73
+ name : impl AsRef < str > ,
74
+ value : impl HandleProperty ,
75
+ ) {
76
+ unsafe { value. update_property ( self . get ( ) , object, name. as_ref ( ) ) }
77
+ }
78
+
70
79
pub fn read_property ( & self , this : * mut zval , name : impl AsRef < str > ) -> & mut Val {
71
80
let name = name. as_ref ( ) ;
72
81
unsafe {
@@ -85,16 +94,18 @@ impl ClassEntry {
85
94
86
95
unsafe impl Sync for ClassEntry { }
87
96
88
- pub trait DeclareProperty {
97
+ pub trait HandleProperty {
89
98
unsafe fn declare_property (
90
99
self ,
91
100
ce : * mut zend_class_entry ,
92
101
name : & str ,
93
102
access_type : c_int ,
94
103
) -> c_int ;
104
+
105
+ unsafe fn update_property ( self , scope : * mut zend_class_entry , object : * mut zval , name : & str ) ;
95
106
}
96
107
97
- impl DeclareProperty for ( ) {
108
+ impl HandleProperty for ( ) {
98
109
unsafe fn declare_property (
99
110
self ,
100
111
ce : * mut zend_class_entry ,
@@ -103,9 +114,13 @@ impl DeclareProperty for () {
103
114
) -> i32 {
104
115
zend_declare_property_null ( ce, name. as_ptr ( ) . cast ( ) , name. len ( ) , access_type)
105
116
}
117
+
118
+ unsafe fn update_property ( self , scope : * mut zend_class_entry , object : * mut zval , name : & str ) {
119
+ zend_update_property_null ( scope, object, name. as_ptr ( ) . cast ( ) , name. len ( ) )
120
+ }
106
121
}
107
122
108
- impl DeclareProperty for bool {
123
+ impl HandleProperty for bool {
109
124
unsafe fn declare_property (
110
125
self ,
111
126
ce : * mut zend_class_entry ,
@@ -120,9 +135,46 @@ impl DeclareProperty for bool {
120
135
access_type,
121
136
)
122
137
}
138
+
139
+ unsafe fn update_property ( self , scope : * mut zend_class_entry , object : * mut zval , name : & str ) {
140
+ zend_update_property_bool (
141
+ scope,
142
+ object,
143
+ name. as_ptr ( ) . cast ( ) ,
144
+ name. len ( ) ,
145
+ self as zend_long ,
146
+ )
147
+ }
148
+ }
149
+
150
+ impl HandleProperty for i64 {
151
+ unsafe fn declare_property (
152
+ self ,
153
+ ce : * mut zend_class_entry ,
154
+ name : & str ,
155
+ access_type : i32 ,
156
+ ) -> i32 {
157
+ zend_declare_property_long (
158
+ ce,
159
+ name. as_ptr ( ) . cast ( ) ,
160
+ name. len ( ) ,
161
+ self as zend_long ,
162
+ access_type,
163
+ )
164
+ }
165
+
166
+ unsafe fn update_property ( self , scope : * mut zend_class_entry , object : * mut zval , name : & str ) {
167
+ zend_update_property_long (
168
+ scope,
169
+ object,
170
+ name. as_ptr ( ) . cast ( ) ,
171
+ name. len ( ) ,
172
+ self as zend_long ,
173
+ )
174
+ }
123
175
}
124
176
125
- impl DeclareProperty for & str {
177
+ impl HandleProperty for & str {
126
178
unsafe fn declare_property (
127
179
self ,
128
180
ce : * mut zend_class_entry ,
@@ -138,6 +190,17 @@ impl DeclareProperty for &str {
138
190
access_type,
139
191
)
140
192
}
193
+
194
+ unsafe fn update_property ( self , scope : * mut zend_class_entry , object : * mut zval , name : & str ) {
195
+ zend_update_property_stringl (
196
+ scope,
197
+ object,
198
+ name. as_ptr ( ) . cast ( ) ,
199
+ name. len ( ) ,
200
+ self . as_ptr ( ) . cast ( ) ,
201
+ self . len ( ) ,
202
+ )
203
+ }
141
204
}
142
205
143
206
#[ repr( transparent) ]
0 commit comments