Download the PHP package krmgns/uuid without Composer
On this page you can find all versions of the php package krmgns/uuid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package uuid
Short Description Random or sortable UUIDs with date/time prefixes.
License Apache-2.0
Homepage https://github.com/krmgns/uuid
Informations about the package uuid
While preserving version & variant fields of generated values, Uuid library provides three types of UUIDs with a simple and fast approach, and can be used where sortable UUIDs are needed.
The generate() method of;
Uuid\Uuidclass uses 16-length random bytes (UUID/v4).Uuid\DateUuidclass uses 12-length random bytes and 4-length bytes of UTC date as prefix, and generated values are sortable up to 8th hex character.Uuid\DateTimeUuidclass uses 10-length random bytes and 6-length bytes of UTC date/time as prefix, and generated values are sortable up to 12th hex character.
Besides these UUIDs are sortable, they can be used for some sort of jobs like folder exploration (say, where we are working with an image cropping service).
So, as a quick example, let's see it in action;
Installing
Notes / Reminding
· Besides all classes can take $value argument (#1) as type of string, Uuid\Uuid class can also take type of Uuid\Uuid, Uuid\DateUuid class can also take type of Uuid\DateUuid, Uuid\DateTimeUuid class can also take type of Uuid\DateTimeUuid, but it also can be skipped for auto-generation at the same time.
· Besides Uuid\Uuid is implementing Stringable interface, Uuid\DateUuid and Uuid\DateTimeUuid are subclasses of Uuid\Uuid class. So, while inheriting some useful methods (toString(), toHashString(), etc.), they also overrides some methods (isValid(), generate(), validate() etc.) alongside __constructor() methods.
· Since Uuid\DateTimeUuid uses an instant date/time stamp up to seconds (format: YmdHis), the best sortable UUIDs can only be generated with this class.
The Uuid\Uuid Class
Like the inheriting classes, when no $value (UUID value) given, Uuid\Uuid class will generate and assign its value by itself. Otherwise, given value will be assigned after it's checked in strict mode (modifier argument is $strict as true) whether it's a valid UUID value or not.
Statics
See test/unit/UuidTest.php for more examples.
The Uuid\DateUuid Class
This class uses 12-length random bytes and 4-length bytes of UTC date as prefix. So, its date can be re-taken (eg: 20231212 or 2023-12-12 with $separator option) to use for any use case and it's usable for where sortable UUIDs are needed.
Statics
See test/unit/DateUuidTest.php for more examples.
The Uuid\DateTimeUuid Class
This class uses 10-length random bytes and 6-length bytes of UTC date/time as prefix. So, its date can be re-taken (eg: 20231212, 101122 or 2023-12-12, 10-11-22 with $separator option) to use for any use case and it's usable for where sortable UUIDs are needed.
Statics
See test/unit/DateTimeUuidTest.php for more examples.
All versions of uuid with dependencies
ext-ctype Version *