Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions ext/lexbor/lexbor/url/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,6 @@ lxb_url_is_url_codepoint(lxb_codepoint_t cp)
return lxb_url_codepoint_alphanumeric[(lxb_char_t) cp] != 0xFF;
}

lxb_inline bool
Comment thread
kocsismate marked this conversation as resolved.
lxb_url_is_special(const lxb_url_t *url)
{
return url->scheme.type != LXB_URL_SCHEMEL_TYPE__UNKNOWN;
}

lxb_inline const lxb_url_scheme_data_t *
lxb_url_scheme_by_type(lxb_url_scheme_type_t type)
{
Expand Down
5 changes: 5 additions & 0 deletions ext/lexbor/lexbor/url/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ lxb_url_get(lxb_url_parser_t *parser)
return parser->url;
}

lxb_inline bool
lxb_url_is_special(const lxb_url_t *url)
{
return url->scheme.type != LXB_URL_SCHEMEL_TYPE__UNKNOWN;
}

#ifdef __cplusplus
} /* extern "C" */
Expand Down
23 changes: 23 additions & 0 deletions ext/uri/php_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "uriparser/Uri.h"

zend_class_entry *php_uri_ce_rfc3986_uri;
zend_class_entry *php_uri_ce_rfc3986_uri_type;
zend_class_entry *php_uri_ce_whatwg_url;
zend_class_entry *php_uri_ce_comparison_mode;
zend_class_entry *php_uri_ce_exception;
Expand Down Expand Up @@ -508,6 +509,16 @@ PHP_METHOD(Uri_WhatWg_Url, __construct)
create_whatwg_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
}

PHP_METHOD(Uri_Rfc3986_Uri, getUriType)
{
ZEND_PARSE_PARAMETERS_NONE();

php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS);
ZEND_ASSERT(uri_object->uri != NULL);

php_uri_parser_rfc3986_uri_type_read(uri_object->uri, return_value);
}

PHP_METHOD(Uri_Rfc3986_Uri, getScheme)
{
php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII);
Expand Down Expand Up @@ -883,6 +894,16 @@ PHP_METHOD(Uri_WhatWg_Url, withScheme)
php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_SCHEME);
}

PHP_METHOD(Uri_WhatWg_Url, isSpecialScheme)
{
ZEND_PARSE_PARAMETERS_NONE();

php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS);
ZEND_ASSERT(uri_object->uri != NULL);

RETVAL_BOOL(php_uri_parser_whatwg_is_special(uri_object->uri));
}

PHP_METHOD(Uri_WhatWg_Url, withUsername)
{
php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_USERNAME);
Expand Down Expand Up @@ -1078,6 +1099,8 @@ static PHP_MINIT_FUNCTION(uri)
object_handlers_rfc3986_uri.free_obj = php_uri_object_handler_free;
object_handlers_rfc3986_uri.clone_obj = php_uri_object_handler_clone;

php_uri_ce_rfc3986_uri_type = register_class_Uri_Rfc3986_UriType();

php_uri_ce_whatwg_url = register_class_Uri_WhatWg_Url();
php_uri_ce_whatwg_url->create_object = php_uri_object_create_whatwg;
php_uri_ce_whatwg_url->default_object_handlers = &object_handlers_whatwg_uri;
Expand Down
12 changes: 12 additions & 0 deletions ext/uri/php_uri.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@ enum UriComparisonMode
}

namespace Uri\Rfc3986 {
enum UriType
{
case AbsolutePathReference;
case RelativePathReference;
case NetworkPathReference;
case Uri;
}

/** @strict-properties */
final readonly class Uri
{
public static function parse(string $uri, ?\Uri\Rfc3986\Uri $baseUrl = null): ?static {}

public function __construct(string $uri, ?\Uri\Rfc3986\Uri $baseUrl = null) {}

public function getUriType(): ?\Uri\Rfc3986\UriType {}

public function getScheme(): ?string {}

public function getRawScheme(): ?string {}
Expand Down Expand Up @@ -165,6 +175,8 @@ public function getScheme(): string {}

public function withScheme(string $scheme): static {}

public function isSpecialScheme(): bool {}

/** @implementation-alias Uri\Rfc3986\Uri::getUsername */
public function getUsername(): ?string {}

Expand Down
27 changes: 26 additions & 1 deletion ext/uri/php_uri_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/uri/php_uri_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "php_uri_decl.h"

extern zend_class_entry *php_uri_ce_rfc3986_uri;
extern zend_class_entry *php_uri_ce_rfc3986_uri_type;
extern zend_class_entry *php_uri_ce_whatwg_url;
extern zend_class_entry *php_uri_ce_comparison_mode;
extern zend_class_entry *php_uri_ce_exception;
Expand Down
15 changes: 11 additions & 4 deletions ext/uri/php_uri_decl.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Test Uri\Rfc3986\Uri getter - uri type - Absolute path reference
--FILE--
<?php

$uri = Uri\Rfc3986\Uri::parse("/foo/bar");

var_dump($uri->getUriType());

?>
--EXPECT--
enum(Uri\Rfc3986\UriType::AbsolutePathReference)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Test Uri\Rfc3986\Uri getter - uri type - Network path reference
--FILE--
<?php

$uri = Uri\Rfc3986\Uri::parse("//example.com/foo/bar");

var_dump($uri->getUriType());

?>
--EXPECT--
enum(Uri\Rfc3986\UriType::NetworkPathReference)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Test Uri\Rfc3986\Uri getter - uri type - Relative path reference
--FILE--
<?php

$uri = Uri\Rfc3986\Uri::parse("foo/bar");

var_dump($uri->getUriType());

?>
--EXPECT--
enum(Uri\Rfc3986\UriType::RelativePathReference)
12 changes: 12 additions & 0 deletions ext/uri/tests/rfc3986/getters/uri_type_success_uri_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Test Uri\Rfc3986\Uri getter - uri type - URI
--FILE--
<?php

$uri = Uri\Rfc3986\Uri::parse("https://example.com");

var_dump($uri->getUriType());

?>
--EXPECT--
enum(Uri\Rfc3986\UriType::Uri)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Test Uri\Rfc3986\Uri getter - uri type - URI with empty authority
--FILE--
<?php

$uri = Uri\Rfc3986\Uri::parse("https://");

var_dump($uri->getUriType());

?>
--EXPECT--
enum(Uri\Rfc3986\UriType::Uri)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Test Uri\Rfc3986\Uri getter - uri type - URI without authority
--FILE--
<?php

$uri = Uri\Rfc3986\Uri::parse("https:");

var_dump($uri->getUriType());

?>
--EXPECT--
enum(Uri\Rfc3986\UriType::Uri)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Test Uri\WhatWg\Url::isSpecialScheme() - success - not special
--FILE--
<?php

$url = Uri\WhatWg\Url::parse("scheme://example.com");

var_dump($url->isSpecialScheme());

?>
--EXPECT--
bool(false)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Test Uri\WhatWg\Url::isSpecialScheme() - success - special
--FILE--
<?php

$url = Uri\WhatWg\Url::parse("http://example.com");
var_dump($url->isSpecialScheme());

$url = Uri\WhatWg\Url::parse("https://example.com");
var_dump($url->isSpecialScheme());

$url = Uri\WhatWg\Url::parse("ws://example.com");
var_dump($url->isSpecialScheme());

$url = Uri\WhatWg\Url::parse("wss://example.com");
var_dump($url->isSpecialScheme());

$url = Uri\WhatWg\Url::parse("ftp://example.com");
var_dump($url->isSpecialScheme());

$url = Uri\WhatWg\Url::parse("file://example.com");
var_dump($url->isSpecialScheme());

?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
20 changes: 20 additions & 0 deletions ext/uri/uri_parser_rfc3986.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "php.h"
#include "uri_parser_rfc3986.h"
#include "php_uri_common.h"
#include "Zend/zend_enum.h"
#include "Zend/zend_smart_str.h"
#include "Zend/zend_exceptions.h"

Expand Down Expand Up @@ -110,6 +111,25 @@ ZEND_ATTRIBUTE_NONNULL static UriUriA *get_uri_for_writing(php_uri_parser_rfc398
return &uriparser_uris->uri;
}

ZEND_ATTRIBUTE_NONNULL void php_uri_parser_rfc3986_uri_type_read(php_uri_parser_rfc3986_uris *uri, zval *retval)
{
const UriUriA *uriparser_uri = get_uri_for_reading(uri, PHP_URI_COMPONENT_READ_MODE_RAW);

const char *type;

if (has_text_range(&uriparser_uri->scheme)) {
type = "Uri";
} else if (has_text_range(&uriparser_uri->hostText)) {
type = "NetworkPathReference";
} else if (uriparser_uri->absolutePath) {
type = "AbsolutePathReference";
} else {
type = "RelativePathReference";
}

ZVAL_OBJ_COPY(retval, zend_enum_get_case_cstr(php_uri_ce_rfc3986_uri_type, type));
}

ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_parser_rfc3986_scheme_read(void *uri, php_uri_component_read_mode read_mode, zval *retval)
{
const UriUriA *uriparser_uri = get_uri_for_reading(uri, read_mode);
Expand Down
2 changes: 2 additions & 0 deletions ext/uri/uri_parser_rfc3986.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ PHPAPI extern const php_uri_parser php_uri_parser_rfc3986;

typedef struct php_uri_parser_rfc3986_uris php_uri_parser_rfc3986_uris;

ZEND_ATTRIBUTE_NONNULL void php_uri_parser_rfc3986_uri_type_read(php_uri_parser_rfc3986_uris *uri, zval *retval);

zend_result php_uri_parser_rfc3986_userinfo_read(php_uri_parser_rfc3986_uris *uri, php_uri_component_read_mode read_mode, zval *retval);
zend_result php_uri_parser_rfc3986_userinfo_write(php_uri_parser_rfc3986_uris *uri, zval *value, zval *errors);

Expand Down
Loading