21
21
#include "php.h"
22
22
#include "Zend/zend_interfaces.h"
23
23
#include "Zend/zend_exceptions.h"
24
+ #include "Zend/zend_enum.h"
24
25
#include "main/php_ini.h"
25
26
26
27
#include "php_uri.h"
@@ -38,6 +39,7 @@ zend_class_entry *uri_exception_ce;
38
39
zend_class_entry * uninitialized_uri_exception_ce ;
39
40
zend_class_entry * uri_operation_exception_ce ;
40
41
zend_class_entry * invalid_uri_exception_ce ;
42
+ zend_class_entry * whatwg_error_type_ce ;
41
43
zend_class_entry * whatwg_error_ce ;
42
44
43
45
static zend_array uri_handlers ;
@@ -181,25 +183,23 @@ PHPAPI void php_uri_free(uri_internal_t *internal_uri)
181
183
efree (internal_uri );
182
184
}
183
185
184
- PHP_METHOD (Uri_WhatWgError , __construct )
186
+ PHP_METHOD (Uri_WhatWg_WhatWgError , __construct )
185
187
{
186
- zend_string * uri , * position ;
187
- zend_long error ;
188
+ zend_string * context ;
189
+ zval * type ;
188
190
189
- ZEND_PARSE_PARAMETERS_START (3 , 3 )
190
- Z_PARAM_STR (uri )
191
- Z_PARAM_STR (position )
192
- Z_PARAM_LONG (error )
191
+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
192
+ Z_PARAM_STR (context )
193
+ Z_PARAM_OBJECT_OF_CLASS (type , whatwg_error_type_ce )
193
194
ZEND_PARSE_PARAMETERS_END ();
194
195
195
- zend_update_property_str (whatwg_error_ce , Z_OBJ_P (ZEND_THIS ), "uri ", sizeof(" uri ") - 1, uri);
196
- zend_update_property_str (whatwg_error_ce , Z_OBJ_P (ZEND_THIS ), "position" , sizeof ("position" ) - 1 , position );
197
- zend_update_property_long (whatwg_error_ce , Z_OBJ_P (ZEND_THIS ), "error" , sizeof ("error" ) - 1 , error );
196
+ zend_update_property_str (whatwg_error_ce , Z_OBJ_P (ZEND_THIS ), "context" , sizeof ("context" ) - 1 , context );
197
+ zend_update_property (whatwg_error_ce , Z_OBJ_P (ZEND_THIS ), "type" , sizeof ("type" ) - 1 , type );
198
198
}
199
199
200
200
PHPAPI void php_uri_instantiate_uri (
201
201
INTERNAL_FUNCTION_PARAMETERS , const uri_handler_t * handler , const zend_string * uri_str , const zend_string * base_url_str ,
202
- bool is_constructor , bool return_errors
202
+ bool is_constructor , zval * errors_zv
203
203
) {
204
204
zval errors ;
205
205
ZVAL_UNDEF (& errors );
@@ -211,8 +211,16 @@ PHPAPI void php_uri_instantiate_uri(
211
211
zval_ptr_dtor (& errors );
212
212
RETURN_THROWS ();
213
213
} else {
214
- if (return_errors && Z_TYPE (errors ) == IS_ARRAY ) {
215
- RETURN_ZVAL (& errors , false, false);
214
+ if (errors_zv != NULL && Z_TYPE (errors ) == IS_ARRAY ) {
215
+ errors_zv = zend_try_array_init (errors_zv );
216
+ if (!errors_zv ) {
217
+ RETURN_THROWS ();
218
+ }
219
+
220
+ zval * error ;
221
+ ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P (errors_zv ), error ) {
222
+ zend_hash_next_index_insert (Z_ARRVAL_P (errors_zv ), error );
223
+ } ZEND_HASH_FOREACH_END ();
216
224
}
217
225
218
226
zval_ptr_dtor (& errors );
@@ -235,11 +243,13 @@ PHPAPI void php_uri_instantiate_uri(
235
243
static void create_rfc3986_uri (INTERNAL_FUNCTION_PARAMETERS , bool is_constructor )
236
244
{
237
245
zend_string * uri_str , * base_url_str = NULL ;
246
+ zval * errors ;
238
247
239
248
ZEND_PARSE_PARAMETERS_START (1 , 2 )
240
249
Z_PARAM_PATH_STR (uri_str )
241
250
Z_PARAM_OPTIONAL
242
251
Z_PARAM_PATH_STR_OR_NULL (base_url_str )
252
+ Z_PARAM_ZVAL (errors )
243
253
ZEND_PARSE_PARAMETERS_END ();
244
254
245
255
if (ZSTR_LEN (uri_str ) == 0 ) {
@@ -252,7 +262,7 @@ static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor
252
262
RETURN_THROWS ();
253
263
}
254
264
255
- php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & uriparser_uri_handler , uri_str , base_url_str , is_constructor , false );
265
+ php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & uriparser_uri_handler , uri_str , base_url_str , is_constructor , NULL );
256
266
}
257
267
258
268
PHP_METHOD (Uri_Rfc3986Uri , parse )
@@ -268,11 +278,13 @@ PHP_METHOD(Uri_Rfc3986Uri, __construct)
268
278
static void create_whatwg_uri (INTERNAL_FUNCTION_PARAMETERS , bool is_constructor )
269
279
{
270
280
zend_string * uri_str , * base_url_str = NULL ;
281
+ zval * errors = NULL ;
271
282
272
- ZEND_PARSE_PARAMETERS_START (1 , 2 )
283
+ ZEND_PARSE_PARAMETERS_START (1 , 3 )
273
284
Z_PARAM_PATH_STR (uri_str )
274
285
Z_PARAM_OPTIONAL
275
286
Z_PARAM_PATH_STR_OR_NULL (base_url_str )
287
+ Z_PARAM_ZVAL (errors )
276
288
ZEND_PARSE_PARAMETERS_END ();
277
289
278
290
if (ZSTR_LEN (uri_str ) == 0 ) {
@@ -285,7 +297,7 @@ static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
285
297
RETURN_THROWS ();
286
298
}
287
299
288
- php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & lexbor_uri_handler , uri_str , base_url_str , is_constructor , true );
300
+ php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & lexbor_uri_handler , uri_str , base_url_str , is_constructor , errors );
289
301
}
290
302
291
303
PHP_METHOD (Uri_WhatWgUri , parse )
@@ -378,7 +390,7 @@ PHP_METHOD(Uri_Rfc3986Uri, withFragment)
378
390
URI_WITHER_STR (ZSTR_KNOWN (ZEND_STR_FRAGMENT ));
379
391
}
380
392
381
- PHP_METHOD (Uri_Rfc3986Uri , equalsTo )
393
+ PHP_METHOD (Uri_Rfc3986Uri , equals )
382
394
{
383
395
zend_object * that_object ;
384
396
bool exclude_fragment = true;
@@ -514,7 +526,7 @@ PHP_METHOD(Uri_Rfc3986Uri, toNormalizedString)
514
526
internal_uri -> handler -> free_uri (new_uri );
515
527
}
516
528
517
- PHP_METHOD (Uri_Rfc3986Uri , __toString )
529
+ PHP_METHOD (Uri_Rfc3986Uri , toString )
518
530
{
519
531
ZEND_PARSE_PARAMETERS_NONE ();
520
532
@@ -525,6 +537,23 @@ PHP_METHOD(Uri_Rfc3986Uri, __toString)
525
537
RETURN_STR (internal_uri -> handler -> uri_to_string (internal_uri -> uri , false));
526
538
}
527
539
540
+ PHP_METHOD (Uri_Rfc3986Uri , resolve )
541
+ {
542
+ zend_string * uri_str ;
543
+
544
+ ZEND_PARSE_PARAMETERS_START (1 , 1 ) \
545
+ Z_PARAM_PATH_STR (uri_str ) \
546
+ ZEND_PARSE_PARAMETERS_END (); \
547
+
548
+ zend_object * this_object = Z_OBJ_P (ZEND_THIS );
549
+ uri_internal_t * internal_uri = uri_internal_from_obj (this_object );
550
+ URI_CHECK_INITIALIZATION_RETURN_THROWS (internal_uri , this_object );
551
+
552
+ zend_string * base_uri_str = internal_uri -> handler -> uri_to_string (internal_uri -> uri , false); // TODO optimize by not reparsing the base URI
553
+
554
+ php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , internal_uri -> handler , uri_str , base_uri_str , true, NULL );
555
+ }
556
+
528
557
PHP_METHOD (Uri_Rfc3986Uri , __serialize )
529
558
{
530
559
ZEND_PARSE_PARAMETERS_NONE ();
@@ -839,9 +868,7 @@ zend_result uri_handler_register(const uri_handler_t *uri_handler)
839
868
840
869
static PHP_MINIT_FUNCTION (uri )
841
870
{
842
- register_php_uri_symbols (module_number );
843
-
844
- uri_interface_ce = register_class_Uri_UriInterface (zend_ce_stringable );
871
+ uri_interface_ce = register_class_Uri_Uri ();
845
872
846
873
rfc3986_uri_ce = register_class_Uri_Rfc3986Uri (uri_interface_ce );
847
874
php_uri_implementation_set_object_handlers (rfc3986_uri_ce , & rfc3986_uri_object_handlers );
@@ -853,7 +880,8 @@ static PHP_MINIT_FUNCTION(uri)
853
880
uninitialized_uri_exception_ce = register_class_Uri_UninitializedUriException (uri_exception_ce );
854
881
uri_operation_exception_ce = register_class_Uri_UriOperationException (uri_exception_ce );
855
882
invalid_uri_exception_ce = register_class_Uri_InvalidUriException (uri_exception_ce );
856
- whatwg_error_ce = register_class_Uri_WhatWgError ();
883
+ whatwg_error_ce = register_class_Uri_WhatWg_WhatWgError ();
884
+ whatwg_error_type_ce = register_class_Uri_WhatWg_WhatWgErrorType ();
857
885
858
886
zend_hash_init (& uri_handlers , 4 , NULL , ZVAL_PTR_DTOR , true);
859
887
0 commit comments