Skip to content

Commit cd08ce2

Browse files
committed
Add support for Uri\Rfc3986\Uri withers
1 parent a4bb5b9 commit cd08ce2

File tree

12 files changed

+578
-61
lines changed

12 files changed

+578
-61
lines changed

ext/uri/php_uri.c

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,12 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawScheme)
497497
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_SCHEME, URI_COMPONENT_READ_RAW);
498498
}
499499

500-
static void read_uriparser_userinfo(INTERNAL_FUNCTION_PARAMETERS, uri_component_read_mode_t read_mode)
500+
PHP_METHOD(Uri_Rfc3986_Uri, withScheme)
501+
{
502+
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_SCHEME);
503+
}
504+
505+
static void rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAMETERS, uri_component_read_mode_t read_mode)
501506
{
502507
ZEND_PARSE_PARAMETERS_NONE();
503508

@@ -512,12 +517,48 @@ static void read_uriparser_userinfo(INTERNAL_FUNCTION_PARAMETERS, uri_component_
512517

513518
PHP_METHOD(Uri_Rfc3986_Uri, getUserInfo)
514519
{
515-
read_uriparser_userinfo(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_COMPONENT_READ_NORMALIZED_ASCII);
520+
rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_COMPONENT_READ_NORMALIZED_ASCII);
516521
}
517522

518523
PHP_METHOD(Uri_Rfc3986_Uri, getRawUserInfo)
519524
{
520-
read_uriparser_userinfo(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_COMPONENT_READ_RAW);
525+
rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_COMPONENT_READ_RAW);
526+
}
527+
528+
PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo)
529+
{
530+
zend_string *value;
531+
532+
ZEND_PARSE_PARAMETERS_START(1, 1)
533+
Z_PARAM_PATH_STR_OR_NULL(value)
534+
ZEND_PARSE_PARAMETERS_END();
535+
536+
zval zv;
537+
if (value == NULL) {
538+
ZVAL_NULL(&zv);
539+
} else {
540+
ZVAL_STR(&zv, value);
541+
}
542+
543+
uri_internal_t *internal_uri = Z_URI_INTERNAL_P(ZEND_THIS);
544+
URI_ASSERT_INITIALIZATION(internal_uri);
545+
546+
zend_object *new_object = uri_clone_obj_handler(Z_OBJ_P(ZEND_THIS));
547+
ZEND_ASSERT(new_object != NULL);
548+
549+
uri_internal_t *new_internal_uri = uri_internal_from_obj(new_object);
550+
URI_ASSERT_INITIALIZATION(new_internal_uri);
551+
552+
zval errors;
553+
ZVAL_UNDEF(&errors);
554+
if (UNEXPECTED(php_uri_parser_rfc3986_userinfo_write(new_internal_uri, &zv, NULL) == FAILURE)) {
555+
zval_ptr_dtor(&errors);
556+
zend_object_release(new_object);
557+
RETURN_THROWS();
558+
}
559+
560+
ZEND_ASSERT(Z_ISUNDEF(errors));
561+
RETVAL_OBJ(new_object);
521562
}
522563

523564
PHP_METHOD(Uri_Rfc3986_Uri, getUsername)
@@ -550,11 +591,21 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawHost)
550591
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_HOST, URI_COMPONENT_READ_RAW);
551592
}
552593

594+
PHP_METHOD(Uri_Rfc3986_Uri, withHost)
595+
{
596+
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_HOST);
597+
}
598+
553599
PHP_METHOD(Uri_Rfc3986_Uri, getPort)
554600
{
555601
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PORT, URI_COMPONENT_READ_RAW);
556602
}
557603

604+
PHP_METHOD(Uri_Rfc3986_Uri, withPort)
605+
{
606+
uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PORT);
607+
}
608+
558609
PHP_METHOD(Uri_Rfc3986_Uri, getPath)
559610
{
560611
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH, URI_COMPONENT_READ_NORMALIZED_ASCII);
@@ -565,6 +616,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawPath)
565616
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH, URI_COMPONENT_READ_RAW);
566617
}
567618

619+
PHP_METHOD(Uri_Rfc3986_Uri, withPath)
620+
{
621+
uri_write_component_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH);
622+
}
623+
568624
PHP_METHOD(Uri_Rfc3986_Uri, getQuery)
569625
{
570626
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY, URI_COMPONENT_READ_NORMALIZED_ASCII);
@@ -575,6 +631,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawQuery)
575631
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY, URI_COMPONENT_READ_RAW);
576632
}
577633

634+
PHP_METHOD(Uri_Rfc3986_Uri, withQuery)
635+
{
636+
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY);
637+
}
638+
578639
PHP_METHOD(Uri_Rfc3986_Uri, getFragment)
579640
{
580641
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT, URI_COMPONENT_READ_NORMALIZED_ASCII);
@@ -585,6 +646,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawFragment)
585646
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT, URI_COMPONENT_READ_RAW);
586647
}
587648

649+
PHP_METHOD(Uri_Rfc3986_Uri, withFragment)
650+
{
651+
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT);
652+
}
653+
588654
static void throw_cannot_recompose_uri_to_string(zend_object *object)
589655
{
590656
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->ce->name));
@@ -830,29 +896,9 @@ PHP_METHOD(Uri_WhatWg_Url, getUnicodeHost)
830896
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_HOST, URI_COMPONENT_READ_NORMALIZED_UNICODE);
831897
}
832898

833-
PHP_METHOD(Uri_WhatWg_Url, withHost)
834-
{
835-
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_HOST);
836-
}
837-
838-
PHP_METHOD(Uri_WhatWg_Url, withPort)
839-
{
840-
uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PORT);
841-
}
842-
843-
PHP_METHOD(Uri_WhatWg_Url, withPath)
899+
PHP_METHOD(Uri_WhatWg_Url, getFragment)
844900
{
845-
uri_write_component_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH);
846-
}
847-
848-
PHP_METHOD(Uri_WhatWg_Url, withQuery)
849-
{
850-
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY);
851-
}
852-
853-
PHP_METHOD(Uri_WhatWg_Url, withFragment)
854-
{
855-
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT);
901+
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT, URI_COMPONENT_READ_NORMALIZED_UNICODE);
856902
}
857903

858904
PHP_METHOD(Uri_WhatWg_Url, equals)

ext/uri/php_uri.stub.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ public function getScheme(): ?string {}
3232

3333
public function getRawScheme(): ?string {}
3434

35+
public function withScheme(?string $scheme): static {}
36+
3537
public function getUserInfo(): ?string {}
3638

3739
public function getRawUserInfo(): ?string {}
3840

41+
public function withUserInfo(#[\SensitiveParameter] ?string $userinfo): static {}
42+
3943
public function getUsername(): ?string {}
4044

4145
public function getRawUsername(): ?string {}
@@ -48,20 +52,30 @@ public function getHost(): ?string {}
4852

4953
public function getRawHost(): ?string {}
5054

55+
public function withHost(?string $host): static {}
56+
5157
public function getPort(): ?int {}
5258

59+
public function withPort(?int $port): static {}
60+
5361
public function getPath(): string {}
5462

5563
public function getRawPath(): string {}
5664

65+
public function withPath(string $path): static {}
66+
5767
public function getQuery(): ?string {}
5868

5969
public function getRawQuery(): ?string {}
6070

71+
public function withQuery(?string $query): static {}
72+
6173
public function getFragment(): ?string {}
6274

6375
public function getRawFragment(): ?string {}
6476

77+
public function withFragment(?string $fragment): static {}
78+
6579
public function equals(\Uri\Rfc3986\Uri $uri, \Uri\UriComparisonMode $comparisonMode = \Uri\UriComparisonMode::ExcludeFragment): bool {}
6680

6781
public function toString(): string {}
@@ -157,26 +171,31 @@ public function getAsciiHost(): ?string {}
157171

158172
public function getUnicodeHost(): ?string {}
159173

174+
/** @implementation-alias Uri\Rfc3986\Uri::withHost */
160175
public function withHost(?string $host): static {}
161176

162177
/** @implementation-alias Uri\Rfc3986\Uri::getPort */
163178
public function getPort(): ?int {}
164179

180+
/** @implementation-alias Uri\Rfc3986\Uri::withPort */
165181
public function withPort(?int $port): static {}
166182

167183
/** @implementation-alias Uri\Rfc3986\Uri::getPath */
168184
public function getPath(): string {}
169185

186+
/** @implementation-alias Uri\Rfc3986\Uri::withPath */
170187
public function withPath(string $path): static {}
171188

172189
/** @implementation-alias Uri\Rfc3986\Uri::getQuery */
173190
public function getQuery(): ?string {}
174191

192+
/** @implementation-alias Uri\Rfc3986\Uri::withQuery */
175193
public function withQuery(?string $query): static {}
176194

177195
/** @implementation-alias Uri\Rfc3986\Uri::getFragment */
178196
public function getFragment(): ?string {}
179197

198+
/** @implementation-alias Uri\Rfc3986\Uri::withFragment */
180199
public function withFragment(?string $fragment): static {}
181200

182201
public function equals(\Uri\WhatWg\Url $url, \Uri\UriComparisonMode $comparisonMode = \Uri\UriComparisonMode::ExcludeFragment): bool {}

0 commit comments

Comments
 (0)