diff --git a/CHANGELOG.md b/CHANGELOG.md index b9f16fcd..dcd66247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ ## 2.1.0 under development - Enh #740: Use `Yiisoft\NetworkUtilities\IpRanges` in `Ip` rule: add `getIpRanges()` method and deprecate - `getRanges()`, `getNetworks()`, `isAllowed()` methods (@vjik) + `getRanges()`, `getNetworks()`, `isAllowed()` methods (@vjik) +- Enh #746: Use `NEGATION_CHARACTER` constant from `network-utilities` package in `IpHandler` instead of declaring its own + constant (@arogachev) ## 2.0.0 August 02, 2024 diff --git a/composer.json b/composer.json index 9cd21aca..c1aba53a 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "psr/http-message": "^1.0|^2.0", "yiisoft/arrays": "^2.1|^3.0", "yiisoft/friendly-exception": "^1.0", - "yiisoft/network-utilities": "^1.1", + "yiisoft/network-utilities": "^1.2", "yiisoft/strings": "^2.1", "yiisoft/translator": "^2.1|^3.0" }, diff --git a/src/Rule/IpHandler.php b/src/Rule/IpHandler.php index db9231a4..f8a6963d 100644 --- a/src/Rule/IpHandler.php +++ b/src/Rule/IpHandler.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use Yiisoft\NetworkUtilities\IpHelper; +use Yiisoft\NetworkUtilities\IpRanges; use Yiisoft\Validator\Exception\UnexpectedRuleException; use Yiisoft\Validator\Result; use Yiisoft\Validator\RuleHandlerInterface; @@ -21,14 +22,6 @@ */ final class IpHandler implements RuleHandlerInterface { - /** - * Negation character. - * - * Used to negate {@see $ranges} or {@see $network} or to negate value validated when {@see $allowNegation} - * is used. - */ - private const NEGATION_CHARACTER = '!'; - public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result { if (!$rule instanceof Ip) { @@ -82,7 +75,7 @@ public function validate(mixed $value, RuleInterface $rule, ValidationContext $c private static function getIpParsePattern(): string { return '/^(?' . - self::NEGATION_CHARACTER . + IpRanges::NEGATION_CHARACTER . ')?(?(?(?:' . IpHelper::IPV4_PATTERN . ')|(?:' . IpHelper::IPV6_PATTERN . '))(?:\/(?-?\d+))?)$/'; }