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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ PHP NEWS

- Intl:
. Added IntlNumberFormatter::toSkeleton(). (Weilin Du)
. Added Spoofchecker::getChecks() and Spoofchecker::getAllowedLocales().
(Weilin Du)
. Added Spoofchecker::getRestrictionLevel(). (Weilin Du)
. Added Collator::getRules() and collator_get_rules(). (Weilin Du)
. Added IntlRelativeDateTimeFormatter for locale-aware relative date and time
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ PHP 8.7 UPGRADE NOTES
the rules cannot be converted to UTF-8.
. Added IntlNumberFormatter::toSkeleton() to export the formatter settings
as a normalized, locale-independent ICU number skeleton.
. Added Spoofchecker::getChecks() to retrieve the enabled checks as a bitmask
and Spoofchecker::getAllowedLocales() to retrieve the configured locale list.
. Added Spoofchecker::getRestrictionLevel() to retrieve the configured
restriction level as one of the Spoofchecker restriction level constants.

Expand Down
4 changes: 4 additions & 0 deletions ext/intl/spoofchecker/spoofchecker.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ public function areConfusable(string $string1, string $string2, &$errorCode = nu
/** @tentative-return-type */
public function setAllowedLocales(string $locales): void {}

public function getAllowedLocales(): string {}

/** @tentative-return-type */
public function setChecks(int $checks): void {}

public function getChecks(): int {}

/** @tentative-return-type */
public function setRestrictionLevel(int $level): void {}

Expand Down
15 changes: 12 additions & 3 deletions ext/intl/spoofchecker/spoofchecker_arginfo.h

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

38 changes: 38 additions & 0 deletions ext/intl/spoofchecker/spoofchecker_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ PHP_METHOD(Spoofchecker, setAllowedLocales)
}
/* }}} */

/* {{{ Get the configured list of allowed locales. */
PHP_METHOD(Spoofchecker, getAllowedLocales)
{
SPOOFCHECKER_METHOD_INIT_VARS;

ZEND_PARSE_PARAMETERS_NONE();

SPOOFCHECKER_METHOD_FETCH_OBJECT;

const char *locales = uspoof_getAllowedLocales(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co));
if (UNEXPECTED(locales == nullptr)) {
intl_error_set_code(nullptr, SPOOFCHECKER_ERROR_CODE(co));
zend_throw_exception(IntlException_ce_ptr, "Failed to retrieve allowed locales", 0);
RETURN_THROWS();
}
RETURN_STRING(locales);
}
/* }}} */

/* {{{ Set the checks to run */
PHP_METHOD(Spoofchecker, setChecks)
{
Expand All @@ -137,6 +156,25 @@ PHP_METHOD(Spoofchecker, setChecks)
}
/* }}} */

/* {{{ Get the enabled checks as a bitmask. */
PHP_METHOD(Spoofchecker, getChecks)
{
SPOOFCHECKER_METHOD_INIT_VARS;

ZEND_PARSE_PARAMETERS_NONE();

SPOOFCHECKER_METHOD_FETCH_OBJECT;

int32_t checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co));
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
intl_error_set_code(nullptr, SPOOFCHECKER_ERROR_CODE(co));
zend_throw_exception(IntlException_ce_ptr, "Failed to retrieve enabled checks", 0);
RETURN_THROWS();
}
RETURN_LONG(checks);
}
/* }}} */

/* TODO Document this method on PHP.net */
/* {{{ Set the loosest restriction level allowed for strings. */
PHP_METHOD(Spoofchecker, setRestrictionLevel)
Expand Down
34 changes: 34 additions & 0 deletions ext/intl/tests/spoofchecker_get_checks_and_allowed_locales.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Spoofchecker::getChecks() and getAllowedLocales() reflect changes to the checker
--EXTENSIONS--
intl
--FILE--
<?php
$checker = new Spoofchecker();
var_dump($checker->getAllowedLocales());

$checker->setChecks(Spoofchecker::INVISIBLE);
var_dump($checker->getChecks() === Spoofchecker::INVISIBLE);

$checker->setAllowedLocales('en');
$locales = $checker->getAllowedLocales();
var_dump($checker->getChecks() === (Spoofchecker::INVISIBLE | Spoofchecker::CHAR_LIMIT));

$checker->setAllowedLocales('');
var_dump($checker->getAllowedLocales(), $locales);
var_dump($checker->getChecks() === Spoofchecker::INVISIBLE);

$checker->setChecks(0);
var_dump($checker->getChecks());
$checker->setAllowedChars('[a-z]');
var_dump($checker->getChecks() === Spoofchecker::CHAR_LIMIT);
?>
--EXPECT--
string(0) ""
bool(true)
bool(true)
string(0) ""
string(2) "en"
bool(true)
int(0)
bool(true)
21 changes: 21 additions & 0 deletions ext/intl/tests/spoofchecker_get_settings_unconstructed.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Spoofchecker::getChecks() and getAllowedLocales() reject an unconstructed object
--EXTENSIONS--
intl
--FILE--
<?php
$checker = new class extends Spoofchecker {
public function __construct() {}
};

foreach (['getChecks', 'getAllowedLocales'] as $method) {
try {
$checker->$method();
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
}
?>
--EXPECT--
Found unconstructed Spoofchecker
Found unconstructed Spoofchecker
Loading