This source file includes following definitions.
- PHP_METHOD
- dom_processinginstruction_target_read
- dom_processinginstruction_data_read
- dom_processinginstruction_data_write
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "php.h"
27 #if HAVE_LIBXML && HAVE_DOM
28 #include "php_dom.h"
29
30
31
32 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_processinginstruction_construct, 0, 0, 1)
33 ZEND_ARG_INFO(0, name)
34 ZEND_ARG_INFO(0, value)
35 ZEND_END_ARG_INFO();
36
37
38
39
40
41
42
43
44
45 const zend_function_entry php_dom_processinginstruction_class_functions[] = {
46 PHP_ME(domprocessinginstruction, __construct, arginfo_dom_processinginstruction_construct, ZEND_ACC_PUBLIC)
47 PHP_FE_END
48 };
49
50
51 PHP_METHOD(domprocessinginstruction, __construct)
52 {
53
54 zval *id;
55 xmlNodePtr nodep = NULL, oldnode = NULL;
56 dom_object *intern;
57 char *name, *value = NULL;
58 int name_len, value_len, name_valid;
59 zend_error_handling error_handling;
60
61 zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
62 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &id, dom_processinginstruction_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
63 zend_restore_error_handling(&error_handling TSRMLS_CC);
64 return;
65 }
66
67 zend_restore_error_handling(&error_handling TSRMLS_CC);
68
69 name_valid = xmlValidateName((xmlChar *) name, 0);
70 if (name_valid != 0) {
71 php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
72 RETURN_FALSE;
73 }
74
75 nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
76
77 if (!nodep) {
78 php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
79 RETURN_FALSE;
80 }
81
82 intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
83 if (intern != NULL) {
84 oldnode = dom_object_get_node(intern);
85 if (oldnode != NULL) {
86 php_libxml_node_free_resource(oldnode TSRMLS_CC);
87 }
88 php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern TSRMLS_CC);
89 }
90 }
91
92
93
94
95
96
97
98 int dom_processinginstruction_target_read(dom_object *obj, zval **retval TSRMLS_DC)
99 {
100 xmlNodePtr nodep;
101
102 nodep = dom_object_get_node(obj);
103
104 if (nodep == NULL) {
105 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
106 return FAILURE;
107 }
108
109 ALLOC_ZVAL(*retval);
110 ZVAL_STRING(*retval, (char *) (nodep->name), 1);
111
112 return SUCCESS;
113 }
114
115
116
117
118
119
120
121
122 int dom_processinginstruction_data_read(dom_object *obj, zval **retval TSRMLS_DC)
123 {
124 xmlNodePtr nodep;
125 xmlChar *content;
126
127 nodep = dom_object_get_node(obj);
128
129 if (nodep == NULL) {
130 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
131 return FAILURE;
132 }
133
134 ALLOC_ZVAL(*retval);
135
136
137 if ((content = xmlNodeGetContent(nodep)) != NULL) {
138 ZVAL_STRING(*retval, content, 1);
139 xmlFree(content);
140 } else {
141 ZVAL_EMPTY_STRING(*retval);
142 }
143
144 return SUCCESS;
145 }
146
147 int dom_processinginstruction_data_write(dom_object *obj, zval *newval TSRMLS_DC)
148 {
149 zval value_copy;
150 xmlNode *nodep;
151
152 nodep = dom_object_get_node(obj);
153
154 if (nodep == NULL) {
155 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
156 return FAILURE;
157 }
158
159 if (newval->type != IS_STRING) {
160 if(Z_REFCOUNT_P(newval) > 1) {
161 value_copy = *newval;
162 zval_copy_ctor(&value_copy);
163 newval = &value_copy;
164 }
165 convert_to_string(newval);
166 }
167
168 xmlNodeSetContentLen(nodep, Z_STRVAL_P(newval), Z_STRLEN_P(newval) + 1);
169
170 if (newval == &value_copy) {
171 zval_dtor(newval);
172 }
173
174 return SUCCESS;
175 }
176
177
178
179 #endif
180
181
182
183
184
185
186
187
188