Repository navigation
Added
- Breaking: Add
microtime()andgetMyPid()toRamsey\Identifier\Service\Os\Os.microtime()returns the current time as a float of seconds, andgetMyPid()returns the identifier of the current process, orfalsewhen it cannot be read. An implementation ofOsmust have both. - Add
getSortKey()to every identifier. It returns a string of bytes that places the identifier in order among other identifiers. A Microsoft GUID's sort key is in RFC 9562 layout, so it differs from the bytestoBytes()returns. - Add
Ramsey\Identifier\Exception\NotConvertible, whichgetDateTime()throws when an identifier cannot return a date-time. - Add
Ramsey\Identifier\Service\Cache\InvalidCacheArgument, which implements the PSR-16InvalidArgumentException.InMemoryCachethrows it for a key that is not a string, for keys or values that are not iterable, and for a TTL that is notnull, an integer, or aDateInterval. - Add
Ramsey\Identifier\Service\BytesGenerator\TimeSourceFailure.MonotonicBytesGenerator::bytes()throws it when the current time is after 10889-08-02 05:31:50.655 UTC, when the current time is before 1970-01-01 and no earlier call gave the generator a time to continue from, when the operating system service returns a value that is not a time, and when the timestamp would have to move past the last millisecond. - Add
Ramsey\Identifier\Service\BytesGenerator\RandomSourceFailure.MonotonicBytesGenerator::bytes()throws it when the bytes generator it was given returns a different number of bytes than it was asked for. - Add a third constructor parameter to
MonotonicBytesGenerator, theOsservice it reads the system time and the process identifier from. It defaults toPhpOs.
Changed
- Breaking: Require identifier/identifier
^0.6.1. - Breaking: Four exceptions are in the namespace of the code that throws them:
Ramsey\Identifier\Service\Nic\MacAddressNotFound,Ramsey\Identifier\Service\Os\MissingFunction,Ramsey\Identifier\Service\Dce\DceIdentifierNotFound, andRamsey\Identifier\Uuid\CannotDetermineVersion. Each was inRamsey\Identifier\Exception. - Breaking:
PhpOsandMd5Hashare final, as the other service classes are. - Breaking:
PhpOs::run()passes the command to the shell as written and does not escape it, so shell syntax such as a pipe has its usual meaning. A caller that adds an argument from outside the program must escape it. - Breaking:
Ramsey\Identifier\Exception\NotComparableextendsRamsey\Identifier\Exception\InvalidArgumentin place ofRuntimeException. - Breaking:
compareTo()given anyIdentifier\Identifiercompares the two sort keys and does not throw. - Breaking:
compareTo()throwsNotComparablefornull, numbers, booleans, objects that are neither identifiers norStringable, and strings (orStringableobjects) not in the identifier's own string form, including raw bytes and bare hexadecimal strings. - Breaking:
equals()returnstrueonly for an identifier of the same kind (UUID, ULID, or snowflake) with the same sort key, or a string in the identifier's own string form with the same value; a UUID and a ULID with the same bytes are not equal. - Breaking: The snowflake classes and factories refuse a string with a leading zero, such as
0123. - Breaking:
createFromInteger()on every UUID factory and on the ULID factory refuses a string that is not decimal digits with no sign and no leading zero, such as an empty string,+1,-0,0123,1.0, or1e3. - Breaking:
toUuid()on a ULID returns anUntypedUuidwith the same bytes as the ULID. CalltoTypedUuid()on it to get a typed UUID, such asUuidV7orNonstandardUuid. - Breaking:
UntypedUuidandNonstandardUuidread a byte string in RFC 9562 layout, whatever its variant, so the bytes have the version and the value their string form shows. UseMicrosoftGuidorMicrosoftGuidFactoryfor bytes in Microsoft GUID byte order; whentoTypedUuid()returns aMicrosoftGuidfor bytes of the Microsoft variant, itstoBytes()is in GUID byte order. - Breaking: A version 3 or 5 UUID created from a
MicrosoftGuidnamespace hashes the namespace by its value in RFC 9562 layout, so it is the same UUID as one created from the namespace's string form; a version 3 or 5 UUID stored from aMicrosoftGuidnamespace by an earlier release differs. - Breaking:
UlidFactory::createFromUuid()given aMicrosoftGuidreturns a ULID with the GUID's value, the same value as its string form; a ULID created from aMicrosoftGuidby an earlier release differs. - Breaking: The bytes
MonotonicBytesGeneratorreturns have a new layout: 48 bits of milliseconds, 4 bits at zero, a 12-bit fraction of the millisecond, 2 bits at zero, and a 62-bit counter that starts at a random value. A version 7 UUID or a ULID created for a given time has different bytes after its first 48 bits, and version 7 UUIDs and ULIDs sort by creation time to about a microsecond.getDateTime()returns the time to the millisecond. - Require PHP 8.3 or later.
- Support brick/math
^0.14.2 || ^0.15 || ^0.16 || ^0.17 || ^0.18 || ^0.19 || ^0.20 || ^1.0. - Support psr/simple-cache
^1.0 || ^2.0 || ^3.0. Uuid,Ulid, andSnowflakenow extendIdentifier\StringIdentifier,JsonSerializable, andStringable.getDateTime()onMicrosoftGuidandUntypedUuidthrowsNotConvertiblefor a UUID that has no date-time. It extendsBadMethodCall, so code that catchesBadMethodCallis unaffected.getDateTime()on a version 1, 2, or 6 UUID whose timestamp is not a whole number of microseconds rounds to the nearest microsecond, with a half rounded up, on both sides of the Unix Epoch.PhpOschecks forshell_exec(),file_get_contents(),glob(), andis_readable()when the method that needs each one is called, and that method throwsMissingFunction. Its constructor throws nothing, soSystemNic,SystemDce, andUuidV2Factorycan be created on a system that disables one of these functions.- When a PHP function it needs is not available,
SystemNicgoes on to its next way of finding the address, ending with a random address, andSystemDcethrowsDceIdentifierNotFound. toUuidV7()on a ULID created byUlidFactorywith its default bytes generator returns the version 7 UUID with the same timestamp, fraction, and counter.- A
MonotonicBytesGeneratorcreated with a clock other thanSystemClockkeeps its own timestamp and counter. Generators created withSystemClockshare one. MonotonicBytesGeneratorasks the bytes generator it was given for 8 bytes for each new counter, for 64 bytes for every 21 times a counter increases, and, when more than 16 bytes are wanted, for the bytes beyond 16.MonotonicBytesGenerator::bytes()throwsTimeSourceFailurewhen the current time is after 10889-08-02 05:31:50.655 UTC, or is before 1970-01-01 and no earlier call gave the generator a time to continue from.UuidV7Factory::create()andUlidFactory::create()can throw it.
Fixed
createFromInteger()andtoInteger()on UUIDs and ULIDs keep the exact value of an integer just abovePHP_INT_MAX, such as9223372036854775808.UuidFactory::createFromInteger()given an integer greater than 128 bits throwsInvalidArgumentwith a message that names the integer.- Unserializing an identifier whose serialized data has a value of the wrong type, or no value, throws
InvalidArgumentin place of a PHPTypeError. - Identifiers whose bytes look like numbers to PHP compare by their bytes, not as numbers.
- GUIDs sort in the order of their string form.
- An
UntypedUuidcreated from bytes of the Microsoft variant is equal to theMicrosoftGuidthattoTypedUuid()returns, and the two have the same string form. UlidFactory::createFromUuid()given aMicrosoftGuidreturns a ULID with the GUID's value, so the two compare as equal.UuidV3FactoryandUuidV5Factorygiven aMicrosoftGuidnamespace create the same UUID as for any other UUID with the same string form.- A version 1, 2, or 6 UUID, or a snowflake, created from a date-time before the Unix Epoch that has a fraction of a second has that date-time.
getDateTime()on a snowflake whose epoch offset puts the date-time out of range throwsNotConvertiblein place of a PHP error.getDateTime()on a snowflake returns the right date-time when the date-time is less than one second before the Unix Epoch.GenericSnowflakeFactory::createFromDateTime()with a negative epoch offset names the factory's epoch and its latest date-time correctly in the exceptions it throws, in place of a PHP error.GenericSnowflakeFactory::createFromDateTime()throwsInvalidArgumentfor a date-time too far from the Unix Epoch to count in milliseconds, in place of a snowflake with a wrong timestamp.- A snowflake value above the largest unsigned 64-bit integer was accepted when written with a leading zero.
MastodonSnowflakeFactorythrowsInvalidArgumentwhen its sequence returns anything other than an integer or a decimal string that fits in an integer.- A date-time passed to
UuidV7Factory::create(),UuidV7Factory::createFromDateTime(), orUlidFactory::createFromDateTime()does not change the identifiers created after it without one; they have the current time. - A parent process and a child process create different version 7 UUIDs and ULIDs after a fork.
- A version 7 UUID created without a date-time is always greater than the one created before it in the same process.
MonotonicBytesGenerator::bytes()given a date-time before 1970-01-01 or after 10889-08-02 05:31:50.655 UTC throwsInvalidArgument, in place of bytes with a wrong timestamp.MonotonicBytesGeneratorrefuses a bytes generator that returns the wrong number of bytes, withRandomSourceFailure, in place of PHP warnings and wrong bytes.MonotonicBytesGeneratorthrowsTimeSourceFailurewhen its counter would move the timestamp past 10889-08-02 05:31:50.655 UTC, in place of bytes with a wrong timestamp.MonotonicBytesGeneratorreturns the same bytes on big-endian and little-endian machines for the same time and the same random bytes.- The amounts by which
MonotonicBytesGeneratorincreases a counter cannot be worked out from identifiers it created earlier. bytes()onFixedBytesGenerator,MonotonicBytesGenerator, andRandomBytesGeneratorthrowsInvalidArgumentfor a length less than 1, in place of an empty string, the wrong number of bytes, or a PHPValueError.MonotonicSequencedoes not raise a deprecation on PHP 8.6. A call without a state keeps its value on the instance and does not use the cache, so a new sequence does not continue from an earlier sequence's value, and a sequence does not return to its start value when a cache entry expires.MonotonicSequence::next()throwsSequenceOverflowonly when the step would move the sequence past the limit in the step's own direction, so a rising sequence can start at or nearPHP_INT_MIN. A step ofPHP_INT_MINthat would pass the minimum throwsSequenceOverflow.Rfc4122ClockSequencecompares date-times before the Unix Epoch that have a fraction of a second in the right order, so its sequence rises only when the date-time moves backward.InMemoryCacheevicts the least recently used item when its clock is before the Unix Epoch.InMemoryCachehandles keys that look like integers, such as123, insetMultiple()and when it evicts an item, in place of a PHPTypeError.SystemDce::groupId()returns a group identifier on Windows. It is the lowest relative identifier among the built-in groups of the running user, or, for a user in no built-in group, the lowest among the user's machine and domain groups.SystemNicdoes not take part of a longer value, such as a DHCPv6 identifier in the output ofipconfig /all, for a hardware address.
Full Changelog: 0.1.0...0.2.0