Download the PHP package mastersteelblade/discriminator without Composer
On this page you can find all versions of the php package mastersteelblade/discriminator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mastersteelblade/discriminator
More information about mastersteelblade/discriminator
Files in mastersteelblade/discriminator
Package discriminator
Short Description A simple package to handle basic discriminator manipulation for user management.
License MIT
Homepage https://github.com/MasterSteelblade/php-discriminator
Informations about the package discriminator
Discriminator
| Branch | GitHub Actions | Coverage |
|---|---|---|
| main | ||
| dev |
About
This is a simple utility class to allow developers to implement discriminators on users, similar to Discord. This allows multiple users to share the same nickname, while allowing accounts to be tied to, for example, email addresses for uniqueness.
Installation using Composer
Usage
Discriminator is very simple to use. Below are some examples, but first, make things easier on yourself:
If you use another package that has a class of the same name, substitute the classes below with the full namespace.
Generate a discriminator
Generating a discriminator can be done in one of two ways. First, you can simply create an object without passing a parameter in.
As no parameter has been passed, it will generate one automatically, in a range of 0 to 9999 inclusive.
You can then, if disired, get the integer value using
Alternatively, to generate a discriminator without instantiating, a static method exists to return an integer value.
Loading a user from a database
Lets say a you want to display a profile page for a user, and you retrieve their information from a database.
The discriminator reads the numeric value, and creates itself accordingly.
Displaying a discriminator
Discriminators can be included in strings. For example:
Representations of discriminators add leading zeroes to make the length consistent.
You can also retrieve the string value statically, by providing an integer value:
License
Discriminator is provided under the MIT license.