Skip to content

Commit a052959

Browse files
committed
Add support for Uri\Rfc3986\Uri withers
1 parent 914f9ad commit a052959

37 files changed

+4820
-158
lines changed

ext/uri/config.m4

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ URIPARSER_SOURCES="$URIPARSER_DIR/src/UriCommon.c $URIPARSER_DIR/src/UriCompare.
1717
$URIPARSER_DIR/src/UriEscape.c $URIPARSER_DIR/src/UriFile.c $URIPARSER_DIR/src/UriIp4.c $URIPARSER_DIR/src/UriIp4Base.c \
1818
$URIPARSER_DIR/src/UriMemory.c $URIPARSER_DIR/src/UriNormalize.c $URIPARSER_DIR/src/UriNormalizeBase.c \
1919
$URIPARSER_DIR/src/UriParse.c $URIPARSER_DIR/src/UriParseBase.c $URIPARSER_DIR/src/UriQuery.c \
20-
$URIPARSER_DIR/src/UriRecompose.c $URIPARSER_DIR/src/UriResolve.c $URIPARSER_DIR/src/UriShorten.c"
20+
$URIPARSER_DIR/src/UriRecompose.c $URIPARSER_DIR/src/UriResolve.c $URIPARSER_DIR/src/UriSetFragment.c \
21+
$URIPARSER_DIR/src/UriSetHostCommon.c $URIPARSER_DIR/src/UriSetHostIp4.c $URIPARSER_DIR/src/UriSetHostIp6.c \
22+
$URIPARSER_DIR/src/UriSetHostIpFuture.c $URIPARSER_DIR/src/UriSetHostRegName.c $URIPARSER_DIR/src/UriSetPath.c \
23+
$URIPARSER_DIR/src/UriSetPort.c $URIPARSER_DIR/src/UriSetQuery.c $URIPARSER_DIR/src/UriSetScheme.c \
24+
$URIPARSER_DIR/src/UriSetUserInfo.c $URIPARSER_DIR/src/UriShorten.c"
2125

2226
PHP_NEW_EXTENSION(uri, [php_uri.c php_uri_common.c uri_parser_rfc3986.c uri_parser_whatwg.c uri_parser_php_parse_url.c $URIPARSER_SOURCES], [no],,[-I$ext_srcdir/$URIPARSER_DIR/include -DURI_STATIC_BUILD -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
2327
PHP_ADD_EXTENSION_DEP(uri, lexbor)

ext/uri/config.w32

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ AC_DEFINE("URI_NO_UNICODE", 1, "Define to 1 for disabling unicode support of uri
55
ADD_FLAG("CFLAGS_URI", "/D URI_STATIC_BUILD");
66

77
ADD_EXTENSION_DEP('uri', 'lexbor');
8-
ADD_SOURCES("ext/uri/uriparser/src", "UriCommon.c UriCompare.c UriCopy.c UriEscape.c UriFile.c UriIp4.c UriIp4Base.c UriMemory.c UriNormalize.c UriNormalizeBase.c UriParse.c UriParseBase.c UriQuery.c UriRecompose.c UriResolve.c UriShorten.c", "uri");
8+
ADD_SOURCES("ext/uri/uriparser/src", "UriCommon.c UriCompare.c UriCopy.c UriEscape.c UriFile.c UriIp4.c UriIp4Base.c \
9+
UriMemory.c UriNormalize.c UriNormalizeBase.c UriParse.c UriParseBase.c UriQuery.c UriRecompose.c UriResolve.c \
10+
UriSetFragment.c UriSetHostCommon.c UriSetHostIp4.c UriSetHostIp6.c UriSetHostIpFuture.c UriSetHostRegName.c \
11+
UriSetPath.c UriSetPort.c UriSetQuery.c UriSetScheme.c UriSetUserInfo.c UriShorten.c", "uri");
912
PHP_INSTALL_HEADERS("ext/uri", "php_uri.h php_uri_common.h uri_parser_rfc3986.h uri_parser_whatwg.h uri_parser_php_parse_url.h uriparser/src uriparser/include");

ext/uri/php_uri.c

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,12 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawScheme)
500500
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_SCHEME, URI_COMPONENT_READ_RAW);
501501
}
502502

503-
static void read_uriparser_userinfo(INTERNAL_FUNCTION_PARAMETERS, uri_component_read_mode_t read_mode)
503+
PHP_METHOD(Uri_Rfc3986_Uri, withScheme)
504+
{
505+
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_SCHEME);
506+
}
507+
508+
static void rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAMETERS, uri_component_read_mode_t read_mode)
504509
{
505510
ZEND_PARSE_PARAMETERS_NONE();
506511

@@ -515,12 +520,48 @@ static void read_uriparser_userinfo(INTERNAL_FUNCTION_PARAMETERS, uri_component_
515520

516521
PHP_METHOD(Uri_Rfc3986_Uri, getUserInfo)
517522
{
518-
read_uriparser_userinfo(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_COMPONENT_READ_NORMALIZED_ASCII);
523+
rfc3986_userinfo_read(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_COMPONENT_READ_NORMALIZED_ASCII);
519524
}
520525

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

526567
PHP_METHOD(Uri_Rfc3986_Uri, getUsername)
@@ -553,11 +594,21 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawHost)
553594
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_HOST, URI_COMPONENT_READ_RAW);
554595
}
555596

597+
PHP_METHOD(Uri_Rfc3986_Uri, withHost)
598+
{
599+
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_HOST);
600+
}
601+
556602
PHP_METHOD(Uri_Rfc3986_Uri, getPort)
557603
{
558604
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PORT, URI_COMPONENT_READ_NORMALIZED_ASCII);
559605
}
560606

607+
PHP_METHOD(Uri_Rfc3986_Uri, withPort)
608+
{
609+
uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PORT);
610+
}
611+
561612
PHP_METHOD(Uri_Rfc3986_Uri, getPath)
562613
{
563614
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH, URI_COMPONENT_READ_NORMALIZED_ASCII);
@@ -568,6 +619,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawPath)
568619
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH, URI_COMPONENT_READ_RAW);
569620
}
570621

622+
PHP_METHOD(Uri_Rfc3986_Uri, withPath)
623+
{
624+
uri_write_component_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH);
625+
}
626+
571627
PHP_METHOD(Uri_Rfc3986_Uri, getQuery)
572628
{
573629
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY, URI_COMPONENT_READ_NORMALIZED_ASCII);
@@ -578,6 +634,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawQuery)
578634
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY, URI_COMPONENT_READ_RAW);
579635
}
580636

637+
PHP_METHOD(Uri_Rfc3986_Uri, withQuery)
638+
{
639+
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY);
640+
}
641+
581642
PHP_METHOD(Uri_Rfc3986_Uri, getFragment)
582643
{
583644
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT, URI_COMPONENT_READ_NORMALIZED_ASCII);
@@ -588,6 +649,11 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawFragment)
588649
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT, URI_COMPONENT_READ_RAW);
589650
}
590651

652+
PHP_METHOD(Uri_Rfc3986_Uri, withFragment)
653+
{
654+
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT);
655+
}
656+
591657
static void throw_cannot_recompose_uri_to_string(zend_object *object)
592658
{
593659
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->ce->name));
@@ -833,29 +899,9 @@ PHP_METHOD(Uri_WhatWg_Url, getUnicodeHost)
833899
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_HOST, URI_COMPONENT_READ_NORMALIZED_UNICODE);
834900
}
835901

836-
PHP_METHOD(Uri_WhatWg_Url, withHost)
837-
{
838-
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_HOST);
839-
}
840-
841-
PHP_METHOD(Uri_WhatWg_Url, withPort)
842-
{
843-
uri_write_component_long_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PORT);
844-
}
845-
846-
PHP_METHOD(Uri_WhatWg_Url, withPath)
902+
PHP_METHOD(Uri_WhatWg_Url, getFragment)
847903
{
848-
uri_write_component_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_PATH);
849-
}
850-
851-
PHP_METHOD(Uri_WhatWg_Url, withQuery)
852-
{
853-
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_QUERY);
854-
}
855-
856-
PHP_METHOD(Uri_WhatWg_Url, withFragment)
857-
{
858-
uri_write_component_str_or_null(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT);
904+
uri_read_component(INTERNAL_FUNCTION_PARAM_PASSTHRU, URI_PROPERTY_NAME_FRAGMENT, URI_COMPONENT_READ_NORMALIZED_UNICODE);
859905
}
860906

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