Skip to content
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

Feature Request: validate string as package version for Composer #168

Open
LeTraceurSnork opened this issue Nov 21, 2024 · 2 comments
Open
Labels

Comments

@LeTraceurSnork
Copy link

Is there any plans to add functionality for checking whether the passed string is a valid package version for Composer?

@Seldaek
Copy link
Member

Seldaek commented Nov 25, 2024

You can use new VersionParser()->normalize() from https://github.com/composer/semver/blob/main/src/VersionParser.php#L108 that will throw if it's not parseable. That's the code Composer uses so it should do what you want I guess.

@LeTraceurSnork
Copy link
Author

Oh, yeah, I saw that, and yeah, I used that exactly as you proposed, tho, I find it kinda odd - instead of just checking whether or not string is a version and getting (presumably) true/false answer, you had to ->normalize() it (not obvious solution by itself), but also you had to catch an exception after it. Not so... beautiful I guess? Not so straightforward, maybe. So, wouldn't it be more convenient to add some true/false method (that maybe do exactly that ->normalize() + catch) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants