Skip to content

[Validator] Add SemVer constraint for semantic versioning validation #60995

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 28 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
74b2af6
[Validator] Add SemVer constraint for semantic versioning validation
OskarStark Jun 30, 2025
5a1aa4a
Add newlines at EOF and improve code formatting
OskarStark Jun 30, 2025
2ac6a74
Import DataProvider attribute and use short syntax
OskarStark Jun 30, 2025
1e3e416
fix
OskarStark Jun 30, 2025
bf610d8
-
OskarStark Jun 30, 2025
94fd2ac
Fix SemVer validation pattern and tests
OskarStark Jun 30, 2025
949d5e9
Simplify SemVer constraint to use single 'strict' option
OskarStark Jul 1, 2025
c287e8d
Update src/Symfony/Component/Validator/Constraints/SemVerValidator.php
OskarStark Jul 1, 2025
4e5ec8b
Change default value of strict option to true
OskarStark Jul 1, 2025
a1e9e3a
Remove array-based configuration support from SemVer constraint
OskarStark Jul 1, 2025
980da3b
Remove unnecessary comment
OskarStark Jul 1, 2025
24ae6af
Use x modifier for regex patterns to improve readability
OskarStark Jul 1, 2025
29fa35a
Apply stof's suggestions for better compatibility
OskarStark Jul 1, 2025
a1150a8
Apply suggestions from code review
OskarStark Jul 1, 2025
16a50f5
Update src/Symfony/Component/Validator/Constraints/SemVer.php
OskarStark Jul 2, 2025
eb7cb3a
Add min/max version constraints to SemVer validator
OskarStark Jul 2, 2025
c662126
Rename tooHighMessage/tooLowMessage to minMessage/maxMessage and make…
OskarStark Jul 2, 2025
b944f69
Update src/Symfony/Component/Validator/Tests/Constraints/SemVerValida…
OskarStark Jul 2, 2025
2481bab
Move expectException calls directly before the code that triggers the…
OskarStark Jul 2, 2025
ccf6364
Add tests for custom message, minMessage and maxMessage
OskarStark Jul 2, 2025
5fc3119
Follow Symfony constraint pattern: initialize message properties with…
OskarStark Jul 2, 2025
7b2c9d2
Update src/Symfony/Component/Validator/Tests/Constraints/SemVerValida…
OskarStark Jul 3, 2025
dd3a772
Update src/Symfony/Component/Validator/Tests/Constraints/SemVerValida…
OskarStark Jul 3, 2025
bcd66da
Remove unnecessary comments as requested in code review
OskarStark Jul 3, 2025
f87dff0
Apply code review feedback from fabpot and nicolas-grekas
OskarStark Jul 7, 2025
2af8ece
Add documentation for SemVer constraint options
OskarStark Jul 7, 2025
8d04e1e
Refactor SemVer constraint to use non-nullable constructor arguments
OskarStark Jul 8, 2025
09dbe1c
Fix parameter order: keep nullable parameters at the end
OskarStark Jul 8, 2025
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
Prev Previous commit
Next Next commit
Remove unnecessary comments as requested in code review
As per Alex Daubois's review comments, removed explanatory comments
that were deemed unnecessary for clean, self-documenting code.
  • Loading branch information
OskarStark committed Jul 8, 2025
commit bcd66da700d61e28d285c657b4be1a56fee332ac
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ public function validate(mixed $value, Constraint $constraint): void
return;
}

// Normalize the version for comparison (remove 'v' prefix if present)
$normalizedValue = $this->normalizeVersion($value);

// Check min constraint
if (null !== $constraint->min) {
$normalizedMin = $this->normalizeVersion($constraint->min);

Expand All @@ -120,7 +118,6 @@ public function validate(mixed $value, Constraint $constraint): void
}
}

// Check max constraint
if (null !== $constraint->max) {
$normalizedMax = $this->normalizeVersion($constraint->max);

Expand All @@ -144,13 +141,10 @@ public function validate(mixed $value, Constraint $constraint): void
*/
private function normalizeVersion(string $version): string
{
// Remove 'v' prefix if present
$version = ltrim($version, 'v');

// Split into parts
$parts = explode('.', explode('-', explode('+', $version)[0])[0]);

// Ensure we have at least 3 parts for version_compare
while (count($parts) < 3) {
$parts[] = '0';
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy