8000 [Validator] Add additional versions (`*_NO_PUBLIC`, `*_ONLY_PRIV` & `*_ONLY_RES`) in IP address constraint by Ninos · Pull Request #51777 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Add additional versions (*_NO_PUBLIC, *_ONLY_PRIV & *_ONLY_RES) in IP address constraint #51777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a98f828
Enhancement: Add *_ONLY_PRIV & *_ONLY_RES as possible versions in IP …
Ninos Sep 28, 2023
9551dc3
Updated: Changelog
Ninos Sep 28, 2023
2b1e888
Updated: UPGRADE-6.4.md
Ninos Sep 28, 2023
24c73a3
CS
Ninos Sep 28, 2023
2200cd8
Added: Tests for `Mac` constraint
Ninos Sep 28, 2023
3cb3119
Fixed: Tests for `Mac` constraint
Ninos Sep 28, 2023
99e03ea
Added: OnlyPrivate & OnlyReserved tests
Ninos Sep 28, 2023
c11c261
Enhancement: OnlyPrivate & OnlyReserved tests
Ninos Sep 28, 2023
12f126e
CS
Ninos Sep 28, 2023
e4e6a24
Update src/Symfony/Component/Validator/Constraints/Mac.php
Ninos Oct 5, 2023
0e6cf5e
Update src/Symfony/Component/Validator/Constraints/Ip.php
Ninos Oct 5, 2023
0b7910f
Update src/Symfony/Component/Validator/Constraints/MacValidator.php
Ninos Oct 5, 2023
719be6c
Update src/Symfony/Component/Validator/Constraints/Mac.php
Ninos Oct 5, 2023
a6eb4f2
Update src/Symfony/Component/Validator/Constraints/Mac.php
Ninos Oct 5, 2023
4b4c5e4
Update src/Symfony/Component/Validator/Constraints/Mac.php
Ninos Oct 5, 2023
9cf46fc
Update src/Symfony/Component/Validator/Constraints/Mac.php
Ninos Oct 5, 2023
9775156
CS
Ninos Oct 5, 2023
646fd5f
Removed: Mac constraint
Ninos Oct 6, 2023
26e9f2a
[Validator] Remove `Mac` constraint
Ninos Oct 6, 2023
6e84494
[Validator] Fix IpTest
Ninos Oct 6, 2023
cfff49a
[Validator] Renamed constants to full-word names
Ninos Nov 5, 2023
3f58f6b
[Validator] Renamed constants to full-word names
Ninos Nov 5, 2023
a0419db
[Validator] Possibility to use all `Ip` constraint versions in `Cidr`…
Ninos Nov 6, 2023
ed09494
[Validator] Possibility to use all `Ip` constraint versions in `Cidr`…
Ninos Nov 6, 2023
65b3184
[Validator] Possibility to use all `Ip` constraint versions in `Cidr`…
Ninos Nov 6, 2023
b066087
[Validator] Possibility to use all `Ip` constraint versions in `Cidr`…
Ninos Nov 6, 2023
1991107
[Validator] Fixed tests & added `*_NO_PUBLIC`
Ninos Nov 6, 2023
cbdd81f
[Validator] Fixed tests
Ninos Nov 6, 2023
601809c
[Validator] Added normalizer to `Cidr` + better string support
Ninos Nov 7, 2023
cc930ef
Merge branch '7.1' into constraints-networking
Ninos Nov 20, 2023
0d12319
[Validator] Small fixes
Ninos Nov 20, 2023
b58bb03
[Validator] Small fixes
Ninos Nov 20, 2023
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
8000
Diff view
Prev Previous commit
Next Next commit
[Validator] Small fixes
  • Loading branch information
Ninos committed Nov 20, 2023
commit 0d12319cd3faea080cc1b4d78a79514ec2ce12af
8 changes: 6 additions & 2 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ CHANGELOG
* Remove `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead
* Remove `AnnotationLoader`, use `AttributeLoader` instead

7.1
---

* Add `*_NO_PUBLIC`, `*_ONLY_PRIVATE` and `*_ONLY_RESERVED` versions to `Ip` constraint
* Possibility to use all `Ip` constraint versions for `Cidr` constraint

6.4
---

* Add `*_NO_PUBLIC`, `*_ONLY_PRIVATE` and `*_ONLY_RESERVED` versions to `Ip` constraint
* Possibility to use all `Ip` constraint versions for `Cidr` constraint
* Add `is_valid` function to the `Expression` constraint, its behavior is the same as `ValidatorInterface::validate`
* Allow single integer for the `versions` option of the `Uuid` constraint
* Allow single constraint to be passed to the `constraints` option of the `When` constraint
Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Component/Validator/Constraints/Cidr.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@ public function __construct(
int $netmaskMin = null,
int $netmaskMax = null,
string $message = null,
callable $normalizer = null,
array $groups = null,
$payload = null
$payload = null,
callable $normalizer = null
) {
$this->version = $version ?? $options['version'] ?? $this->version;

if (!\in_array($this->version, array_keys(self::NET_MAXES))) {
throw new ConstraintDefinitionException(sprintf('The option "version" must be one of "%s".', implode('", "', array_keys(self::NET_MAXES))));
if (!\array_key_exists($this->version, self::NET_MAXES)) {
throw new ConstraintDefinitionException(sprintf('The option "version" must be one of "%s".', implode('", "', array_keys(static::NET_MAXES))));
}

$this->netmaskMin = $netmaskMin ?? $options['netmaskMin'] ?? $this->netmaskMin;
$this->netmaskMax = $netmaskMax ?? $options['netmaskMax'] ?? self::NET_MAXES[$this->version];
$this->netmaskMax = $netmaskMax ?? $options['netmaskMax'] ?? static::NET_MAXES[$this->version];
$this->message = $message ?? $this->message;
$this->normalizer = $normalizer ?? $this->normalizer;

unset($options['ne 8000 tmaskMin'], $options['netmaskMax'], $options['version']);

if ($this->netmaskMin < 0 || $this->netmaskMax > self::NET_MAXES[$this->version] || $this->netmaskMin > $this->netmaskMax) {
throw new ConstraintDefinitionException(sprintf('The netmask range must be between 0 and %d.', self::NET_MAXES[$this->version]));
if ($this->netmaskMin < 0 || $this->netmaskMax > static::NET_MAXES[$this->version] || $this->netmaskMin > $this->netmaskMax) {
throw new ConstraintDefinitionException(sprintf('The netmask range must be between 0 and %d.', static::NET_MAXES[$this->version]));
}

if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
Expand Down
25 changes: 4 additions & 21 deletions src/Symfony/Component/Validator/Constraints/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,15 @@ class Ip extends Constraint

public const INVALID_IP_ERROR = 'b1b427ae-9f6f-41b0-aa9b-84511fbb3c5b';

/**
* @deprecated since Symfony 6.4, use const V4_NO_PRIVATE instead
*/
// BC: Aliases
public const V4_NO_PRIV = '4_no_priv';
/**
* @deprecated since Symfony 6.4, use const V6_NO_PRIVATE instead
*/
public const V6_NO_PRIV = '6_no_priv';
/**
* @deprecated since Symfony 6.4, use const ALL_NO_PRIVATE instead
*/
public const ALL_NO_PRIV = 'all_no_priv';
/**
* @deprecated since Symfony 6.4, use const 4_NO_RESERVED instead
*/
public const V4_NO_RES = '4_no_res';
/**
* @deprecated since Symfony 6.4, use const 6_NO_RESERVED instead
*/
public const V6_NO_RES = '6_no_res';
/**
* @deprecated since Symfony 6.4, use const ALL_NO_RESERVED instead
*/
public const ALL_NO_RES = 'all_no_res';

protected const DEPRECATED_VERSIONS = [
protected const ALIAS_VERSIONS = [
self::V4_NO_PRIV => self::V4_NO_PRIVATE,
self::V6_NO_PRIV => self::V6_NO_PRIVATE,
self::ALL_NO_PRIV => self::ALL_NO_PRIVATE,
Expand Down Expand Up @@ -149,8 +132,8 @@ public function __construct(
$this->message = $message ?? $this->message;
$this->normalizer = $normalizer ?? $this->normalizer;

if (isset(self::DEPRECATED_VERSIONS[$this->version])) {
$this->version = self::DEPRECATED_VERSIONS[$this->version];
if (isset(static::ALIAS_VERSIONS[$this->version])) {
$this->version = static::ALIAS_VERSIONS[$this->version];
}

if (!\in_array($this->version, static::VERSIONS, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function validate(mixed $value, Constraint $constraint): void
throw new UnexpectedValueException($value, 'string');
}

$value = (string)$value;
$value = (string) $value;

if (null !== $constraint->normalizer) {
$value = ($constraint->normalizer)($value);
Expand Down
0