Commit e8140351d7e for php
commit e8140351d7e04d36fa951484eb1470567ec914c4
Author: Weilin Du <weilindu@php.net>
Date: Fri Nov 13 00:36:50 2026 +0800
ext/intl: Add Spoofchecker::getRestrictionLevel() (#25422)
Expose ICU's uspoof_getRestrictionLevel() to retrieve the currently
configured restriction level as a Spoofchecker restriction level constant.
diff --git a/NEWS b/NEWS
index 5acaf162608..a0bce4ed6f4 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,7 @@ PHP NEWS
throwing a ValueError. (Marc Bennewitz)
- Intl:
+ . Added Spoofchecker::getRestrictionLevel(). (Weilin Du)
. Added Collator::getRules() and collator_get_rules(). (Weilin Du)
. Added IntlRelativeDateTimeFormatter for locale-aware relative date and time
formatting, with enums for styles, capitalization contexts, and units.
diff --git a/UPGRADING b/UPGRADING
index 3fc692ac9ac..d9242ecb3c1 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -134,6 +134,8 @@ PHP 8.7 UPGRADE NOTES
to the root collation order; the full root/UCA rules are not included. An
empty string is returned if no tailoring rules are available, or false if
the rules cannot be converted to UTF-8.
+ . Added Spoofchecker::getRestrictionLevel() to retrieve the configured
+ restriction level as one of the Spoofchecker restriction level constants.
========================================
7. New Classes and Interfaces
diff --git a/ext/intl/spoofchecker/spoofchecker.stub.php b/ext/intl/spoofchecker/spoofchecker.stub.php
index 160ad63128b..0232f5ccbe4 100644
--- a/ext/intl/spoofchecker/spoofchecker.stub.php
+++ b/ext/intl/spoofchecker/spoofchecker.stub.php
@@ -78,6 +78,9 @@ public function setChecks(int $checks): void {}
/** @tentative-return-type */
public function setRestrictionLevel(int $level): void {}
+
+ public function getRestrictionLevel(): int {}
+
public function setAllowedChars(string $pattern, int $patternOptions = 0): void {}
public function getSkeleton(string $string): string|false {}
diff --git a/ext/intl/spoofchecker/spoofchecker_arginfo.h b/ext/intl/spoofchecker/spoofchecker_arginfo.h
index 236a292767c..550096605ea 100644
Binary files a/ext/intl/spoofchecker/spoofchecker_arginfo.h and b/ext/intl/spoofchecker/spoofchecker_arginfo.h differ
diff --git a/ext/intl/spoofchecker/spoofchecker_main.cpp b/ext/intl/spoofchecker/spoofchecker_main.cpp
index 8caa5e345aa..cbadf6f3d1b 100644
--- a/ext/intl/spoofchecker/spoofchecker_main.cpp
+++ b/ext/intl/spoofchecker/spoofchecker_main.cpp
@@ -166,6 +166,19 @@ PHP_METHOD(Spoofchecker, setRestrictionLevel)
}
/* }}} */
+/* {{{ Get the configured restriction level. */
+PHP_METHOD(Spoofchecker, getRestrictionLevel)
+{
+ SPOOFCHECKER_METHOD_INIT_VARS;
+
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ SPOOFCHECKER_METHOD_FETCH_OBJECT;
+
+ RETURN_LONG(uspoof_getRestrictionLevel(co->uspoof));
+}
+/* }}} */
+
PHP_METHOD(Spoofchecker, setAllowedChars)
{
zend_string *pattern;
diff --git a/ext/intl/tests/spoofchecker_get_restriction_level.phpt b/ext/intl/tests/spoofchecker_get_restriction_level.phpt
new file mode 100644
index 00000000000..8490fbb1237
--- /dev/null
+++ b/ext/intl/tests/spoofchecker_get_restriction_level.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Spoofchecker::getRestrictionLevel() returns the configured restriction level
+--EXTENSIONS--
+intl
+--FILE--
+<?php
+$checker = new Spoofchecker();
+var_dump($checker->getRestrictionLevel() === Spoofchecker::HIGHLY_RESTRICTIVE);
+
+foreach ([
+ Spoofchecker::ASCII,
+ Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE,
+ Spoofchecker::HIGHLY_RESTRICTIVE,
+ Spoofchecker::MODERATELY_RESTRICTIVE,
+ Spoofchecker::MINIMALLY_RESTRICTIVE,
+ Spoofchecker::UNRESTRICTIVE,
+] as $level) {
+ $checker->setRestrictionLevel($level);
+ var_dump($checker->getRestrictionLevel() === $level);
+}
+
+// Disabling checks does not change the configured restriction level.
+$checker->setRestrictionLevel(Spoofchecker::ASCII);
+$checker->setChecks(0);
+var_dump($checker->getRestrictionLevel() === Spoofchecker::ASCII);
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/intl/tests/spoofchecker_get_restriction_level_unconstructed.phpt b/ext/intl/tests/spoofchecker_get_restriction_level_unconstructed.phpt
new file mode 100644
index 00000000000..35317eb3553
--- /dev/null
+++ b/ext/intl/tests/spoofchecker_get_restriction_level_unconstructed.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Spoofchecker::getRestrictionLevel() rejects an unconstructed object
+--EXTENSIONS--
+intl
+--FILE--
+<?php
+$checker = new class extends Spoofchecker {
+ public function __construct() {}
+};
+
+try {
+ $checker->getRestrictionLevel();
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+?>
+--EXPECT--
+Found unconstructed Spoofchecker