nikolaposa / version

♈ Value Object that represents a SemVer-compliant version number.
MIT License
139 stars 10 forks source link

Changing version comparator #22

Closed dontub closed 5 years ago

dontub commented 5 years ago

In version 2 it is possible to change the version comparator via Version::setComparator(). This method was removed in version 3. I would highly appreciate if it comes back. Is that possible?

nikolaposa commented 5 years ago

I thought that custom comparison strategies would be so rare, which is why I decided to remove that ugly static method, but still when a user wants to roll custom one, they could still do the comparison like so: $customComparator->compare($version1, $version2).

But I do get your point, you would prefer to perform comparison through Version class API. Can you show me some example where you would find it very useful?

dontub commented 5 years ago

I have the number of commits since the last git tag in the build part. So I additionally compare the build part if the previous parts are equal. For me it is very useful to just call Version::setComparator() once in the bootstrap file and to use the Version class API then. It also ensures that the use of the custom comparator cannot be forgotten (neither by me nor by others).

nikolaposa commented 5 years ago

Ok, can you make a PR for Version::setComparator() functionality, and then I'll consider it for 3.2.0?

nikolaposa commented 5 years ago

FYI I'll give it a few more days before releasing 3.2.0, but I've updated Composer branch alias to 3.2.x so you can already pull it into your project (https://getcomposer.org/doc/articles/aliases.md#branch-alias).

dontub commented 5 years ago

Thanks.

dontub commented 5 years ago

An update at packagist.org would be nice :)

nikolaposa commented 5 years ago

Done, thanks for a reminder!