Skip to content
Merged
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ PHP NEWS
(nielsdos)
. Prevent modifying Uri\WhatWg\Url and Uri\Rfc3986\Uri objects by manually
calling __construct() or __unserialize(). (timwolla)
. Add new Uri\UriError exception that is thrown for internal error
conditions. (timwolla)
. Further clean up the internal API. (timwolla)

- Windows:
Expand Down
4 changes: 3 additions & 1 deletion ext/uri/php_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ zend_class_entry *uri_whatwg_url_ce;
zend_object_handlers uri_whatwg_uri_object_handlers;
zend_class_entry *uri_comparison_mode_ce;
zend_class_entry *uri_exception_ce;
zend_class_entry *uri_error_ce;
zend_class_entry *uri_invalid_uri_exception_ce;
zend_class_entry *uri_whatwg_invalid_url_exception_ce;
zend_class_entry *uri_whatwg_url_validation_error_type_ce;
Expand Down Expand Up @@ -675,7 +676,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withFragment)

static void throw_cannot_recompose_uri_to_string(zend_object *object)
{
zend_throw_exception_ex(NULL, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->ce->name));
zend_throw_exception_ex(uri_error_ce, 0, "Cannot recompose %s to a string", ZSTR_VAL(object->ce->name));
}

static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, zend_object *that_object, zend_object *comparison_mode)
Expand Down Expand Up @@ -1105,6 +1106,7 @@ static PHP_MINIT_FUNCTION(uri)

uri_comparison_mode_ce = register_class_Uri_UriComparisonMode();
uri_exception_ce = register_class_Uri_UriException(zend_ce_exception);
uri_error_ce = register_class_Uri_UriError(zend_ce_error);
uri_invalid_uri_exception_ce = register_class_Uri_InvalidUriException(uri_exception_ce);
uri_whatwg_invalid_url_exception_ce = register_class_Uri_WhatWg_InvalidUrlException(uri_invalid_uri_exception_ce);
uri_whatwg_url_validation_error_ce = register_class_Uri_WhatWg_UrlValidationError();
Expand Down
5 changes: 5 additions & 0 deletions ext/uri/php_uri.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class UriException extends \Exception
{
}

/** @strict-properties */
class UriError extends \Error
{
}

/** @strict-properties */
class InvalidUriException extends \Uri\UriException
{
Expand Down
12 changes: 11 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.

2 changes: 1 addition & 1 deletion ext/uri/php_uri_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void uri_read_component(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name prop
const php_uri_property_handler *property_handler = php_uri_parser_property_handler_by_name(internal_uri->parser, property_name);

if (UNEXPECTED(property_handler->read(internal_uri->uri, component_read_mode, return_value) == FAILURE)) {
zend_throw_error(NULL, "The %s component cannot be retrieved", ZSTR_VAL(get_known_string_by_property_name(property_name)));
zend_throw_exception_ex(uri_error_ce, 0, "The %s component cannot be retrieved", ZSTR_VAL(get_known_string_by_property_name(property_name)));
RETURN_THROWS();
}
}
Expand Down
1 change: 1 addition & 0 deletions ext/uri/php_uri_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern zend_class_entry *uri_whatwg_url_ce;
extern zend_object_handlers uri_whatwg_uri_object_handlers;
extern zend_class_entry *uri_comparison_mode_ce;
extern zend_class_entry *uri_exception_ce;
extern zend_class_entry *uri_error_ce;
extern zend_class_entry *uri_invalid_uri_exception_ce;
extern zend_class_entry *uri_whatwg_invalid_url_exception_ce;
extern zend_class_entry *uri_whatwg_url_validation_error_type_ce;
Expand Down
18 changes: 9 additions & 9 deletions ext/uri/uri_parser_rfc3986.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static zend_result php_uri_parser_rfc3986_scheme_write(void *uri, zval *value, z
return FAILURE;
default:
/* This should be unreachable in practice. */
zend_throw_exception(uri_invalid_uri_exception_ce, "Failed to update the scheme", 0);
zend_throw_exception(uri_error_ce, "Failed to update the scheme", 0);
return FAILURE;
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ zend_result php_uri_parser_rfc3986_userinfo_write(void *uri, zval *value, zval *
return FAILURE;
default:
/* This should be unreachable in practice. */
zend_throw_exception(uri_invalid_uri_exception_ce, "Failed to update the userinfo", 0);
zend_throw_exception(uri_error_ce, "Failed to update the userinfo", 0);
return FAILURE;
}
}
Expand Down Expand Up @@ -271,7 +271,7 @@ static zend_result php_uri_parser_rfc3986_host_write(void *uri, zval *value, zva
return FAILURE;
default:
/* This should be unreachable in practice. */
zend_throw_exception(uri_invalid_uri_exception_ce, "Failed to update the host", 0);
zend_throw_exception(uri_error_ce, "Failed to update the host", 0);
return FAILURE;
}
}
Expand Down Expand Up @@ -331,7 +331,7 @@ static zend_result php_uri_parser_rfc3986_port_write(void *uri, zval *value, zva
return FAILURE;
default:
/* This should be unreachable in practice. */
zend_throw_exception(uri_invalid_uri_exception_ce, "Failed to update the port", 0);
zend_throw_exception(uri_error_ce, "Failed to update the port", 0);
return FAILURE;
}
}
Expand Down Expand Up @@ -383,7 +383,7 @@ static zend_result php_uri_parser_rfc3986_path_write(void *uri, zval *value, zva
return FAILURE;
default:
/* This should be unreachable in practice. */
zend_throw_exception(uri_invalid_uri_exception_ce, "Failed to update the path", 0);
zend_throw_exception(uri_error_ce, "Failed to update the path", 0);
return FAILURE;
}
}
Expand Down Expand Up @@ -420,7 +420,7 @@ static zend_result php_uri_parser_rfc3986_query_write(void *uri, zval *value, zv
return FAILURE;
default:
/* This should be unreachable in practice. */
zend_throw_exception(uri_invalid_uri_exception_ce, "Failed to update the query", 0);
zend_throw_exception(uri_error_ce, "Failed to update the query", 0);
return FAILURE;
}
}
Expand Down Expand Up @@ -457,7 +457,7 @@ static zend_result php_uri_parser_rfc3986_fragment_write(void *uri, zval *value,
return FAILURE;
default:
/* This should be unreachable in practice. */
zend_throw_exception(uri_invalid_uri_exception_ce, "Failed to update the fragment", 0);
zend_throw_exception(uri_error_ce, "Failed to update the fragment", 0);
return FAILURE;
}
}
Expand All @@ -484,7 +484,7 @@ php_uri_parser_rfc3986_uris *php_uri_parser_rfc3986_parse_ex(const char *uri_str
break;
default:
/* This should be unreachable in practice. */
zend_throw_exception(uri_invalid_uri_exception_ce, "Failed to parse the specified URI", 0);
zend_throw_exception(uri_error_ce, "Failed to parse the specified URI", 0);
break;
}
}
Expand All @@ -506,7 +506,7 @@ php_uri_parser_rfc3986_uris *php_uri_parser_rfc3986_parse_ex(const char *uri_str
break;
default:
/* This should be unreachable in practice. */
zend_throw_exception(uri_invalid_uri_exception_ce, "Failed to resolve the specified URI against the base URI", 0);
zend_throw_exception(uri_error_ce, "Failed to resolve the specified URI against the base URI", 0);
break;
}
}
Expand Down