Skip to content

Commit f55d512

Browse files
committed
Add support for Uri\Rfc3986\Uri withers
1 parent 9f8802c commit f55d512

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
@@ -498,7 +498,12 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawScheme)
498498
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_SCHEME, URI_COMPONENT_READ_RAW);
499499
}
500500

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

@@ -513,12 +518,48 @@ static void read_uriparser_userinfo(INTERNAL_FUNCTION_PARAMETERS, uri_component_
513518

514519
PHP_METHOD(Uri_Rfc3986_Uri, getUserInfo)
515520
{
516-
read_uriparser_userinfo(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_COMPONENT_READ_NORMALIZED_ASCII);
521+
rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_COMPONENT_READ_NORMALIZED_ASCII);
517522
}
518523

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

524565
PHP_METHOD(Uri_Rfc3986_Uri, getUsername)
@@ -551,11 +592,21 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawHost)
551592
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_HOST, URI_COMPONENT_READ_RAW);
552593
}
553594

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

605+
PHP_METHOD(Uri_Rfc3986_Uri, withPort)
606+
{
607+
uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PORT);
608+
}
609+
559610
PHP_METHOD(Uri_Rfc3986_Uri, getPath)
560611
{
561612
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH, URI_COMPONENT_READ_NORMALIZED_ASCII);
@@ -566,6 +617,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawPath)
566617
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH, URI_COMPONENT_READ_RAW);
567618
}
568619

620+
PHP_METHOD(Uri_Rfc3986_Uri, withPath)
621+
{
622+
uri_write_component_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH);
623+
}
624+
569625
PHP_METHOD(Uri_Rfc3986_Uri, getQuery)
570626
{
571627
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY, URI_COMPONENT_READ_NORMALIZED_ASCII);
@@ -576,6 +632,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawQuery)
576632
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY, URI_COMPONENT_READ_RAW);
577633
}
578634

635+
PHP_METHOD(Uri_Rfc3986_Uri, withQuery)
636+
{
637+
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY);
638+
}
639+
579640
PHP_METHOD(Uri_Rfc3986_Uri, getFragment)
580641
{
581642
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT, URI_COMPONENT_READ_NORMALIZED_ASCII);
@@ -586,6 +647,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawFragment)
586647
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT, URI_COMPONENT_READ_RAW);
587648
}
588649

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

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

859905
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)