Skip to content

Commit a24f551

Browse files
arogachevvjik
andauthored
Reuse negation character (#746)
* Revert "Revert "Change type of `$escape` argument in `Error::getValuePath()` from `bool|string|null` to `string|null`"" This reverts commit c5a2b49. * Use negation character constant from network utilities package in `IpHandler` * Update CHANGELOG.md [skip ci] * Update CHANGELOG.md Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru> --------- Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
1 parent abc0bd9 commit a24f551

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
## 2.1.0 under development
44

55
- Enh #740: Use `Yiisoft\NetworkUtilities\IpRanges` in `Ip` rule: add `getIpRanges()` method and deprecate
6-
`getRanges()`, `getNetworks()`, `isAllowed()` methods (@vjik)
6+
`getRanges()`, `getNetworks()`, `isAllowed()` methods (@vjik)
7+
- Enh #746: Use `NEGATION_CHARACTER` constant from `network-utilities` package in `IpHandler` instead of declaring its own
8+
constant (@arogachev)
79

810
## 2.0.0 August 02, 2024
911

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"psr/http-message": "^1.0|^2.0",
3434
"yiisoft/arrays": "^2.1|^3.0",
3535
"yiisoft/friendly-exception": "^1.0",
36-
"yiisoft/network-utilities": "^1.1",
36+
"yiisoft/network-utilities": "^1.2",
3737
"yiisoft/strings": "^2.1",
3838
"yiisoft/translator": "^2.1|^3.0"
3939
},

src/Rule/IpHandler.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use InvalidArgumentException;
88
use Yiisoft\NetworkUtilities\IpHelper;
9+
use Yiisoft\NetworkUtilities\IpRanges;
910
use Yiisoft\Validator\Exception\UnexpectedRuleException;
1011
use Yiisoft\Validator\Result;
1112
use Yiisoft\Validator\RuleHandlerInterface;
@@ -21,14 +22,6 @@
2122
*/
2223
final class IpHandler implements RuleHandlerInterface
2324
{
24-
/**
25-
* Negation character.
26-
*
27-
* Used to negate {@see $ranges} or {@see $network} or to negate value validated when {@see $allowNegation}
28-
* is used.
29-
*/
30-
private const NEGATION_CHARACTER = '!';
31-
3225
public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result
3326
{
3427
if (!$rule instanceof Ip) {
@@ -82,7 +75,7 @@ public function validate(mixed $value, RuleInterface $rule, ValidationContext $c
8275
private static function getIpParsePattern(): string
8376
{
8477
return '/^(?<not>' .
85-
self::NEGATION_CHARACTER .
78+
IpRanges::NEGATION_CHARACTER .
8679
')?(?<ipCidr>(?<ip>(?:' . IpHelper::IPV4_PATTERN . ')|(?:' . IpHelper::IPV6_PATTERN . '))(?:\/(?<cidr>-?\d+))?)$/';
8780
}
8881

0 commit comments

Comments
 (0)