From de1aca982107e7e264335ae6ab2efb294b34f561 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Fri, 12 Apr 2024 14:57:48 +0500 Subject: [PATCH 1/4] Revert "Revert "Change type of `$escape` argument in `Error::getValuePath()` from `bool|string|null` to `string|null`"" This reverts commit c5a2b49187e1d8f5de26711b2884b0692833c370. --- CHANGELOG.md | 2 ++ UPGRADE.md | 3 +++ src/Error.php | 14 +++----------- tests/ErrorTest.php | 13 ++----------- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bd5299fe..11611fef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ (@arogachev) - Chg #679: Change type of `$rule` argument in `RuleHandlerInterface::validate()` from `object` to `RuleInterface` (@arogachev) +- Chg #613: Change type of `$escape` argument in `Error::getValuePath()` from `bool|string|null` to `string|null` + (@arogachev) ## 1.3.0 April 04, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 799648742..548c9bb55 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -27,3 +27,6 @@ for both A and B. public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result; ``` + +* The type of `$escape` argument in `Yiisoft\Validator\Error::getValuePath()` changed from `bool|string|null` to + `string|null`. If you used `bool`, replace `false` with `null` and `true` with dot (`.`). diff --git a/src/Error.php b/src/Error.php index 1b960be03..e8dd692de 100644 --- a/src/Error.php +++ b/src/Error.php @@ -106,26 +106,18 @@ public function getParameters(): array * A getter for {@see $valuePath} property. Returns a sequence of keys determining where a value caused the * validation error is located within a nested structure. * - * @param bool|string|null $escape Symbol that will be escaped with a backslash char (`\`) in path elements. + * @param string|null $escape Symbol that will be escaped with a backslash char (`\`) in path elements. * When it's null path is returned without escaping. - * Boolean value is deprecated and will be removed in the next major release. Boolean value processed in the following way: - * - `false` as null, - * - `true` as dot (`.`). * * @return array A list of keys for nested structures or an empty array otherwise. - * * @psalm-return list */ - public function getValuePath(bool|string|null $escape = false): array + public function getValuePath(string|null $escape = null): array { - if ($escape === false || $escape === null) { + if ($escape === null) { return $this->valuePath; } - if ($escape === true) { - $escape = '.'; - } - if (mb_strlen($escape) !== 1) { throw new InvalidArgumentException('Escape symbol must be exactly one character.'); } diff --git a/tests/ErrorTest.php b/tests/ErrorTest.php index 649228d6d..6e2c2af0c 100644 --- a/tests/ErrorTest.php +++ b/tests/ErrorTest.php @@ -28,19 +28,10 @@ public function dataGetValuePath(): array ['user', 'the.data😎age'], '😎', ], - - // deprecated - 'true' => [ + 'dot' => [ ['user', 'data\.age'], ['user', 'data.age'], - true, - ], - - // deprecated - 'false' => [ - ['user', 'data.age'], - ['user', 'data.age'], - false, + '.', ], ]; } From 21931f98f1e78fa16e81bbc488f0b88129e8612f Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Mon, 2 Sep 2024 20:21:48 +0500 Subject: [PATCH 2/4] Use negation character constant from network utilities package in `IpHandler` --- CHANGELOG.md | 4 +++- composer.json | 2 +- src/Rule/IpHandler.php | 11 ++--------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9f16fcd6..17d46fcfc 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) +- Chg #?: 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 9cd21acaa..c1aba53a4 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 db9231a41..f8a6963d8 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+))?)$/'; } From 54bd6fc557215fda12cf5646ba1d63231fb9ba74 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Mon, 2 Sep 2024 20:24:52 +0500 Subject: [PATCH 3/4] Update CHANGELOG.md [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17d46fcfc..44d47c4fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Enh #740: Use `Yiisoft\NetworkUtilities\IpRanges` in `Ip` rule: add `getIpRanges()` method and deprecate `getRanges()`, `getNetworks()`, `isAllowed()` methods (@vjik) -- Chg #?: Use `NEGATION_CHARACTER` constant from `network-utilities` package in `IpHandler` instead of declaring its own +- Chg #746: Use `NEGATION_CHARACTER` constant from `network-utilities` package in `IpHandler` instead of declaring its own constant (@arogachev) ## 2.0.0 August 02, 2024 From 065ff2e0d7cb49406516ad6e293a5c58e9b2efa0 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Tue, 3 Sep 2024 14:06:25 +0500 Subject: [PATCH 4/4] Update CHANGELOG.md Co-authored-by: Sergei Predvoditelev --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44d47c4fa..dcd662471 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Enh #740: Use `Yiisoft\NetworkUtilities\IpRanges` in `Ip` rule: add `getIpRanges()` method and deprecate `getRanges()`, `getNetworks()`, `isAllowed()` methods (@vjik) -- Chg #746: Use `NEGATION_CHARACTER` constant from `network-utilities` package in `IpHandler` instead of declaring its own +- 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