xref: /php-src/ext/dom/entity.c (revision 7e45e57d)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Christian Stocker <chregu@php.net>                          |
14    |          Rob Richards <rrichards@php.net>                            |
15    +----------------------------------------------------------------------+
16 */
17 
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21 
22 #include "php.h"
23 #if defined(HAVE_LIBXML) && defined(HAVE_DOM)
24 #include "php_dom.h"
25 #include "dom_properties.h"
26 
27 
28 /*
29 * class DOMEntity extends DOMNode
30 *
31 * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-527DCFF2
32 * Since:
33 */
34 
35 /* {{{ publicId	string
36 readonly=yes
37 URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D7303025
38 Since:
39 */
dom_entity_public_id_read(dom_object * obj,zval * retval)40 zend_result dom_entity_public_id_read(dom_object *obj, zval *retval)
41 {
42 	DOM_PROP_NODE(xmlEntityPtr, nodep, obj);
43 
44 	if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY || !nodep->ExternalID) {
45 		ZVAL_NULL(retval);
46 	} else {
47 		ZVAL_STRING(retval, (const char *) nodep->ExternalID);
48 	}
49 
50 	return SUCCESS;
51 }
52 
53 /* }}} */
54 
55 /* {{{ systemId	string
56 readonly=yes
57 URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D7C29F3E
58 Since:
59 */
dom_entity_system_id_read(dom_object * obj,zval * retval)60 zend_result dom_entity_system_id_read(dom_object *obj, zval *retval)
61 {
62 	DOM_PROP_NODE(xmlEntityPtr, nodep, obj);
63 
64 	if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
65 		ZVAL_NULL(retval);
66 	} else {
67 		ZVAL_STRING(retval, (const char *) nodep->SystemID);
68 	}
69 
70 	return SUCCESS;
71 }
72 
73 /* }}} */
74 
75 /* {{{ notationName	string
76 readonly=yes
77 URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6ABAEB38
78 Since:
79 */
dom_entity_notation_name_read(dom_object * obj,zval * retval)80 zend_result dom_entity_notation_name_read(dom_object *obj, zval *retval)
81 {
82 	DOM_PROP_NODE(xmlEntityPtr, nodep, obj);
83 
84 	if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
85 		ZVAL_NULL(retval);
86 	} else {
87 		/* According to spec, NULL is only allowed for unparsed entities, if it's not set we should use the empty string. */
88 		if (!nodep->content) {
89 			ZVAL_EMPTY_STRING(retval);
90 		} else {
91 			ZVAL_STRING(retval, (const char *) nodep->content);
92 		}
93 	}
94 
95 	return SUCCESS;
96 }
97 
98 /* }}} */
99 
100 /* {{{ actualEncoding	string
101 readonly=yes
102 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Entity3-actualEncoding
103 Since: DOM Level 3
104 */
dom_entity_actual_encoding_read(dom_object * obj,zval * retval)105 zend_result dom_entity_actual_encoding_read(dom_object *obj, zval *retval)
106 {
107 	PHP_DOM_DEPRECATED_PROPERTY("Property DOMEntity::$actualEncoding is deprecated");
108 
109 	ZVAL_NULL(retval);
110 	return SUCCESS;
111 }
112 
113 /* }}} */
114 
115 /* {{{ encoding	string
116 readonly=yes
117 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Entity3-encoding
118 Since: DOM Level 3
119 */
dom_entity_encoding_read(dom_object * obj,zval * retval)120 zend_result dom_entity_encoding_read(dom_object *obj, zval *retval)
121 {
122 	PHP_DOM_DEPRECATED_PROPERTY("Property DOMEntity::$encoding is deprecated");
123 
124 	ZVAL_NULL(retval);
125 	return SUCCESS;
126 }
127 
128 /* }}} */
129 
130 /* {{{ version	string
131 readonly=yes
132 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Entity3-version
133 Since: DOM Level 3
134 */
dom_entity_version_read(dom_object * obj,zval * retval)135 zend_result dom_entity_version_read(dom_object *obj, zval *retval)
136 {
137 	PHP_DOM_DEPRECATED_PROPERTY("Property DOMEntity::$version is deprecated");
138 
139 	ZVAL_NULL(retval);
140 	return SUCCESS;
141 }
142 
143 /* }}} */
144 
145 #endif
146