@@ -994,34 +994,17 @@ PHP_METHOD(Dom_HTMLDocument, createFromString)
994
994
RETURN_THROWS ();
995
995
}
996
996
997
- PHP_METHOD (Dom_HTMLDocument , createFromFile )
997
+ static void dom_html_document_create_from_stream (
998
+ zval * return_value ,
999
+ php_stream * stream ,
1000
+ zend_long options ,
1001
+ const char * override_encoding ,
1002
+ size_t override_encoding_len ,
1003
+ zend_string * opened_path ,
1004
+ const char * filename
1005
+ )
998
1006
{
999
- const char * filename , * override_encoding = NULL ;
1000
1007
php_dom_private_data * private_data = NULL ;
1001
- size_t filename_len , override_encoding_len ;
1002
- zend_long options = 0 ;
1003
- php_stream * stream = NULL ;
1004
- if (zend_parse_parameters (
1005
- ZEND_NUM_ARGS (),
1006
- "p|lp!" ,
1007
- & filename ,
1008
- & filename_len ,
1009
- & options ,
1010
- & override_encoding ,
1011
- & override_encoding_len
1012
- ) == FAILURE ) {
1013
- RETURN_THROWS ();
1014
- }
1015
-
1016
- /* See php_libxml_streams_IO_open_wrapper(), apparently this caused issues in the past. */
1017
- if (strstr (filename , "%00" )) {
1018
- zend_argument_value_error (1 , "must not contain percent-encoded NUL bytes" );
1019
- RETURN_THROWS ();
1020
- }
1021
-
1022
- if (!check_options_validity (2 , options )) {
1023
- RETURN_THROWS ();
1024
- }
1025
1008
1026
1009
dom_lexbor_libxml2_bridge_application_data application_data ;
1027
1010
application_data .input_name = filename ;
@@ -1058,15 +1041,6 @@ PHP_METHOD(Dom_HTMLDocument, createFromFile)
1058
1041
dom_setup_parser_encoding_manually ((const lxb_char_t * ) buf , encoding_data , & decoding_encoding_ctx , & application_data );
1059
1042
}
1060
1043
1061
- zend_string * opened_path = NULL ;
1062
- stream = php_stream_open_wrapper_ex (filename , "rb" , REPORT_ERRORS , & opened_path , php_libxml_get_stream_context ());
1063
- if (!stream ) {
1064
- if (!EG (exception )) {
1065
- zend_throw_exception_ex (NULL , 0 , "Cannot open file '%s'" , filename );
1066
- }
1067
- RETURN_THROWS ();
1068
- }
1069
-
1070
1044
/* MIME sniff */
1071
1045
if (should_determine_encoding_implicitly ) {
1072
1046
zend_string * charset = php_libxml_sniff_charset_from_stream (stream );
@@ -1192,12 +1166,6 @@ PHP_METHOD(Dom_HTMLDocument, createFromFile)
1192
1166
lxml_doc -> URL = xmlStrdup ((const xmlChar * ) filename );
1193
1167
}
1194
1168
1195
- if (opened_path != NULL ) {
1196
- zend_string_release_ex (opened_path , false);
1197
- }
1198
- php_stream_close (stream );
1199
- stream = NULL ;
1200
-
1201
1169
dom_object * intern = php_dom_instantiate_object_helper (
1202
1170
return_value ,
1203
1171
dom_html_document_class_entry ,
@@ -1216,10 +1184,52 @@ PHP_METHOD(Dom_HTMLDocument, createFromFile)
1216
1184
php_dom_private_data_destroy (private_data );
1217
1185
}
1218
1186
lxb_html_document_destroy (document );
1219
- php_stream_close (stream );
1187
+ }
1188
+
1189
+ PHP_METHOD (Dom_HTMLDocument , createFromFile )
1190
+ {
1191
+ const char * filename , * override_encoding = NULL ;
1192
+ size_t filename_len , override_encoding_len ;
1193
+ zend_long options = 0 ;
1194
+ if (zend_parse_parameters (
1195
+ ZEND_NUM_ARGS (),
1196
+ "p|lp!" ,
1197
+ & filename ,
1198
+ & filename_len ,
1199
+ & options ,
1200
+ & override_encoding ,
1201
+ & override_encoding_len
1202
+ ) == FAILURE ) {
1203
+ RETURN_THROWS ();
1204
+ }
1205
+
1206
+ /* See php_libxml_streams_IO_open_wrapper(), apparently this caused issues in the past. */
1207
+ if (strstr (filename , "%00" )) {
1208
+ zend_argument_value_error (1 , "must not contain percent-encoded NUL bytes" );
1209
+ RETURN_THROWS ();
1210
+ }
1211
+
1212
+ if (!check_options_validity (2 , options )) {
1213
+ RETURN_THROWS ();
1214
+ }
1215
+
1216
+ zend_string * opened_path = NULL ;
1217
+ php_stream * stream = php_stream_open_wrapper_ex (filename , "rb" , REPORT_ERRORS , & opened_path , php_libxml_get_stream_context ());
1218
+ if (!stream ) {
1219
+ if (!EG (exception )) {
1220
+ zend_throw_exception_ex (NULL , 0 , "Cannot open file '%s'" , filename );
1221
+ }
1222
+ RETURN_THROWS ();
1223
+ }
1224
+
1225
+ dom_html_document_create_from_stream (
1226
+ return_value , stream , options , override_encoding , override_encoding_len , opened_path , filename
1227
+ );
1228
+
1220
1229
if (opened_path != NULL ) {
1221
1230
zend_string_release_ex (opened_path , false);
1222
1231
}
1232
+ php_stream_close (stream );
1223
1233
}
1224
1234
1225
1235
static zend_result dom_write_output_smart_str (void * ctx , const char * buf , size_t size )
0 commit comments