@@ -34,6 +34,7 @@ zend_class_entry *rfc3986_uri_ce;
34
34
zend_object_handlers rfc3986_uri_object_handlers ;
35
35
zend_class_entry * whatwg_url_ce ;
36
36
zend_object_handlers whatwg_uri_object_handlers ;
37
+ zend_class_entry * uri_comparison_mode_ce ;
37
38
zend_class_entry * uri_exception_ce ;
38
39
zend_class_entry * invalid_uri_exception_ce ;
39
40
zend_class_entry * whatwg_invalid_url_exception_ce ;
@@ -353,13 +354,20 @@ static zend_result pass_errors_by_ref(zval *errors_zv, zval *errors)
353
354
}
354
355
355
356
PHPAPI void php_uri_instantiate_uri (
356
- INTERNAL_FUNCTION_PARAMETERS , const uri_handler_t * handler , const zend_string * uri_str , const zend_string * base_url_str ,
357
+ INTERNAL_FUNCTION_PARAMETERS , const uri_handler_t * handler , const zend_string * uri_str , const zend_object * base_url_object ,
357
358
bool is_constructor , zval * errors_zv
358
359
) {
359
360
zval errors ;
360
361
ZVAL_UNDEF (& errors );
361
362
362
- void * uri = handler -> parse_uri (uri_str , base_url_str , is_constructor || errors_zv != NULL ? & errors : NULL );
363
+ void * base_url = NULL ;
364
+ if (base_url_object != NULL ) {
365
+ uri_internal_t * internal_base_url = uri_internal_from_obj (base_url_object );
366
+ URI_CHECK_INITIALIZATION (internal_base_url );
367
+ base_url = internal_base_url -> uri ;
368
+ }
369
+
370
+ void * uri = handler -> parse_uri (uri_str , base_url , is_constructor || errors_zv != NULL ? & errors : NULL );
363
371
if (UNEXPECTED (uri == NULL )) {
364
372
if (is_constructor ) {
365
373
throw_invalid_uri_exception (handler , & errors );
@@ -389,25 +397,16 @@ PHPAPI void php_uri_instantiate_uri(
389
397
390
398
static void create_rfc3986_uri (INTERNAL_FUNCTION_PARAMETERS , bool is_constructor )
391
399
{
392
- zend_string * uri_str , * base_url_str = NULL ;
400
+ zend_string * uri_str ;
401
+ zend_object * base_url_object = NULL ;
393
402
394
403
ZEND_PARSE_PARAMETERS_START (1 , 2 )
395
404
Z_PARAM_PATH_STR (uri_str )
396
405
Z_PARAM_OPTIONAL
397
- Z_PARAM_PATH_STR_OR_NULL ( base_url_str )
406
+ Z_PARAM_OBJ_OF_CLASS_OR_NULL ( base_url_object , rfc3986_uri_ce )
398
407
ZEND_PARSE_PARAMETERS_END ();
399
408
400
- if (ZSTR_LEN (uri_str ) == 0 ) {
401
- zend_argument_value_error (1 , "cannot be empty" );
402
- RETURN_THROWS ();
403
- }
404
-
405
- if (base_url_str && ZSTR_LEN (base_url_str ) == 0 ) {
406
- zend_argument_value_error (2 , "cannot be empty" );
407
- RETURN_THROWS ();
408
- }
409
-
410
- php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & uriparser_uri_handler , uri_str , base_url_str , is_constructor , NULL );
409
+ php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & uriparser_uri_handler , uri_str , base_url_object , is_constructor , NULL );
411
410
}
412
411
413
412
PHP_METHOD (Uri_Rfc3986_Uri , parse )
@@ -422,27 +421,18 @@ PHP_METHOD(Uri_Rfc3986_Uri, __construct)
422
421
423
422
static void create_whatwg_uri (INTERNAL_FUNCTION_PARAMETERS , bool is_constructor )
424
423
{
425
- zend_string * uri_str , * base_url_str = NULL ;
424
+ zend_string * uri_str ;
425
+ zend_object * base_url_object = NULL ;
426
426
zval * errors = NULL ;
427
427
428
428
ZEND_PARSE_PARAMETERS_START (1 , 3 )
429
429
Z_PARAM_PATH_STR (uri_str )
430
430
Z_PARAM_OPTIONAL
431
- Z_PARAM_PATH_STR_OR_NULL ( base_url_str )
431
+ Z_PARAM_OBJ_OF_CLASS_OR_NULL ( base_url_object , whatwg_url_ce )
432
432
Z_PARAM_ZVAL (errors )
433
433
ZEND_PARSE_PARAMETERS_END ();
434
434
435
- if (ZSTR_LEN (uri_str ) == 0 ) {
436
- zend_argument_value_error (1 , "cannot be empty" );
437
- RETURN_THROWS ();
438
- }
439
-
440
- if (base_url_str && ZSTR_LEN (base_url_str ) == 0 ) {
441
- zend_argument_value_error (2 , "cannot be empty" );
442
- RETURN_THROWS ();
443
- }
444
-
445
- php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & lexbor_uri_handler , uri_str , base_url_str , is_constructor , errors );
435
+ php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & lexbor_uri_handler , uri_str , base_url_object , is_constructor , errors );
446
436
}
447
437
448
438
PHP_METHOD (Uri_WhatWg_Url , parse )
@@ -575,7 +565,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withFragment)
575
565
URI_WITHER_STR_OR_NULL (ZSTR_KNOWN (ZEND_STR_FRAGMENT ));
576
566
}
577
567
578
- static void uri_equals (INTERNAL_FUNCTION_PARAMETERS , zend_object * that_object , bool exclude_fragment )
568
+ static void uri_equals (INTERNAL_FUNCTION_PARAMETERS , zend_object * that_object , zend_object * comparison_mode )
579
569
{
580
570
zend_object * this_object = Z_OBJ_P (ZEND_THIS );
581
571
uri_internal_t * this_internal_uri = uri_internal_from_obj (this_object );
@@ -591,6 +581,14 @@ static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, zend_object *that_object, b
591
581
RETURN_FALSE ;
592
582
}
593
583
584
+ bool exclude_fragment = true;
585
+ if (comparison_mode ) {
586
+ zval * case_name = zend_enum_fetch_case_name (comparison_mode );
587
+ zend_string * comparison_mode_name = Z_STR_P (case_name );
588
+
589
+ exclude_fragment = ZSTR_VAL (comparison_mode_name )[0 ] + ZSTR_LEN (comparison_mode_name ) == 'E' + sizeof ("ExcludeFragment" ) - 1 ;
590
+ }
591
+
594
592
zend_string * this_str = this_internal_uri -> handler -> uri_to_string (
595
593
this_internal_uri -> uri , URI_RECOMPOSITION_NORMALIZED_ASCII , exclude_fragment );
596
594
if (this_str == NULL ) {
@@ -614,15 +612,15 @@ static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, zend_object *that_object, b
614
612
PHP_METHOD (Uri_Rfc3986_Uri , equals )
615
613
{
616
614
zend_object * that_object ;
617
- bool exclude_fragment = true ;
615
+ zend_object * comparison_mode = NULL ;
618
616
619
617
ZEND_PARSE_PARAMETERS_START (1 , 2 )
620
618
Z_PARAM_OBJ_OF_CLASS (that_object , rfc3986_uri_ce )
621
619
Z_PARAM_OPTIONAL
622
- Z_PARAM_BOOL ( exclude_fragment )
620
+ Z_PARAM_OBJ_OF_CLASS ( comparison_mode , uri_comparison_mode_ce );
623
621
ZEND_PARSE_PARAMETERS_END ();
624
622
625
- uri_equals (INTERNAL_FUNCTION_PARAM_PASSTHRU , that_object , exclude_fragment );
623
+ uri_equals (INTERNAL_FUNCTION_PARAM_PASSTHRU , that_object , comparison_mode );
626
624
}
627
625
628
626
PHP_METHOD (Uri_Rfc3986_Uri , toRawString )
@@ -671,14 +669,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, resolve)
671
669
uri_internal_t * internal_uri = uri_internal_from_obj (this_object );
672
670
URI_CHECK_INITIALIZATION (internal_uri );
673
671
674
- zend_string * base_uri_str = internal_uri -> handler -> uri_to_string (
675
- internal_uri -> uri , URI_RECOMPOSITION_RAW_ASCII , false); // TODO optimize by not reparsing the base URI
676
- if (base_uri_str == NULL ) {
677
- zend_throw_exception_ex (NULL , 0 , "Cannot recompose %s to string" , ZSTR_VAL (this_object -> ce -> name ));
678
- RETURN_THROWS ();
679
- }
680
-
681
- php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , internal_uri -> handler , uri_str , base_uri_str , true, NULL );
672
+ php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , internal_uri -> handler , uri_str , this_object , true, NULL );
682
673
}
683
674
684
675
PHP_METHOD (Uri_Rfc3986_Uri , __serialize )
@@ -832,15 +823,15 @@ PHP_METHOD(Uri_WhatWg_Url, withHost)
832
823
PHP_METHOD (Uri_WhatWg_Url , equals )
833
824
{
834
825
zend_object * that_object ;
835
- bool exclude_fragment = true ;
826
+ zend_object * comparison_mode = NULL ;
836
827
837
828
ZEND_PARSE_PARAMETERS_START (1 , 2 )
838
829
Z_PARAM_OBJ_OF_CLASS (that_object , whatwg_url_ce )
839
830
Z_PARAM_OPTIONAL
840
- Z_PARAM_BOOL ( exclude_fragment )
831
+ Z_PARAM_OBJ_OF_CLASS ( comparison_mode , uri_comparison_mode_ce );
841
832
ZEND_PARSE_PARAMETERS_END ();
842
833
843
- uri_equals (INTERNAL_FUNCTION_PARAM_PASSTHRU , that_object , exclude_fragment );
834
+ uri_equals (INTERNAL_FUNCTION_PARAM_PASSTHRU , that_object , comparison_mode );
844
835
}
845
836
846
837
PHP_METHOD (Uri_WhatWg_Url , toUnicodeString )
@@ -955,6 +946,7 @@ static PHP_MINIT_FUNCTION(uri)
955
946
whatwg_url_ce = register_class_Uri_WhatWg_Url ();
956
947
php_uri_implementation_set_object_handlers (whatwg_url_ce , & whatwg_uri_object_handlers );
957
948
949
+ uri_comparison_mode_ce = register_class_Uri_UriComparisonMode ();
958
950
uri_exception_ce = register_class_Uri_UriException (zend_ce_exception );
959
951
invalid_uri_exception_ce = register_class_Uri_InvalidUriException (uri_exception_ce );
960
952
whatwg_invalid_url_exception_ce = register_class_Uri_WhatWg_InvalidUrlException (invalid_uri_exception_ce );
0 commit comments