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
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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.
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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
Expand Down
3 changes: 3 additions & 0 deletions ext/intl/spoofchecker/spoofchecker.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
7 changes: 6 additions & 1 deletion ext/intl/spoofchecker/spoofchecker_arginfo.h

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

13 changes: 13 additions & 0 deletions ext/intl/spoofchecker/spoofchecker_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions ext/intl/tests/spoofchecker_get_restriction_level.phpt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
Loading