Commit Graph

135 Commits

Author SHA1 Message Date
Ben Ramsey ae247f1dcd chore: clean up types and PHP 8-ify the code 2022-09-15 22:14:04 -05:00
Ben Ramsey 685c2f3f23 feat: support max UUIDs 2022-09-14 20:44:24 -05:00
Ben Ramsey 4f4deb1dd6 feat: add UUIDv7 documentation and customization 2022-09-14 18:21:10 -05:00
Ben Ramsey aa1e488afa feat: support version 7 (Unix Epoch time) UUIDs 2022-09-13 22:13:33 -05:00
Ben Ramsey 078feed166 chore: update nomenclature 2022-09-12 20:56:42 -05:00
Ben Ramsey b78bcda2d1 feat: move UuidV6 to the Rfc4122 namespace 2022-09-12 19:41:46 -05:00
Ben Ramsey 89905d1948 chore: remove deprecation notices 2022-09-12 19:41:45 -05:00
Ben Ramsey 2083110316 feat: deprecate variant and version constants 2022-08-12 20:18:40 -05:00
George Steel b4dff559ab Assert non-empty-string when UUID is valid (#410)
* Assert, for psalm, the string is non-empty if validation passes
* Adds a test for SA asserting that valid string are also non-empty
* Suppress PHPStan error for unsupported conditional type assertion
* Check SA tools don't complain about non-empty-string as input parameter to `Uuid::isValid()`
2022-08-09 10:04:36 -05:00
Ben Ramsey 7b3eaf32c7 Deprecate Uuid::setFactory() and Uuid::getFactory() 2022-08-05 17:34:18 -05:00
Ben Ramsey 55693967d7 Deprecate direct instantiation of Ramsey\Uuid\Uuid 2022-08-05 17:28:11 -05:00
Ben Ramsey f1891183f9 Upgrade PHPStan 2022-08-05 14:46:56 -05:00
Ben Ramsey 115ec653d8 Un-deprecate UuidInterface::getUrn() 2022-03-27 20:55:27 -05:00
hubipe e3e9179f27 LazyUuidFromString for valid UUIDs in uppercase (#401) 2022-01-29 13:05:59 -06:00
Graham Campbell 2ed177534e Ignore serialization shape checking for code coverage purposes 2021-09-05 14:03:47 +01:00
Graham Campbell 0997de99a2 Add support for PHP 8.1 2021-09-05 12:41:13 +01:00
Chris Smith 8fa223b1af Fix soft BC break of Uuid::fromString()
Uses an assertion to indicate the `$uuid` variable cannot be an empty
string, satisfying docblock on `LazyUuidFromString`.
2021-08-09 12:51:40 +01:00
Ben Ramsey 06f8e67792 Merge pull request #361 from slevomat/patch-1
Serialization should not use internal codec
2021-08-06 16:25:27 -05:00
Ben Ramsey c005f69d6e chore: update package files 2021-08-06 14:05:57 -05:00
Jan Langer ef25479d05 Serialization should not use internal codec 2021-02-05 17:36:26 +01:00
Marco Pivetta a621ca9e81 Uuid::uuid3() uses impure Uuid::getFactory() API - suppressing it from purity static analysis checks 2020-07-09 14:04:20 +02:00
Marco Pivetta b805572537 Ensure that Uuid::uuidX() generators produce instances equivalent to Uuid::fromString() and Uuid::fromBytes()
With this change, `Uuid::uuid1()`, `Uuid::uuid2()` and so forth now produce a `LazyUuidFromString` instance, which
is both more memory efficient and comparable to `Uuid::fromString()` instances in other tools, such as within
PHPUnit's `Assertion::assertEqual()`, which would reject any two objects not matching each other's types.

Before this patch, `Assertion::assertEquals(Uuid::uuid5(...), Uuid::fromString(...))` would always fail due to
different subtypes produced by the two factory methods.
2020-07-09 13:57:30 +02:00
Marco Pivetta 910e3e459c Adjusted comment wording: s/string/strict (typo)
Co-authored-by: Jacob Dreesen <jacob@hdreesen.de>
2020-07-09 13:57:30 +02:00
Marco Pivetta 1f0cd71d93 Applied fixes and suppressions (sadly) to match psalm/phpstan code quality guidelines
We have a lot of deprecated API in here which shouldn't exist in first place, but that
will luckily disappear with v5.0.0 :-)
2020-07-09 13:57:30 +02:00
Marco Pivetta 1ce3f55673 Applied automated CS fixes according to project CS settings 2020-07-09 13:57:30 +02:00
Marco Pivetta 0f68910bf2 Optimized Uuid::fromBytes() de-serialization to use LazyUuidFromString where possible 2020-07-09 13:57:30 +02:00
Marco Pivetta 569e93ac4e Re-implemented Uuid::fromString() so it produces a LazyUuidFromString when possible
This should speed up `Uuid::fromString()` massively, leading to much shallower execution
paths when `toString()` and similar simplistic API is required.
2020-07-09 13:57:30 +02:00
Ben Ramsey 22ee596348 Make serialize(UuidInterface) more compact
Resolves #318
2020-07-08 15:27:19 -05:00
Ben Ramsey ba8fff1d3a Fix collection deserialization errors 2020-03-29 15:13:32 -05:00
Marco Pivetta c8e8b7b693 Marking Uuid::uuid3() as pure as well: it produces same values for same input 2020-03-23 10:18:21 +01:00
Marco Pivetta e830b23d77 Marking Uuid::uuid5() as pure: same input leads to same output, and no I/O under normal operational constraints 2020-03-23 10:18:21 +01:00
Ben Ramsey b31703e7c9 Improve documentation 2020-03-04 22:50:39 -06:00
Ben Ramsey cbd6a45a6a [ci skip] Update documentation 2020-03-01 23:59:58 -06:00
Ben Ramsey bb78f0e598 Simplify comparison algorithm 2020-03-01 16:19:40 -06:00
Ben Ramsey 19a91b7522 Add missing convenience methods for UuidV2 2020-02-29 11:29:12 -06:00
Ben Ramsey fec93008bc Accept Type\Hexadecimal for the first parameter to uuid1() 2020-02-24 14:34:40 -06:00
Ben Ramsey ab3c89fb8e Change the $node parameter from mixed to ?Hexadecimal 2020-02-24 13:44:03 -06:00
Ben Ramsey 614fc69b45 Add use statements for PHP functions 2020-02-23 16:13:31 -06:00
Ben Ramsey a8bbc2f58a Add ValidatorInterface::getPattern() and set constants to private 2020-02-23 16:12:52 -06:00
Ben Ramsey cc2bf6f8ef Support version 6 UUIDs
See the following:

* https://github.com/uuid6/uuid6-ietf-draft
* http://gh.peabody.io/uuidv6/
2020-02-22 22:41:15 -06:00
Ben Ramsey 65b0c091c0 Deprecate VALID_PATTERN, UUID_TYPE_IDENTIFIER; suggest replacements 2020-02-21 13:37:06 -06:00
Ben Ramsey f42afcecbb Rename Type\IntegerValue to Type\Integer
Rename `Type\IntegerValue` to `Type\Integer`. It was originally named
`IntegerValue` because static analysis sees `Integer` in docblock
annotations and treats it as the native `int` type. `Integer` is not a
reserved word in PHP, so it should be named `Integer` for consistency
with other types in this library. When using it, a class alias prevents
static analysis from complaining.
2020-02-21 11:59:49 -06:00
Ben Ramsey e0ff858ff6 Return Hexadecimal from getHex() and IntegerValue from getInteger() 2020-02-21 01:40:14 -06:00
Marco Pivetta a252f29847 Import used functions and constants via use statement to disallow ambiguity for compiler/static-analysis
As documented in https://wiki.php.net/rfc/use_global_elements, the engine (by default) does a local namespace
lookup, then falls back to global namespace when first calling a global function referenced in namespaced code,
unless that function is referenced via fully qualified name (FQN).

By using the FQN, the actual symbol can be looked up at compile-time, both by the PHP engine and by static analysis
tooling, allowing for compiler (in particular) optimizations to replace known hot-path functions with specialized opcodes.

Sadly, no actual benchmark at hand: the improvements can be minimal or massive, depending on where this library is
used (tight loops being most relevant).
2020-02-03 13:15:35 -06:00
Marco Pivetta 598b47d07f Refining type of producing a string that can be declared as non-empty-string 2020-02-03 11:05:36 -06:00
Ben Ramsey 5fa4eb4f17 Add fromDateTime() to create version 1 UUIDs from DateTime instances
Fixes #28
2020-02-03 00:48:41 -06:00
Ben Ramsey 59dc5bf06d Move deprecated methods to DeprecatedUuidMethodsTrait 2020-01-18 14:57:05 -06:00
Ben Ramsey 268e66aad8 Add static Uuid::uuid2() method 2020-01-18 14:14:47 -06:00
Ben Ramsey 72a2312f62 Support generation of version 2 (DCE Security) UUIDs 2020-01-18 12:14:01 -06:00
Ben Ramsey 0cfd017034 Mark more methods on UuidInterface and Uuid for deprecation 2020-01-18 12:14:01 -06:00