Skip to content

Commit 90540e5

Browse files
committed
ext/intl: Add Spoofchecker::getRestrictionLevel()
1 parent d1ec606 commit 90540e5

7 files changed

Lines changed: 78 additions & 1 deletion

‎NEWS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PHP NEWS
2525
throwing a ValueError. (Marc Bennewitz)
2626

2727
- Intl:
28+
. Added Spoofchecker::getRestrictionLevel(). (Weilin Du)
2829
. Added Collator::getRules() and collator_get_rules(). (Weilin Du)
2930
. Added IntlRelativeDateTimeFormatter for locale-aware relative date and time
3031
formatting, with enums for styles, capitalization contexts, and units.

‎UPGRADING‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ PHP 8.7 UPGRADE NOTES
129129
to the root collation order; the full root/UCA rules are not included. An
130130
empty string is returned if no tailoring rules are available, or false if
131131
the rules cannot be converted to UTF-8.
132+
. Added Spoofchecker::getRestrictionLevel() to retrieve the configured
133+
restriction level as one of the Spoofchecker restriction level constants.
132134

133135
========================================
134136
7. New Classes and Interfaces

‎ext/intl/spoofchecker/spoofchecker.stub.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public function setChecks(int $checks): void {}
7878

7979
/** @tentative-return-type */
8080
public function setRestrictionLevel(int $level): void {}
81+
82+
public function getRestrictionLevel(): int {}
83+
8184
public function setAllowedChars(string $pattern, int $patternOptions = 0): void {}
8285

8386
public function getSkeleton(string $string): string|false {}

‎ext/intl/spoofchecker/spoofchecker_arginfo.h‎

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ext/intl/spoofchecker/spoofchecker_main.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ PHP_METHOD(Spoofchecker, setRestrictionLevel)
166166
}
167167
/* }}} */
168168

169+
/* {{{ Get the configured restriction level. */
170+
PHP_METHOD(Spoofchecker, getRestrictionLevel)
171+
{
172+
SPOOFCHECKER_METHOD_INIT_VARS;
173+
174+
ZEND_PARSE_PARAMETERS_NONE();
175+
176+
SPOOFCHECKER_METHOD_FETCH_OBJECT;
177+
178+
RETURN_LONG(uspoof_getRestrictionLevel(co->uspoof));
179+
}
180+
/* }}} */
181+
169182
PHP_METHOD(Spoofchecker, setAllowedChars)
170183
{
171184
zend_string *pattern;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Spoofchecker::getRestrictionLevel() returns the configured restriction level
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
$checker = new Spoofchecker();
8+
var_dump($checker->getRestrictionLevel() === Spoofchecker::HIGHLY_RESTRICTIVE);
9+
10+
foreach ([
11+
Spoofchecker::ASCII,
12+
Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE,
13+
Spoofchecker::HIGHLY_RESTRICTIVE,
14+
Spoofchecker::MODERATELY_RESTRICTIVE,
15+
Spoofchecker::MINIMALLY_RESTRICTIVE,
16+
Spoofchecker::UNRESTRICTIVE,
17+
] as $level) {
18+
$checker->setRestrictionLevel($level);
19+
var_dump($checker->getRestrictionLevel() === $level);
20+
}
21+
22+
// Disabling checks does not change the configured restriction level.
23+
$checker->setRestrictionLevel(Spoofchecker::ASCII);
24+
$checker->setChecks(0);
25+
var_dump($checker->getRestrictionLevel() === Spoofchecker::ASCII);
26+
?>
27+
--EXPECT--
28+
bool(true)
29+
bool(true)
30+
bool(true)
31+
bool(true)
32+
bool(true)
33+
bool(true)
34+
bool(true)
35+
bool(true)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Spoofchecker::getRestrictionLevel() rejects an unconstructed object
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
$checker = new class extends Spoofchecker {
8+
public function __construct() {}
9+
};
10+
11+
try {
12+
$checker->getRestrictionLevel();
13+
} catch (Error $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
?>
17+
--EXPECT--
18+
Found unconstructed Spoofchecker

0 commit comments

Comments
 (0)