25
25
#include "namespace_compat.h"
26
26
#include "xml_serializer.h"
27
27
#include "internal_helpers.h"
28
+ #include "dom_properties.h"
28
29
#include <libxml/SAX.h>
29
30
#ifdef LIBXML_SCHEMAS_ENABLED
30
31
#include <libxml/relaxng.h>
@@ -45,15 +46,9 @@ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-
45
46
*/
46
47
zend_result dom_document_doctype_read (dom_object * obj , zval * retval )
47
48
{
48
- xmlDoc * docp = (xmlDocPtr ) dom_object_get_node (obj );
49
- xmlDtdPtr dtdptr ;
49
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
50
50
51
- if (docp == NULL ) {
52
- php_dom_throw_error (INVALID_STATE_ERR , true);
53
- return FAILURE ;
54
- }
55
-
56
- dtdptr = xmlGetIntSubset (docp );
51
+ xmlDtdPtr dtdptr = xmlGetIntSubset (docp );
57
52
if (!dtdptr ) {
58
53
ZVAL_NULL (retval );
59
54
return SUCCESS ;
@@ -84,15 +79,9 @@ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-
84
79
*/
85
80
zend_result dom_document_document_element_read (dom_object * obj , zval * retval )
86
81
{
87
- xmlDoc * docp = (xmlDocPtr ) dom_object_get_node (obj );
88
- xmlNode * root ;
82
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
89
83
90
- if (docp == NULL ) {
91
- php_dom_throw_error (INVALID_STATE_ERR , true);
92
- return FAILURE ;
93
- }
94
-
95
- root = xmlDocGetRootElement (docp );
84
+ xmlNodePtr root = xmlDocGetRootElement (docp );
96
85
if (!root ) {
97
86
ZVAL_NULL (retval );
98
87
return SUCCESS ;
@@ -110,15 +99,9 @@ Since: DOM Level 3
110
99
*/
111
100
zend_result dom_document_encoding_read (dom_object * obj , zval * retval )
112
101
{
113
- xmlDoc * docp = (xmlDocPtr ) dom_object_get_node (obj );
114
- char * encoding ;
115
-
116
- if (docp == NULL ) {
117
- php_dom_throw_error (INVALID_STATE_ERR , true);
118
- return FAILURE ;
119
- }
102
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
120
103
121
- encoding = (char * ) docp -> encoding ;
104
+ const char * encoding = (const char * ) docp -> encoding ;
122
105
123
106
if (encoding != NULL ) {
124
107
ZVAL_STRING (retval , encoding );
@@ -131,13 +114,7 @@ zend_result dom_document_encoding_read(dom_object *obj, zval *retval)
131
114
132
115
zend_result dom_document_encoding_write (dom_object * obj , zval * newval )
133
116
{
134
- xmlDoc * docp = (xmlDocPtr ) dom_object_get_node (obj );
135
- xmlCharEncodingHandlerPtr handler ;
136
-
137
- if (docp == NULL ) {
138
- php_dom_throw_error (INVALID_STATE_ERR , true);
139
- return FAILURE ;
140
- }
117
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
141
118
142
119
/* Typed property, can only be IS_STRING or IS_NULL. */
143
120
ZEND_ASSERT (Z_TYPE_P (newval ) == IS_STRING || Z_TYPE_P (newval ) == IS_NULL );
@@ -146,9 +123,9 @@ zend_result dom_document_encoding_write(dom_object *obj, zval *newval)
146
123
goto invalid_encoding ;
147
124
}
148
125
149
- zend_string * str = Z_STR_P (newval );
126
+ const zend_string * str = Z_STR_P (newval );
150
127
151
- handler = xmlFindCharEncodingHandler (ZSTR_VAL (str ));
128
+ xmlCharEncodingHandlerPtr handler = xmlFindCharEncodingHandler (ZSTR_VAL (str ));
152
129
153
130
if (handler != NULL ) {
154
131
xmlCharEncCloseFunc (handler );
@@ -176,30 +153,16 @@ Since: DOM Level 3
176
153
*/
177
154
zend_result dom_document_standalone_read (dom_object * obj , zval * retval )
178
155
{
179
- xmlDoc * docp ;
180
-
181
- docp = (xmlDocPtr ) dom_object_get_node (obj );
182
-
183
- if (docp == NULL ) {
184
- php_dom_throw_error (INVALID_STATE_ERR , true);
185
- return FAILURE ;
186
- }
187
-
156
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
188
157
ZVAL_BOOL (retval , docp -> standalone > 0 );
189
158
return SUCCESS ;
190
159
}
191
160
192
161
zend_result dom_document_standalone_write (dom_object * obj , zval * newval )
193
162
{
194
- xmlDoc * docp = (xmlDocPtr ) dom_object_get_node (obj );
195
- zend_long standalone ;
196
-
197
- if (docp == NULL ) {
198
- php_dom_throw_error (INVALID_STATE_ERR , true);
199
- return FAILURE ;
200
- }
163
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
201
164
202
- standalone = zval_get_long (newval );
165
+ zend_long standalone = zval_get_long (newval );
203
166
docp -> standalone = ZEND_NORMALIZE_BOOL (standalone );
204
167
205
168
return SUCCESS ;
@@ -214,15 +177,9 @@ Since: DOM Level 3
214
177
*/
215
178
zend_result dom_document_version_read (dom_object * obj , zval * retval )
216
179
{
217
- xmlDoc * docp = (xmlDocPtr ) dom_object_get_node (obj );
218
- char * version ;
180
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
219
181
220
- if (docp == NULL ) {
221
- php_dom_throw_error (INVALID_STATE_ERR , true);
222
- return FAILURE ;
223
- }
224
-
225
- version = (char * ) docp -> version ;
182
+ const char * version = (const char * ) docp -> version ;
226
183
227
184
if (version != NULL ) {
228
185
ZVAL_STRING (retval , version );
@@ -235,15 +192,9 @@ zend_result dom_document_version_read(dom_object *obj, zval *retval)
235
192
236
193
zend_result dom_document_version_write (dom_object * obj , zval * newval )
237
194
{
238
- xmlDoc * docp = (xmlDocPtr ) dom_object_get_node (obj );
239
- zend_string * str ;
240
-
241
- if (docp == NULL ) {
242
- php_dom_throw_error (INVALID_STATE_ERR , true);
243
- return FAILURE ;
244
- }
195
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
245
196
246
- str = zval_try_get_string (newval );
197
+ zend_string * str = zval_try_get_string (newval );
247
198
if (UNEXPECTED (!str )) {
248
199
return FAILURE ;
249
200
}
@@ -425,15 +376,9 @@ Since: DOM Level 3
425
376
*/
426
377
zend_result dom_document_document_uri_read (dom_object * obj , zval * retval )
427
378
{
428
- xmlDoc * docp = (xmlDocPtr ) dom_object_get_node (obj );
429
- char * url ;
379
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
430
380
431
- if (docp == NULL ) {
432
- php_dom_throw_error (INVALID_STATE_ERR , true);
433
- return FAILURE ;
434
- }
435
-
436
- url = (char * ) docp -> URL ;
381
+ const char * url = (const char * ) docp -> URL ;
437
382
if (url != NULL ) {
438
383
ZVAL_STRING (retval , url );
439
384
} else {
@@ -449,15 +394,9 @@ zend_result dom_document_document_uri_read(dom_object *obj, zval *retval)
449
394
450
395
zend_result dom_document_document_uri_write (dom_object * obj , zval * newval )
451
396
{
452
- xmlDoc * docp = (xmlDocPtr ) dom_object_get_node (obj );
453
- zend_string * str ;
454
-
455
- if (docp == NULL ) {
456
- php_dom_throw_error (INVALID_STATE_ERR , true);
457
- return FAILURE ;
458
- }
397
+ DOM_PROP_NODE (xmlDocPtr , docp , obj );
459
398
460
- str = zval_try_get_string (newval );
399
+ zend_string * str = zval_try_get_string (newval );
461
400
if (UNEXPECTED (!str )) {
462
401
return FAILURE ;
463
402
}
0 commit comments