diff options
author | Max Kostikov <max@kostikov.co> | 2018-09-28 15:46:14 +0200 |
---|---|---|
committer | Max Kostikov <max@kostikov.co> | 2018-09-28 15:46:14 +0200 |
commit | 4a904fa3a8af1c101ede76657249fb7eb47faf60 (patch) | |
tree | 544509813fb68579ef2b556ce879a971d183269a /vendor/ramsey/uuid | |
parent | f5f6ec3d71acb3e0488386819d5060e59331ec23 (diff) | |
parent | c13d7e29ef9676b0f0e4ae23aa52e203f4ad8895 (diff) | |
download | volse-hubzilla-4a904fa3a8af1c101ede76657249fb7eb47faf60.tar.gz volse-hubzilla-4a904fa3a8af1c101ede76657249fb7eb47faf60.tar.bz2 volse-hubzilla-4a904fa3a8af1c101ede76657249fb7eb47faf60.zip |
Merge branch 'patch-29' into 'dev'
Patch 29
See merge request Kostikov/core!3
Diffstat (limited to 'vendor/ramsey/uuid')
52 files changed, 4859 insertions, 0 deletions
diff --git a/vendor/ramsey/uuid/CHANGELOG.md b/vendor/ramsey/uuid/CHANGELOG.md new file mode 100644 index 000000000..3965fff27 --- /dev/null +++ b/vendor/ramsey/uuid/CHANGELOG.md @@ -0,0 +1,376 @@ +# ramsey/uuid Changelog + +## 3.8.0 + +_Released: 2018-07-19_ + + * Add support for determining MAC address on FreeBSD systems ([#212](https://github.com/ramsey/uuid/pull/212)) + * Add a polyfill for PHP ctype functions to support systems where the ctype functions are not part of the PHP build ([#223](https://github.com/ramsey/uuid/pull/223)) + * Improve validation to disallow UUIDs with a trailing newline character ([#225](https://github.com/ramsey/uuid/pull/225)) + * Add annotations for thrown exceptions for improved IDE hinting ([#232](https://github.com/ramsey/uuid/pull/232)) + * Improve documentation, testing, and project metadata (i.e. `.gitattributes`, etc.) + +## 3.7.3 + +_Released: 2018-01-19_ + + * In rare cases, when using `glob()` to find `/sys/class/net/*/address` files on Linux, `glob()` encountered errors, returning `false` instead of an empty array, causing `array_map()` to emit warnings since its second parameter was not an array; this release gracefully handles cases where `glob()` returns `false` [#203](https://github.com/ramsey/uuid/issues/203) + * Fixed an off-by-one error in `DefaultTimeGenerator` and switching to `random_int()` from `mt_rand()` for better random numbers [#206](https://github.com/ramsey/uuid/pull/206) + +## 3.7.2 + +_Released: 2018-01-13_ + + * On Linux, first check sysfs to determine node identifier; this provides a reliable way to identify the node on Docker images, etc. [#185](https://github.com/ramsey/uuid/pull/185) + +## 3.7.1 + +_Released: 2017-09-22_ + + * Use `random_bytes()` when generating random nodes + * Set the multicast bit for random nodes, according to RFC 4122, ยง4.5, [#170](https://github.com/ramsey/uuid/pull/170), [#171](https://github.com/ramsey/uuid/pull/171), [#182](https://github.com/ramsey/uuid/pull/182) + +## 3.7.0 + +_Released: 2017-08-04_ + + * Add UUID version constants [#173](https://github.com/ramsey/uuid/issues/173), [#177](https://github.com/ramsey/uuid/pull/177) + * `Uuid::UUID_TYPE_TIME` + * `Uuid::UUID_TYPE_IDENTIFIER` + * `Uuid::UUID_TYPE_HASH_MD5` + * `Uuid::UUID_TYPE_RANDOM` + * `Uuid::UUID_TYPE_HASH_SHA1` + +## 3.6.1 + +_Released: 2017-03-26_ + + * Optimize UUID string decoding [#164](https://github.com/ramsey/uuid/pull/164) + +## 3.6.0 + +_Released: 2017-03-18_ + + * Add `InvalidUuidStringException`, thrown when attempting to decode an invalid string UUID; this does not introduce any BC issues, since the new exception inherits from the previously used `InvalidArgumentException` [#162](https://github.com/ramsey/uuid/pull/162) + * Improve memory usage when generating large quantities of UUIDs (use `str_pad()` and `dechex()` instead of `sprintf()`) [#160](https://github.com/ramsey/uuid/pull/160) + * Minor test and documentation updates + +## 3.5.2 + +_Released: 2016-11-22_ + + * Improved test coverage. + +## 3.5.1 + +_Released: 2016-10-02_ + + * Fixed issue where same UUIDs were not treated as equal with mixed case ([#131](https://github.com/ramsey/uuid/issues/131), [#137](https://github.com/ramsey/uuid/pull/137)). + * Test cleanup. + +## 3.5.0 + +_Released: 2016-08-02_ + + * Add `OrderedTimeCodec` to store UUID in an optimized way for InnoDB ([#117](https://github.com/ramsey/uuid/issues/117), [#118](https://github.com/ramsey/uuid/pull/118)). + * Fixed `RandomNodeProvider` to prevent invalid node generation ([#129](https://github.com/ramsey/uuid/pull/129)). + * Cache failed attempt to retrieve system node to avoid multiple system calls ([#107](https://github.com/ramsey/uuid/issues/107), [#121](https://github.com/ramsey/uuid/pull/121)). + * Various test improvements. + +## 3.4.1 + +_Released: 2016-04-23_ + + * Fixed test that violated a PHP CodeSniffer rule, breaking the build. + +## 3.4.0 + +_Released: 2016-04-23_ + + * Add `TimestampFirstCombCodec` and `TimestampLastCombCodec` codecs. + * Improve logic of `CombGenerator` for COMB sequential UUIDs. + * Significantly improved test coverage. + +## 3.3.0 + +_Released: 2016-03-22_ + + * Drop the use of OpenSSL as a fallback and use [paragonie/random_compat][] to support RandomBytesGenerator in versions of PHP earlier than 7.0. This addresses and fixes the [collision issue][]. + * Improved test coverage. + * Update code to conduct to version 1.4 of the Contributor Covenant. + +## 3.2.0 + +_Released: 2016-02-17_ + + * Add random generator option for use for the PECL libsodium extension. + * Updates to test infrastructure. + +## 3.1.0 + +_Released: 2015-12-17_ + + * Uuid objects now may be properly serialized/unserialized. + * Update build environments for testing on Travis CI. + +## 3.0.1 + +_Released: 2015-10-21_ + + * Add project [Contributor Code of Conduct](https://github.com/ramsey/uuid/blob/master/CONDUCT.md) + * Modify Travis CI builds to run tests on multiple CPU architectures + * Clean up code, tests, and documentation + +## 3.0.0 + +_Released: 2015-09-28_ + +The 3.0.0 release represents a significant step for the ramsey/uuid library. While the simple and familiar API used in previous versions remains intact, this release provides greater flexibility to integrators, including the ability to inject your own number generators, UUID codecs, node and time providers, and more. + + * BREAK: The root namespace for this package has changed from "Rhumsaa" to "Ramsey." In most cases, simply making this change in your applications is the only upgrade path you will need. Everything else should work as expected. + * BREAK: The UUID [Doctrine field type](http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html) has been moved to [ramsey/uuid-doctrine](https://github.com/ramsey/uuid-doctrine). + * BREAK: The `uuid` console application has been moved to [ramsey/uuid-console](https://github.com/ramsey/uuid-console). + * BREAK: The `Uuid::VERSION` package version constant has been removed. + * See also the release notes for [3.0.0-alpha1][300-alpha1], [3.0.0-alpha2][300-alpha2], [3.0.0-alpha3][300-alpha3], and [3.0.0-beta1][300-beta1]. + +[300-alpha1]: https://github.com/ramsey/uuid/blob/master/CHANGELOG.md#300-alpha1 +[300-alpha2]: https://github.com/ramsey/uuid/blob/master/CHANGELOG.md#300-alpha2 +[300-alpha3]: https://github.com/ramsey/uuid/blob/master/CHANGELOG.md#300-alpha3 +[300-beta1]: https://github.com/ramsey/uuid/blob/master/CHANGELOG.md#300-beta1 + +## 3.0.0-beta1 + +_Released: 2015-08-31_ + + * Improve GUID support to ensure that: + * On little endian (LE) architectures, the byte order of the first three fields is LE. + * On big endian (BE) architectures, it is the same as a GUID. + * String representation is always the same. + * Fix exception message for `DegradedNumberConverter::fromHex()`. + * Add Scrutinizer configuration to run code-quality builds through Scrutinizer. + * Auto-fix Scrutinizer issues. + * Fix support URLs in composer.json to point to the correct GitHub repository. + +## 3.0.0-alpha3 + +_Released: 2015-07-28_ + + * Time generator improvements: + * Enabled use of custom TimeGenerator implementations. + * BREAK: Removed now unnecessary `timeConverter` and `timeProvider` properties, setters, and getters in both `FeatureSet` and `UuidFactory` as those are now exclusively used by the default `TimeGenerator`. + * Added a `setTimeGenerator` method on `UuidFactory` to override the default time generator. + * Add option to enable `PeclUuidTimeGenerator` via `FeatureSet`. + +## 3.0.0-alpha2 + +_Released: 2015-07-28_ + + * BREAK: Removed `PeclUuidFactory` in favor of using pecl-uuid with generators. + * NEW: Refactored time-based (version 1) UUIDs into a `TimeGeneratorInterface` to allow for other sources to generate version 1 UUIDs in this library. + * NEW: Added `PeclUuidTimeGenerator` and `PeclUuidRandomGenerator` for creating version 1 or version 4 UUIDs using the pecl-uuid extension. + * NEW: Add `RandomBytesGenerator` for use with PHP 7. ramsey/uuid will default to use this generator when running on PHP 7. + * `RandomLibAdapter` now defaults to a medium-strength generator with [ircmaxell/random-lib](https://github.com/ircmaxell/RandomLib). This is configurable, so other generator strengths may be used. + * Migrated to the Travis CI container-based infrastructure for builds. + * Documentation updates and corrections. + +## 3.0.0-alpha1 + +_Released: 2015-07-16_ + + * BREAK: The root namespace for this package has changed from "Rhumsaa" to "Ramsey." In most cases, simply making this change in your applications is the only upgrade path you will need. Everything else should work as expected. + * BREAK: The UUID [Doctrine field type](http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html) has been moved to [ramsey/uuid-doctrine](https://github.com/ramsey/uuid-doctrine). + * BREAK: The `uuid` console application has been moved to [ramsey/uuid-console](https://github.com/ramsey/uuid-console). + * BREAK: The `Uuid::VERSION` package version constant has been removed. + * NEW: The `Uuid` class is no longer marked as `final`. Everything is now based around interfaces and factories, allowing you to use this package as a base to implement other kinds of UUIDs with different dependencies. + * NEW: Through setting dependencies on `UuidFactory` and/or extending `FeatureSet`, you may override any package defaults, injecting your own dependencies. + * NEW: For random number generation, in addition to `OpenSslGenerator` (used if `openssl_random_pseudo_bytes()` is present) and the fallback `MtRandGenerator`, you may use the bundled `CombGenerator` for sequential UUIDs or the `RandomLibAdapter` if using [ircmaxell/random-lib](https://github.com/ircmaxell/RandomLib). + * NEW: In addition to the default UUID generation, this library also supports GUID generation by configuring a `FeatureSet` to use GUIDs. + * NEW: While the interface to create UUIDs hasn't changed, if using this package on a 32-bit system, you will now receive an object of type `DegradedUuid` (which extends `Uuid`, which implements `UuidInterface`). + * NEW: All UUIDs are now [JsonSerializable](http://php.net/JsonSerializable). + +## 2.9.0 + +_Released: 2016-03-22_ + + * Drop support for OpenSSL in favor of [paragonie/random_compat][]. This addresses and fixes the [collision issue][]. + +## 2.8.4 + +_Released: 2015-12-17_ + + * Add support for symfony/console v3. + * Update build matrix to run Travis CI tests on PHP 7 & with lowest package versions. + +## 2.8.3 + +_Released: 2015-08-31_ + + * Fix exception message in `Uuid::calculateUuidTime()`. + * Update composer.json to reflect new repository and package name. + +## 2.8.2 + +_Released: 2015-07-23_ + + * Ensure the release tag makes it into the rhumsaa/uuid package. + * Minor documentation changes. + +## 2.8.1 + +_Released: 2015-06-16_ + + * Use `passthru()` and output buffering in `getIfconfig()`. + * Cache the system node in a static variable so that we process it only once per runtime. + * Set ramsey/uuid as a replacement for rhumsaa/uuid in composer.json. + * Documentation updates and corrections. + +## 2.8.0 + +_Released: 2014-11-09_ + + * Added static `fromInteger()` method to create UUIDs from string integer or `\Moontoast\Math\BigNumber`. + * Friendlier Doctrine conversion to Uuid or string. + * Documentation fixes. + +## 2.7.4 + +_Released: 2014-10-29_ + + * Changed loop in `generateBytes()` from `foreach` to `for`; see #33 + * Use `toString()` in README examples to avoid confusion + * Exclude build/development tools from releases using .gitattributes + * Set timezone properly for tests + +## 2.7.3 + +_Released: 2014-08-27_ + + * Fixed upper range for `mt_rand` used in version 4 UUIDs + +## 2.7.2 + +_Released: 2014-07-28_ + + * Upgraded to PSR-4 autoloading + * Testing upgrades: + * Testing against PHP 5.6 + * Testing with PHPUnit 4 + * Using Coveralls.io to generate code coverage reports + * Documentation fixes + +## 2.7.1 + +_Released: 2014-02-19_ + + * Moved moontoast/math and symfony/console to require-dev; fixes #20 + * Now supporting symfony/console for 2.3 (LTS version); fixes #21 + * Updated tests to run even when dev packages are not installed (skips tests if requirements are not met) + +## 2.7.0 + +_Released: 2014-01-31_ + + * Moved UUID validation regex pattern into constant for external use (`Uuid::VALID_PATTERN`) + +## 2.6.1 + +_Released: 2014-01-27_ + + * Fixed bug where `uuid` console application could not find the Composer autoloader when installed in another project + +## 2.6.0 + +_Released: 2014-01-17_ + + * Introduced `uuid` console application for generating and decoding UUIDs from CLI (run `./bin/uuid` for details) + * Added `Uuid::getInteger()` to retrieve a Moontoast\Math\BigNumber representation of the 128-bit integer representing the UUID + * Added `Uuid::getHex()` to retrieve the hexadecimal representation of the UUID + * Now using netstat on Linux to capture the node for a version 1 UUID + * Now requiring Moontoast\Math as part of the regular package requirements, not just the dev requirements + +## 2.5.0 + +_Released: 2013-10-30_ + + * Using `openssl_random_pseudo_bytes()`, if available, to generate random bytes, by merging in PR #15 from @dfreudenberger + * Fixed test for Rhumsaa\Uuid\Doctrine\UuidType, by merging in PR #17 from @dfreudenberger + * Documentation fixes + +## 2.4.0 + +_Released: 2013-07-29_ + + * `Uuid::getVersion()` now returns null if the UUID isn't an RFC 4122 variant + * `Uuid::fromString()` now supports a 128-bit integer formatted as a hexadecimal string (UUID without dashes) + * Tests have been greatly enhanced, borrowing from the Python UUID library + +## 2.3.0 + +_Released: 2013-07-16_ + + * Added `Uuid::fromBytes()` by merging in PR #14 from @asm89 + +## 2.2.0 + +_Released: 2013-07-04_ + + * Added `Doctrine\UuidType::requiresSQLCommentHint()` method by merging in PR #13 from @zerrvox + * Removed `"minimum-stability": "dev"` from composer.json + +## 2.1.2 + +_Released: 2013-07-03_ + + * @ericthelin found cases where the system node was coming back with uppercase hexadecimal digits; this ensures that case in the node is converted to lowercase + +## 2.1.1 + +_Released: 2013-04-29_ + + * Fixed NIL bug in `Uuid::isValid()` method, reported by @ocubom in PR #11 + +## 2.1.0 + +_Released: 2013-04-15_ + + * Added static `Uuid::isValid()` method for checking whether a string is a valid UUID + +## 2.0.0 + +_Released: 2013-02-11_ + + * Break: `Uuid` class is now marked as "final" + * Break: `Uuid::getLeastSignificantBits()` no longer returns an integer on 64-bit platforms; it requires `moontoast/math` + * Break: `Uuid::getMostSignificantBits()` no longer returns an integer on 64-bit platforms; it requires `moontoast/math` + * Break: Moved `UnsupportedOperationException` to the `Exception` subnamespace + * Added support for 32-bit platforms + * Added generated API documentation to the repository + +## 1.1.2 + +_Released: 2012-11-29_ + + * Relaxed Doctrine type conversion rules + +## 1.1.1 + +_Released: 2012-08-27_ + + * Removed `final` keyword from `Uuid` class + +## 1.1.0 + +_Released: 2012-08-06_ + + * Added `Doctrine\UuidType` as a field mapping type for the Doctrine Database Abstraction Layer (DBAL) + * Improved tests and code coverage + +## 1.0.0 + +_Released: 2012-07-19_ + + * Initial release + + +[paragonie/random_compat]: https://github.com/paragonie/random_compat +[collision issue]: https://github.com/ramsey/uuid/issues/80 diff --git a/vendor/ramsey/uuid/CODE_OF_CONDUCT.md b/vendor/ramsey/uuid/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..9c207259b --- /dev/null +++ b/vendor/ramsey/uuid/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project maintainer at <ben@benramsey.com>. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/vendor/ramsey/uuid/CONTRIBUTING.md b/vendor/ramsey/uuid/CONTRIBUTING.md new file mode 100644 index 000000000..4cde9b840 --- /dev/null +++ b/vendor/ramsey/uuid/CONTRIBUTING.md @@ -0,0 +1,75 @@ +# Contributing + +Contributions are welcome. We accept pull requests on [GitHub](https://github.com/ramsey/uuid). + +This project adheres to a [Contributor Code of Conduct](https://github.com/ramsey/uuid/blob/master/CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code. + +## Team members + +* [Ben Ramsey](https://github.com/ramsey) - original author and maintainer +* [Marijn Huizendveld](https://github.com/marijn) - contributor, author of UUID type definition for Doctrine DBAL +* [Thibaud Fabre](https://github.com/aztech-dev) - contributor, lead developer for version 3.0.0 re-architecture + +## Communication Channels + +You can find help and discussion in the following places: + +* GitHub Issues: <https://github.com/ramsey/uuid/issues> +* Wiki: <https://github.com/ramsey/uuid/wiki> + +## Reporting Bugs + +Bugs are tracked in our project's [issue tracker](https://github.com/ramsey/uuid/issues). + +When submitting a bug report, please include enough information for us to reproduce the bug. A good bug report includes the following sections: + +* Expected outcome +* Actual outcome +* Steps to reproduce, including sample code +* Any other information that will help us debug and reproduce the issue, including stack traces, system/environment information, and screenshots + +**Please do not include passwords or any personally identifiable information in your bug report and sample code.** + +## Fixing Bugs + +We welcome pull requests to fix bugs! + +If you see a bug report that you'd like to fix, please feel free to do so. Following the directions and guidelines described in the "Adding New Features" section below, you may create bugfix branches and send us pull requests. + +## Adding New Features + +If you have an idea for a new feature, it's a good idea to check out our [issues](https://github.com/ramsey/uuid/issues) or active [pull requests](https://github.com/ramsey/uuid/pulls) first to see if the feature is already being worked on. If not, feel free to submit an issue first, asking whether the feature is beneficial to the project. This will save you from doing a lot of development work only to have your feature rejected. We don't enjoy rejecting your hard work, but some features just don't fit with the goals of the project. + +When you do begin working on your feature, here are some guidelines to consider: + +* Your pull request description should clearly detail the changes you have made. We will use this description to add to our CHANGELOG. If there is no description or it does not adequately describe your feature, we will ask you to update the description. +* We following the **[PSR-2 coding standard](http://www.php-fig.org/psr/psr-2/)**. Please ensure your code does, too. +* Please **write tests** for any new features you add. +* Please **ensure that tests pass** before submitting your pull request. We have Travis CI automatically running tests for pull requests. However, running the tests locally will help save time. +* **Use topic/feature branches.** Please do not ask us to pull from your master branch. +* **Submit one feature per pull request.** If you have multiple features you wish to submit, please break them up into separate pull requests. +* **Send coherent history**. Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. + +## Running Tests + +The following tests must pass before we will accept a pull request. If any of these do not pass, it will result in a complete build failure. Before you can run these, be sure to `composer install`. + +``` +composer test +``` + +### Locally Test With Emulated MIPS Architecture + +The following commands use [Vagrant](https://www.vagrantup.com/) to start an Ubuntu VM, install necessary dependencies, and then run the `tools/run-tests.sh` script that will download a Docker image emulating the MIPS architecture. This is especially helpful for testing UUID generation in a big-endian environment. + +``` +vagrant init ubuntu/trusty64 +vagrant up +vagrant ssh +sudo apt-get install docker.io qemu-user-static php5-cli php5-curl +cd /vagrant +curl -sS https://getcomposer.org/installer | php +php composer.phar install --no-interaction --prefer-dist +mkdir -p build/logs +ARCH=mips PHP_VERSION=5.6.14 TRAVIS_BUILD_DIR=/vagrant ./tools/run-tests.sh +``` diff --git a/vendor/ramsey/uuid/LICENSE b/vendor/ramsey/uuid/LICENSE new file mode 100644 index 000000000..753a4c9c8 --- /dev/null +++ b/vendor/ramsey/uuid/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012-2018 Ben Ramsey <ben@benramsey.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/ramsey/uuid/README.md b/vendor/ramsey/uuid/README.md new file mode 100644 index 000000000..b6557abbc --- /dev/null +++ b/vendor/ramsey/uuid/README.md @@ -0,0 +1,159 @@ +# ramsey/uuid + +_NOTICE: Formerly known as `rhumsaa/uuid`, The package and namespace names have changed to `ramsey/uuid` and `Ramsey\Uuid`, respectively._ + +[![Source Code][badge-source]][source] +[![Latest Version][badge-release]][release] +[![Software License][badge-license]][license] +[![Build Status][badge-build]][build] +[![Coverage Status][badge-coverage]][coverage] +[![Total Downloads][badge-downloads]][downloads] + +ramsey/uuid is a PHP 5.4+ library for generating and working with [RFC 4122][rfc4122] version 1, 3, 4, and 5 universally unique identifiers (UUID). + +This project adheres to a [Contributor Code of Conduct][conduct]. By participating in this project and its community, you are expected to uphold this code. + + +## About + +From [Wikipedia](http://en.wikipedia.org/wiki/Universally_unique_identifier): + +> The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination. In this context the word unique should be taken to mean "practically unique" rather than "guaranteed unique". Since the identifiers have a finite size, it is possible for two differing items to share the same identifier. The identifier size and generation process need to be selected so as to make this sufficiently improbable in practice. Anyone can create a UUID and use it to identify something with reasonable confidence that the same identifier will never be unintentionally created by anyone to identify something else. Information labeled with UUIDs can therefore be later combined into a single database without needing to resolve identifier (ID) conflicts. + +Much inspiration for this library came from the [Java][javauuid] and [Python][pyuuid] UUID libraries. + + +## Installation + +The preferred method of installation is via [Packagist][] and [Composer][]. Run the following command to install the package and add it as a requirement to your project's `composer.json`: + +```bash +composer require ramsey/uuid +``` + + +## Upgrading from 2.x to 3.x + +While we have made significant internal changes to the library, we have made every effort to ensure a seamless upgrade path from the 2.x series of this library to 3.x. + +One major breaking change is the transition from the `Rhumsaa` root namespace to `Ramsey`. In most cases, all you will need is to change the namespace to `Ramsey` in your code, and everything will "just work." + +Here are full details on the breaking changes to the public API of this library: + +1. All namespace references of `Rhumsaa` have changed to `Ramsey`. Simply change the namespace to `Ramsey` in your code and everything should work. +2. The console application has moved to [ramsey/uuid-console](https://packagist.org/packages/ramsey/uuid-console). If using the console functionality, use Composer to require `ramsey/uuid-console`. +3. The Doctrine field type mapping has moved to [ramsey/uuid-doctrine](https://packagist.org/packages/ramsey/uuid-doctrine). If using the Doctrine functionality, use Composer to require `ramsey/uuid-doctrine`. + + +## What to do if you see a "rhumsaa/uuid is abandoned" message + +When installing your project's dependencies using Composer, you might see the following message: + +``` +Package rhumsaa/uuid is abandoned, you should avoid using it. Use ramsey/uuid instead. +``` + +Don't panic. Simply execute the following commands with Composer: + +``` bash +composer remove rhumsaa/uuid +composer require ramsey/uuid=^2.9 +``` + +After doing so, you will have the latest ramsey/uuid package in the 2.x series, and there will be no need to modify any code; the namespace in the 2.x series is still `Rhumsaa`. + + +## Requirements + +Some methods in this library have requirements due to integer size restrictions on 32-bit and 64-bit builds of PHP. A 64-bit build of PHP and the [Moontoast\Math][] library are recommended. However, this library is designed to work on 32-bit builds of PHP without Moontoast\Math, with some degraded functionality. Please check the API documentation for more information. + +If a particular requirement is not present, then an `UnsatisfiedDependencyException` is thrown, allowing one to catch a bad call in an environment where the call is not supported and gracefully degrade. + + +## API documentation + +The [latest class API documentation][apidocs] is available online. + +This project uses [ApiGen](http://apigen.org/) to generate this documentation. To generate the documentation on your own, install dev dependencies and run the following command from the root of the project: + +``` +composer build-docs +``` + +This will generate documentation in the `build/apidocs/` folder. + + +## Examples + +See the [cookbook on the wiki][wiki-cookbook] for more examples and approaches to specific use-cases. + +```php +<?php +require 'vendor/autoload.php'; + +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; + +try { + + // Generate a version 1 (time-based) UUID object + $uuid1 = Uuid::uuid1(); + echo $uuid1->toString() . "\n"; // i.e. e4eaaaf2-d142-11e1-b3e4-080027620cdd + + // Generate a version 3 (name-based and hashed with MD5) UUID object + $uuid3 = Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net'); + echo $uuid3->toString() . "\n"; // i.e. 11a38b9a-b3da-360f-9353-a5a725514269 + + // Generate a version 4 (random) UUID object + $uuid4 = Uuid::uuid4(); + echo $uuid4->toString() . "\n"; // i.e. 25769c6c-d34d-4bfe-ba98-e0ee856f3e7a + + // Generate a version 5 (name-based and hashed with SHA1) UUID object + $uuid5 = Uuid::uuid5(Uuid::NAMESPACE_DNS, 'php.net'); + echo $uuid5->toString() . "\n"; // i.e. c4a760a8-dbcf-5254-a0d9-6a4474bd1b62 + +} catch (UnsatisfiedDependencyException $e) { + + // Some dependency was not met. Either the method cannot be called on a + // 32-bit system, or it can, but it relies on Moontoast\Math to be present. + echo 'Caught exception: ' . $e->getMessage() . "\n"; + +} +``` + + +## Contributing + +Contributions are welcome! Please read [CONTRIBUTING][] for details. + + +## Copyright and license + +The ramsey/uuid library is copyright ยฉ [Ben Ramsey](https://benramsey.com/) and licensed for use under the MIT License (MIT). Please see [LICENSE][] for more information. + + + +[rfc4122]: http://tools.ietf.org/html/rfc4122 +[conduct]: https://github.com/ramsey/uuid/blob/master/CODE_OF_CONDUCT.md +[javauuid]: http://docs.oracle.com/javase/6/docs/api/java/util/UUID.html +[pyuuid]: http://docs.python.org/3/library/uuid.html +[packagist]: https://packagist.org/packages/ramsey/uuid +[composer]: http://getcomposer.org/ +[moontoast\math]: https://packagist.org/packages/moontoast/math +[apidocs]: http://docs.benramsey.com/ramsey-uuid/latest/ +[wiki-cookbook]: https://github.com/ramsey/uuid/wiki/Ramsey%5CUuid-Cookbook +[contributing]: https://github.com/ramsey/uuid/blob/master/CONTRIBUTING.md + +[badge-source]: https://img.shields.io/badge/source-ramsey/uuid-blue.svg?style=flat-square +[badge-release]: https://img.shields.io/packagist/v/ramsey/uuid.svg?style=flat-square +[badge-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square +[badge-build]: https://img.shields.io/travis/ramsey/uuid/master.svg?style=flat-square +[badge-coverage]: https://img.shields.io/coveralls/ramsey/uuid/master.svg?style=flat-square +[badge-downloads]: https://img.shields.io/packagist/dt/ramsey/uuid.svg?style=flat-square + +[source]: https://github.com/ramsey/uuid +[release]: https://packagist.org/packages/ramsey/uuid +[license]: https://github.com/ramsey/uuid/blob/master/LICENSE +[build]: https://travis-ci.org/ramsey/uuid +[coverage]: https://coveralls.io/r/ramsey/uuid?branch=master +[downloads]: https://packagist.org/packages/ramsey/uuid diff --git a/vendor/ramsey/uuid/composer.json b/vendor/ramsey/uuid/composer.json new file mode 100644 index 000000000..952120cd4 --- /dev/null +++ b/vendor/ramsey/uuid/composer.json @@ -0,0 +1,80 @@ +{ + "name": "ramsey/uuid", + "description": "Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID).", + "type": "library", + "keywords": ["uuid", "identifier", "guid"], + "homepage": "https://github.com/ramsey/uuid", + "license": "MIT", + "authors": [ + { + "name": "Ben Ramsey", + "email": "ben@benramsey.com", + "homepage": "https://benramsey.com" + }, + { + "name": "Marijn Huizendveld", + "email": "marijn.huizendveld@gmail.com" + }, + { + "name": "Thibaud Fabre", + "email": "thibaud@aztech.io" + } + ], + "support": { + "issues": "https://github.com/ramsey/uuid/issues", + "source": "https://github.com/ramsey/uuid" + }, + "require": { + "php": "^5.4 || ^7.0", + "paragonie/random_compat": "^1.0|^2.0|9.99.99", + "symfony/polyfill-ctype": "^1.8" + }, + "require-dev": { + "codeception/aspect-mock": "^1.0 | ~2.0.0", + "doctrine/annotations": "~1.2.0", + "goaop/framework": "1.0.0-alpha.2 | ^1.0 | ~2.1.0", + "ircmaxell/random-lib": "^1.1", + "jakub-onderka/php-parallel-lint": "^0.9.0", + "mockery/mockery": "^0.9.9", + "moontoast/math": "^1.1", + "php-mock/php-mock-phpunit": "^0.3|^1.1", + "phpunit/phpunit": "^4.7|^5.0|^6.5", + "squizlabs/php_codesniffer": "^2.3" + }, + "suggest": { + "ext-ctype": "Provides support for PHP Ctype functions", + "ircmaxell/random-lib": "Provides RandomLib for use with the RandomLibAdapter", + "ext-libsodium": "Provides the PECL libsodium extension for use with the SodiumRandomGenerator", + "ext-uuid": "Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator", + "moontoast/math": "Provides support for converting UUID to 128-bit integer (in string form).", + "ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type.", + "ramsey/uuid-console": "A console application for generating UUIDs with ramsey/uuid" + }, + "autoload": { + "psr-4": {"Ramsey\\Uuid\\": "src/"} + }, + "autoload-dev": { + "psr-4": {"Ramsey\\Uuid\\Test\\": "tests/"} + }, + "replace": { + "rhumsaa/uuid": "self.version" + }, + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "scripts": { + "lint": "parallel-lint src tests", + "phpunit": "phpunit --verbose --colors=always", + "phpcs": "phpcs src tests --standard=psr2 -sp --colors", + "test": [ + "@lint", + "@phpunit", + "@phpcs" + ] + }, + "config": { + "sort-packages": true + } +} diff --git a/vendor/ramsey/uuid/src/BinaryUtils.php b/vendor/ramsey/uuid/src/BinaryUtils.php new file mode 100644 index 000000000..f04a9d9c1 --- /dev/null +++ b/vendor/ramsey/uuid/src/BinaryUtils.php @@ -0,0 +1,43 @@ +<?php + +namespace Ramsey\Uuid; + +/** + * Provides binary math utilities + */ +class BinaryUtils +{ + /** + * Applies the RFC 4122 variant field to the `clock_seq_hi_and_reserved` field + * + * @param $clockSeqHi + * @return int The high field of the clock sequence multiplexed with the variant + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + public static function applyVariant($clockSeqHi) + { + // Set the variant to RFC 4122 + $clockSeqHi = $clockSeqHi & 0x3f; + $clockSeqHi &= ~(0xc0); + $clockSeqHi |= 0x80; + + return $clockSeqHi; + } + + /** + * Applies the RFC 4122 version number to the `time_hi_and_version` field + * + * @param string $timeHi + * @param integer $version + * @return int The high field of the timestamp multiplexed with the version number + * @link http://tools.ietf.org/html/rfc4122#section-4.1.3 + */ + public static function applyVersion($timeHi, $version) + { + $timeHi = hexdec($timeHi) & 0x0fff; + $timeHi &= ~(0xf000); + $timeHi |= $version << 12; + + return $timeHi; + } +} diff --git a/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php b/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php new file mode 100644 index 000000000..20656acdf --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php @@ -0,0 +1,54 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Builder; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Uuid; + +/** + * DefaultUuidBuilder is the default UUID builder for ramsey/uuid; it builds + * instances of Uuid objects + */ +class DefaultUuidBuilder implements UuidBuilderInterface +{ + /** + * @var NumberConverterInterface + */ + private $converter; + + /** + * Constructs the DefaultUuidBuilder + * + * @param NumberConverterInterface $converter The number converter to use when constructing the Uuid + */ + public function __construct(NumberConverterInterface $converter) + { + $this->converter = $converter; + } + + /** + * Builds a Uuid + * + * @param CodecInterface $codec The codec to use for building this Uuid + * @param array $fields An array of fields from which to construct the Uuid; + * see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure. + * @return Uuid + */ + public function build(CodecInterface $codec, array $fields) + { + return new Uuid($fields, $this->converter, $codec); + } +} diff --git a/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php new file mode 100644 index 000000000..7edb6deb7 --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php @@ -0,0 +1,53 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Builder; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\DegradedUuid; + +/** + * DegradedUuidBuilder builds instances of DegradedUuid + */ +class DegradedUuidBuilder implements UuidBuilderInterface +{ + /** + * @var NumberConverterInterface + */ + private $converter; + + /** + * Constructs the DegradedUuidBuilder + * + * @param NumberConverterInterface $converter The number converter to use when constructing the DegradedUuid + */ + public function __construct(NumberConverterInterface $converter) + { + $this->converter = $converter; + } + + /** + * Builds a DegradedUuid + * + * @param CodecInterface $codec The codec to use for building this DegradedUuid + * @param array $fields An array of fields from which to construct the DegradedUuid; + * see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure. + * @return DegradedUuid + */ + public function build(CodecInterface $codec, array $fields) + { + return new DegradedUuid($fields, $this->converter, $codec); + } +} diff --git a/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php b/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php new file mode 100644 index 000000000..e4e990109 --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php @@ -0,0 +1,34 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Builder; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\UuidInterface; + +/** + * UuidBuilderInterface builds instances UuidInterface + */ +interface UuidBuilderInterface +{ + /** + * Builds an instance of a UuidInterface + * + * @param CodecInterface $codec The codec to use for building this UuidInterface instance + * @param array $fields An array of fields from which to construct a UuidInterface instance; + * see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure. + * @return UuidInterface + */ + public function build(CodecInterface $codec, array $fields); +} diff --git a/vendor/ramsey/uuid/src/Codec/CodecInterface.php b/vendor/ramsey/uuid/src/Codec/CodecInterface.php new file mode 100644 index 000000000..6ea20544f --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/CodecInterface.php @@ -0,0 +1,58 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Codec; + +use Ramsey\Uuid\UuidInterface; + +/** + * CodecInterface represents a UUID coder-decoder + */ +interface CodecInterface +{ + /** + * Encodes a UuidInterface as a string representation of a UUID + * + * @param UuidInterface $uuid + * @return string Hexadecimal string representation of a UUID + */ + public function encode(UuidInterface $uuid); + + /** + * Encodes a UuidInterface as a binary representation of a UUID + * + * @param UuidInterface $uuid + * @return string Binary string representation of a UUID + */ + public function encodeBinary(UuidInterface $uuid); + + /** + * Decodes a string representation of a UUID into a UuidInterface object instance + * + * @param string $encodedUuid + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function decode($encodedUuid); + + /** + * Decodes a binary representation of a UUID into a UuidInterface object instance + * + * @param string $bytes + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + * @throws \InvalidArgumentException if string has not 16 characters + */ + public function decodeBytes($bytes); +} diff --git a/vendor/ramsey/uuid/src/Codec/GuidStringCodec.php b/vendor/ramsey/uuid/src/Codec/GuidStringCodec.php new file mode 100644 index 000000000..864980b30 --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/GuidStringCodec.php @@ -0,0 +1,102 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Codec; + +use Ramsey\Uuid\UuidInterface; + +/** + * GuidStringCodec encodes and decodes globally unique identifiers (GUID) + * + * @link https://en.wikipedia.org/wiki/Globally_unique_identifier + */ +class GuidStringCodec extends StringCodec +{ + /** + * Encodes a UuidInterface as a string representation of a GUID + * + * @param UuidInterface $uuid + * @return string Hexadecimal string representation of a GUID + */ + public function encode(UuidInterface $uuid) + { + $components = array_values($uuid->getFieldsHex()); + + // Swap byte-order on the first three fields + $this->swapFields($components); + + return vsprintf( + '%08s-%04s-%04s-%02s%02s-%012s', + $components + ); + } + + /** + * Encodes a UuidInterface as a binary representation of a GUID + * + * @param UuidInterface $uuid + * @return string Binary string representation of a GUID + */ + public function encodeBinary(UuidInterface $uuid) + { + $components = array_values($uuid->getFieldsHex()); + + return hex2bin(implode('', $components)); + } + + /** + * Decodes a string representation of a GUID into a UuidInterface object instance + * + * @param string $encodedUuid + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function decode($encodedUuid) + { + $components = $this->extractComponents($encodedUuid); + + $this->swapFields($components); + + return $this->getBuilder()->build($this, $this->getFields($components)); + } + + /** + * Decodes a binary representation of a GUID into a UuidInterface object instance + * + * @param string $bytes + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function decodeBytes($bytes) + { + // Specifically call parent::decode to preserve correct byte order + return parent::decode(bin2hex($bytes)); + } + + /** + * Swaps fields to support GUID byte order + * + * @param array $components An array of UUID components (the UUID exploded on its dashes) + * @return void + */ + protected function swapFields(array &$components) + { + $hex = unpack('H*', pack('L', hexdec($components[0]))); + $components[0] = $hex[1]; + $hex = unpack('H*', pack('S', hexdec($components[1]))); + $components[1] = $hex[1]; + $hex = unpack('H*', pack('S', hexdec($components[2]))); + $components[2] = $hex[1]; + } +} diff --git a/vendor/ramsey/uuid/src/Codec/OrderedTimeCodec.php b/vendor/ramsey/uuid/src/Codec/OrderedTimeCodec.php new file mode 100644 index 000000000..3257759c9 --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/OrderedTimeCodec.php @@ -0,0 +1,68 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ +namespace Ramsey\Uuid\Codec; + +use InvalidArgumentException; +use Ramsey\Uuid\UuidInterface; + +/** + * OrderedTimeCodec optimizes the bytes to increment UUIDs when time goes by, to improve database INSERTs. + * The string value will be unchanged from StringCodec. Only works for UUID type 1. + */ +class OrderedTimeCodec extends StringCodec +{ + + /** + * Encodes a UuidInterface as an optimized binary representation of a UUID + * + * @param UuidInterface $uuid + * @return string Binary string representation of a UUID + */ + public function encodeBinary(UuidInterface $uuid) + { + $fields = $uuid->getFieldsHex(); + + $optimized = [ + $fields['time_hi_and_version'], + $fields['time_mid'], + $fields['time_low'], + $fields['clock_seq_hi_and_reserved'], + $fields['clock_seq_low'], + $fields['node'], + ]; + + return hex2bin(implode('', $optimized)); + } + + /** + * Decodes an optimized binary representation of a UUID into a UuidInterface object instance + * + * @param string $bytes + * @return UuidInterface + * @throws \InvalidArgumentException if string has not 16 characters + */ + public function decodeBytes($bytes) + { + if (strlen($bytes) !== 16) { + throw new InvalidArgumentException('$bytes string should contain 16 characters.'); + } + + $hex = unpack('H*', $bytes)[1]; + + // Rearrange the fields to their original order + $hex = substr($hex, 8, 4) . substr($hex, 12, 4) . substr($hex, 4, 4) . substr($hex, 0, 4) . substr($hex, 16); + + return $this->decode($hex); + } +} diff --git a/vendor/ramsey/uuid/src/Codec/StringCodec.php b/vendor/ramsey/uuid/src/Codec/StringCodec.php new file mode 100644 index 000000000..7f352065c --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/StringCodec.php @@ -0,0 +1,170 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Codec; + +use InvalidArgumentException; +use Ramsey\Uuid\Builder\UuidBuilderInterface; +use Ramsey\Uuid\Exception\InvalidUuidStringException; +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\UuidInterface; + +/** + * StringCodec encodes and decodes RFC 4122 UUIDs + * + * @link http://tools.ietf.org/html/rfc4122 + */ +class StringCodec implements CodecInterface +{ + /** + * @var UuidBuilderInterface + */ + private $builder; + + /** + * Constructs a StringCodec for use encoding and decoding UUIDs + * + * @param UuidBuilderInterface $builder The UUID builder to use when encoding UUIDs + */ + public function __construct(UuidBuilderInterface $builder) + { + $this->builder = $builder; + } + + /** + * Encodes a UuidInterface as a string representation of a UUID + * + * @param UuidInterface $uuid + * @return string Hexadecimal string representation of a UUID + */ + public function encode(UuidInterface $uuid) + { + $fields = array_values($uuid->getFieldsHex()); + + return vsprintf( + '%08s-%04s-%04s-%02s%02s-%012s', + $fields + ); + } + + /** + * Encodes a UuidInterface as a binary representation of a UUID + * + * @param UuidInterface $uuid + * @return string Binary string representation of a UUID + */ + public function encodeBinary(UuidInterface $uuid) + { + return hex2bin($uuid->getHex()); + } + + /** + * Decodes a string representation of a UUID into a UuidInterface object instance + * + * @param string $encodedUuid + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function decode($encodedUuid) + { + $components = $this->extractComponents($encodedUuid); + $fields = $this->getFields($components); + + return $this->builder->build($this, $fields); + } + + /** + * Decodes a binary representation of a UUID into a UuidInterface object instance + * + * @param string $bytes + * @return UuidInterface + * @throws \InvalidArgumentException if string has not 16 characters + */ + public function decodeBytes($bytes) + { + if (strlen($bytes) !== 16) { + throw new InvalidArgumentException('$bytes string should contain 16 characters.'); + } + + $hexUuid = unpack('H*', $bytes); + + return $this->decode($hexUuid[1]); + } + + /** + * Returns the UUID builder + * + * @return UuidBuilderInterface + */ + protected function getBuilder() + { + return $this->builder; + } + + /** + * Returns an array of UUID components (the UUID exploded on its dashes) + * + * @param string $encodedUuid + * @return array + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + protected function extractComponents($encodedUuid) + { + $nameParsed = str_replace(array( + 'urn:', + 'uuid:', + '{', + '}', + '-' + ), '', $encodedUuid); + + // We have stripped out the dashes and are breaking up the string using + // substr(). In this way, we can accept a full hex value that doesn't + // contain dashes. + $components = array( + substr($nameParsed, 0, 8), + substr($nameParsed, 8, 4), + substr($nameParsed, 12, 4), + substr($nameParsed, 16, 4), + substr($nameParsed, 20) + ); + + $nameParsed = implode('-', $components); + + if (!Uuid::isValid($nameParsed)) { + throw new InvalidUuidStringException('Invalid UUID string: ' . $encodedUuid); + } + + return $components; + } + + /** + * Returns the fields that make up this UUID + * + * @see \Ramsey\Uuid\UuidInterface::getFieldsHex() + * @param array $components + * @return array + */ + protected function getFields(array $components) + { + return array( + 'time_low' => str_pad($components[0], 8, '0', STR_PAD_LEFT), + 'time_mid' => str_pad($components[1], 4, '0', STR_PAD_LEFT), + 'time_hi_and_version' => str_pad($components[2], 4, '0', STR_PAD_LEFT), + 'clock_seq_hi_and_reserved' => str_pad(substr($components[3], 0, 2), 2, '0', STR_PAD_LEFT), + 'clock_seq_low' => str_pad(substr($components[3], 2), 2, '0', STR_PAD_LEFT), + 'node' => str_pad($components[4], 12, '0', STR_PAD_LEFT) + ); + } +} diff --git a/vendor/ramsey/uuid/src/Codec/TimestampFirstCombCodec.php b/vendor/ramsey/uuid/src/Codec/TimestampFirstCombCodec.php new file mode 100644 index 000000000..2c4ded89e --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/TimestampFirstCombCodec.php @@ -0,0 +1,107 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ +namespace Ramsey\Uuid\Codec; + +use Ramsey\Uuid\UuidInterface; + +/** + * TimestampLastCombCodec encodes and decodes COMB UUIDs which have the timestamp as the first 48 bits. + * To be used with MySQL, PostgreSQL, Oracle. + */ +class TimestampFirstCombCodec extends StringCodec +{ + /** + * Encodes a UuidInterface as a string representation of a timestamp first COMB UUID + * + * @param UuidInterface $uuid + * + * @return string Hexadecimal string representation of a GUID + */ + public function encode(UuidInterface $uuid) + { + $sixPieceComponents = array_values($uuid->getFieldsHex()); + + $this->swapTimestampAndRandomBits($sixPieceComponents); + + return vsprintf( + '%08s-%04s-%04s-%02s%02s-%012s', + $sixPieceComponents + ); + } + + /** + * Encodes a UuidInterface as a binary representation of timestamp first COMB UUID + * + * @param UuidInterface $uuid + * + * @return string Binary string representation of timestamp first COMB UUID + */ + public function encodeBinary(UuidInterface $uuid) + { + $stringEncoding = $this->encode($uuid); + + return hex2bin(str_replace('-', '', $stringEncoding)); + } + + /** + * Decodes a string representation of timestamp first COMB UUID into a UuidInterface object instance + * + * @param string $encodedUuid + * + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function decode($encodedUuid) + { + $fivePieceComponents = $this->extractComponents($encodedUuid); + + $this->swapTimestampAndRandomBits($fivePieceComponents); + + return $this->getBuilder()->build($this, $this->getFields($fivePieceComponents)); + } + + /** + * Decodes a binary representation of timestamp first COMB UUID into a UuidInterface object instance + * + * @param string $bytes + * + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function decodeBytes($bytes) + { + return $this->decode(bin2hex($bytes)); + } + + /** + * Swaps the first 48 bits with the last 48 bits + * + * @param array $components An array of UUID components (the UUID exploded on its dashes) + * + * @return void + */ + protected function swapTimestampAndRandomBits(array &$components) + { + $last48Bits = $components[4]; + if (count($components) == 6) { + $last48Bits = $components[5]; + $components[5] = $components[0] . $components[1]; + } else { + $components[4] = $components[0] . $components[1]; + } + + $components[0] = substr($last48Bits, 0, 8); + $components[1] = substr($last48Bits, 8, 4); + } +} diff --git a/vendor/ramsey/uuid/src/Codec/TimestampLastCombCodec.php b/vendor/ramsey/uuid/src/Codec/TimestampLastCombCodec.php new file mode 100644 index 000000000..0cdd009a4 --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/TimestampLastCombCodec.php @@ -0,0 +1,23 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ +namespace Ramsey\Uuid\Codec; + +/** + * TimestampLastCombCodec encodes and decodes COMB UUIDs which have the timestamp as the last 48 bits. + * To be used with MSSQL. + */ +class TimestampLastCombCodec extends StringCodec +{ + +} diff --git a/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php new file mode 100644 index 000000000..d23512256 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php @@ -0,0 +1,54 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Converter\Number; + +use Moontoast\Math\BigNumber; +use Ramsey\Uuid\Converter\NumberConverterInterface; + +/** + * BigNumberConverter converts UUIDs from hexadecimal characters into + * moontoast/math `BigNumber` representations of integers and vice versa + */ +class BigNumberConverter implements NumberConverterInterface +{ + /** + * Converts a hexadecimal number into a `Moontoast\Math\BigNumber` representation + * + * @param string $hex The hexadecimal string representation to convert + * @return BigNumber + */ + public function fromHex($hex) + { + $number = BigNumber::convertToBase10($hex, 16); + + return new BigNumber($number); + } + + /** + * Converts an integer or `Moontoast\Math\BigNumber` integer representation + * into a hexadecimal string representation + * + * @param int|string|BigNumber $integer An integer or `Moontoast\Math\BigNumber` + * @return string Hexadecimal string + */ + public function toHex($integer) + { + if (!$integer instanceof BigNumber) { + $integer = new BigNumber($integer); + } + + return BigNumber::convertFromBase10($integer, 16); + } +} diff --git a/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php new file mode 100644 index 000000000..96a011c65 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php @@ -0,0 +1,58 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Converter\Number; + +use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +use Ramsey\Uuid\Converter\NumberConverterInterface; + +/** + * DegradedNumberConverter throws `UnsatisfiedDependencyException` exceptions + * if attempting to use number conversion functionality in an environment that + * does not support large integers (i.e. when moontoast/math is not available) + */ +class DegradedNumberConverter implements NumberConverterInterface +{ + /** + * Throws an `UnsatisfiedDependencyException` + * + * @param string $hex The hexadecimal string representation to convert + * @return void + * @throws UnsatisfiedDependencyException + */ + public function fromHex($hex) + { + throw new UnsatisfiedDependencyException( + 'Cannot call ' . __METHOD__ . ' without support for large ' + . 'integers, since integer is an unsigned ' + . '128-bit integer; Moontoast\Math\BigNumber is required.' + ); + } + + /** + * Throws an `UnsatisfiedDependencyException` + * + * @param mixed $integer An integer representation to convert + * @return void + * @throws UnsatisfiedDependencyException + */ + public function toHex($integer) + { + throw new UnsatisfiedDependencyException( + 'Cannot call ' . __METHOD__ . ' without support for large ' + . 'integers, since integer is an unsigned ' + . '128-bit integer; Moontoast\Math\BigNumber is required. ' + ); + } +} diff --git a/vendor/ramsey/uuid/src/Converter/NumberConverterInterface.php b/vendor/ramsey/uuid/src/Converter/NumberConverterInterface.php new file mode 100644 index 000000000..9505e8c6d --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/NumberConverterInterface.php @@ -0,0 +1,46 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Converter; + +/** + * NumberConverterInterface converts UUIDs from hexadecimal characters into + * representations of integers and vice versa + */ +interface NumberConverterInterface +{ + /** + * Converts a hexadecimal number into an integer representation of the number + * + * The integer representation returned may be an object or a string + * representation of the integer, depending on the implementation. + * + * @param string $hex The hexadecimal string representation to convert + * @return mixed + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + */ + public function fromHex($hex); + + /** + * Converts an integer representation into a hexadecimal string representation + * of the number + * + * @param mixed $integer An integer representation to convert; this may be + * a true integer, a string integer, or a object representation that + * this converter can understand + * @return string Hexadecimal string + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + */ + public function toHex($integer); +} diff --git a/vendor/ramsey/uuid/src/Converter/Time/BigNumberTimeConverter.php b/vendor/ramsey/uuid/src/Converter/Time/BigNumberTimeConverter.php new file mode 100644 index 000000000..d47c80191 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Time/BigNumberTimeConverter.php @@ -0,0 +1,58 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Converter\Time; + +use Moontoast\Math\BigNumber; +use Ramsey\Uuid\Converter\TimeConverterInterface; + +/** + * BigNumberTimeConverter uses the moontoast/math library's `BigNumber` to + * provide facilities for converting parts of time into representations that may + * be used in UUIDs + */ +class BigNumberTimeConverter implements TimeConverterInterface +{ + /** + * Uses the provided seconds and micro-seconds to calculate the time_low, + * time_mid, and time_high fields used by RFC 4122 version 1 UUIDs + * + * @param string $seconds + * @param string $microSeconds + * @return string[] An array containing `low`, `mid`, and `high` keys + * @link http://tools.ietf.org/html/rfc4122#section-4.2.2 + */ + public function calculateTime($seconds, $microSeconds) + { + $uuidTime = new BigNumber('0'); + + $sec = new BigNumber($seconds); + $sec->multiply('10000000'); + + $usec = new BigNumber($microSeconds); + $usec->multiply('10'); + + $uuidTime->add($sec) + ->add($usec) + ->add('122192928000000000'); + + $uuidTimeHex = sprintf('%016s', $uuidTime->convertToBase(16)); + + return array( + 'low' => substr($uuidTimeHex, 8), + 'mid' => substr($uuidTimeHex, 4, 4), + 'hi' => substr($uuidTimeHex, 0, 4), + ); + } +} diff --git a/vendor/ramsey/uuid/src/Converter/Time/DegradedTimeConverter.php b/vendor/ramsey/uuid/src/Converter/Time/DegradedTimeConverter.php new file mode 100644 index 000000000..b94589cd3 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Time/DegradedTimeConverter.php @@ -0,0 +1,42 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Converter\Time; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; + +/** + * DegradedTimeConverter throws `UnsatisfiedDependencyException` exceptions + * if attempting to use time conversion functionality in an environment that + * does not support large integers (i.e. when moontoast/math is not available) + */ +class DegradedTimeConverter implements TimeConverterInterface +{ + /** + * Throws an `UnsatisfiedDependencyException` + * + * @param string $seconds + * @param string $microSeconds + * @return void + * @throws UnsatisfiedDependencyException if called on a 32-bit system and `Moontoast\Math\BigNumber` is not present + */ + public function calculateTime($seconds, $microSeconds) + { + throw new UnsatisfiedDependencyException( + 'When calling ' . __METHOD__ . ' on a 32-bit system, ' + . 'Moontoast\Math\BigNumber must be present.' + ); + } +} diff --git a/vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php b/vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php new file mode 100644 index 000000000..6a9da74b8 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php @@ -0,0 +1,47 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Converter\Time; + +use Ramsey\Uuid\Converter\TimeConverterInterface; + +/** + * PhpTimeConverter uses built-in PHP functions and standard math operations + * available to the PHP programming language to provide facilities for + * converting parts of time into representations that may be used in UUIDs + */ +class PhpTimeConverter implements TimeConverterInterface +{ + /** + * Uses the provided seconds and micro-seconds to calculate the time_low, + * time_mid, and time_high fields used by RFC 4122 version 1 UUIDs + * + * @param string $seconds + * @param string $microSeconds + * @return string[] An array containing `low`, `mid`, and `high` keys + * @link http://tools.ietf.org/html/rfc4122#section-4.2.2 + */ + public function calculateTime($seconds, $microSeconds) + { + // 0x01b21dd213814000 is the number of 100-ns intervals between the + // UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00. + $uuidTime = ($seconds * 10000000) + ($microSeconds * 10) + 0x01b21dd213814000; + + return array( + 'low' => sprintf('%08x', $uuidTime & 0xffffffff), + 'mid' => sprintf('%04x', ($uuidTime >> 32) & 0xffff), + 'hi' => sprintf('%04x', ($uuidTime >> 48) & 0x0fff), + ); + } +} diff --git a/vendor/ramsey/uuid/src/Converter/TimeConverterInterface.php b/vendor/ramsey/uuid/src/Converter/TimeConverterInterface.php new file mode 100644 index 000000000..382008ac3 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/TimeConverterInterface.php @@ -0,0 +1,35 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Converter; + +/** + * TimeConverterInterface provides facilities for converting parts of time into + * representations that may be used in UUIDs + */ +interface TimeConverterInterface +{ + /** + * Uses the provided seconds and micro-seconds to calculate the time_low, + * time_mid, and time_high fields used by RFC 4122 version 1 UUIDs + * + * @param string $seconds + * @param string $microSeconds + * @return string[] An array guaranteed to contain `low`, `mid`, and `high` keys + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if called on a 32-bit system and + * `Moontoast\Math\BigNumber` is not present + * @link http://tools.ietf.org/html/rfc4122#section-4.2.2 + */ + public function calculateTime($seconds, $microSeconds); +} diff --git a/vendor/ramsey/uuid/src/DegradedUuid.php b/vendor/ramsey/uuid/src/DegradedUuid.php new file mode 100644 index 000000000..bcf0be800 --- /dev/null +++ b/vendor/ramsey/uuid/src/DegradedUuid.php @@ -0,0 +1,114 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid; + +use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +use Ramsey\Uuid\Exception\UnsupportedOperationException; + +/** + * DegradedUuid represents an RFC 4122 UUID on 32-bit systems + * + * @see Uuid + */ +class DegradedUuid extends Uuid +{ + /** + * @inheritdoc + */ + public function getDateTime() + { + if ($this->getVersion() != 1) { + throw new UnsupportedOperationException('Not a time-based UUID'); + } + + $time = $this->converter->fromHex($this->getTimestampHex()); + + $ts = new \Moontoast\Math\BigNumber($time, 20); + $ts->subtract('122192928000000000'); + $ts->divide('10000000.0'); + $ts->round(); + $unixTime = $ts->getValue(); + + return new \DateTime("@{$unixTime}"); + } + + /** + * For degraded UUIDs, throws an `UnsatisfiedDependencyException` when + * called on a 32-bit system + * + * @throws UnsatisfiedDependencyException if called on a 32-bit system + */ + public function getFields() + { + throw new UnsatisfiedDependencyException( + 'Cannot call ' . __METHOD__ . ' on a 32-bit system, since some ' + . 'values overflow the system max integer value' + . '; consider calling getFieldsHex instead' + ); + } + + /** + * For degraded UUIDs, throws an `UnsatisfiedDependencyException` when + * called on a 32-bit system + * + * @throws UnsatisfiedDependencyException if called on a 32-bit system + */ + public function getNode() + { + throw new UnsatisfiedDependencyException( + 'Cannot call ' . __METHOD__ . ' on a 32-bit system, since node ' + . 'is an unsigned 48-bit integer and can overflow the system ' + . 'max integer value' + . '; consider calling getNodeHex instead' + ); + } + + /** + * For degraded UUIDs, throws an `UnsatisfiedDependencyException` when + * called on a 32-bit system + * + * @throws UnsatisfiedDependencyException if called on a 32-bit system + */ + public function getTimeLow() + { + throw new UnsatisfiedDependencyException( + 'Cannot call ' . __METHOD__ . ' on a 32-bit system, since time_low ' + . 'is an unsigned 32-bit integer and can overflow the system ' + . 'max integer value' + . '; consider calling getTimeLowHex instead' + ); + } + + /** + * For degraded UUIDs, throws an `UnsatisfiedDependencyException` when + * called on a 32-bit system + * + * @throws UnsatisfiedDependencyException if called on a 32-bit system + * @throws UnsupportedOperationException If this UUID is not a version 1 UUID + */ + public function getTimestamp() + { + if ($this->getVersion() != 1) { + throw new UnsupportedOperationException('Not a time-based UUID'); + } + + throw new UnsatisfiedDependencyException( + 'Cannot call ' . __METHOD__ . ' on a 32-bit system, since timestamp ' + . 'is an unsigned 60-bit integer and can overflow the system ' + . 'max integer value' + . '; consider calling getTimestampHex instead' + ); + } +} diff --git a/vendor/ramsey/uuid/src/Exception/InvalidUuidStringException.php b/vendor/ramsey/uuid/src/Exception/InvalidUuidStringException.php new file mode 100644 index 000000000..0e480649d --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/InvalidUuidStringException.php @@ -0,0 +1,22 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Exception; + +/** + * Thrown to indicate that the parsed UUID string is invalid. + */ +class InvalidUuidStringException extends \InvalidArgumentException +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/UnsatisfiedDependencyException.php b/vendor/ramsey/uuid/src/Exception/UnsatisfiedDependencyException.php new file mode 100644 index 000000000..8b5d5d08e --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/UnsatisfiedDependencyException.php @@ -0,0 +1,23 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Exception; + +/** + * Thrown to indicate that the requested operation has dependencies that have not + * been satisfied. + */ +class UnsatisfiedDependencyException extends \RuntimeException +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/UnsupportedOperationException.php b/vendor/ramsey/uuid/src/Exception/UnsupportedOperationException.php new file mode 100644 index 000000000..b371b6823 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/UnsupportedOperationException.php @@ -0,0 +1,22 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Exception; + +/** + * Thrown to indicate that the requested operation is not supported. + */ +class UnsupportedOperationException extends \RuntimeException +{ +} diff --git a/vendor/ramsey/uuid/src/FeatureSet.php b/vendor/ramsey/uuid/src/FeatureSet.php new file mode 100644 index 000000000..56a774eab --- /dev/null +++ b/vendor/ramsey/uuid/src/FeatureSet.php @@ -0,0 +1,333 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Generator\PeclUuidTimeGenerator; +use Ramsey\Uuid\Provider\Node\FallbackNodeProvider; +use Ramsey\Uuid\Provider\Node\RandomNodeProvider; +use Ramsey\Uuid\Provider\Node\SystemNodeProvider; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\Number\BigNumberConverter; +use Ramsey\Uuid\Converter\Number\DegradedNumberConverter; +use Ramsey\Uuid\Converter\Time\BigNumberTimeConverter; +use Ramsey\Uuid\Converter\Time\DegradedTimeConverter; +use Ramsey\Uuid\Converter\Time\PhpTimeConverter; +use Ramsey\Uuid\Provider\Time\SystemTimeProvider; +use Ramsey\Uuid\Builder\UuidBuilderInterface; +use Ramsey\Uuid\Builder\DefaultUuidBuilder; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Codec\StringCodec; +use Ramsey\Uuid\Codec\GuidStringCodec; +use Ramsey\Uuid\Builder\DegradedUuidBuilder; +use Ramsey\Uuid\Generator\RandomGeneratorFactory; +use Ramsey\Uuid\Generator\RandomGeneratorInterface; +use Ramsey\Uuid\Generator\TimeGeneratorFactory; +use Ramsey\Uuid\Generator\TimeGeneratorInterface; +use Ramsey\Uuid\Provider\TimeProviderInterface; +use Ramsey\Uuid\Provider\NodeProviderInterface; + +/** + * FeatureSet detects and exposes available features in the current environment + * (32- or 64-bit, available dependencies, etc.) + */ +class FeatureSet +{ + /** + * @var bool + */ + private $disableBigNumber = false; + + /** + * @var bool + */ + private $disable64Bit = false; + + /** + * @var bool + */ + private $ignoreSystemNode = false; + + /** + * @var bool + */ + private $enablePecl = false; + + /** + * @var UuidBuilderInterface + */ + private $builder; + + /** + * @var CodecInterface + */ + private $codec; + + /** + * @var NodeProviderInterface + */ + private $nodeProvider; + + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var RandomGeneratorInterface + */ + private $randomGenerator; + + /** + * @var TimeGeneratorInterface + */ + private $timeGenerator; + + /** + * Constructs a `FeatureSet` for use by a `UuidFactory` to determine or set + * features available to the environment + * + * @param bool $useGuids Whether to build UUIDs using the `GuidStringCodec` + * @param bool $force32Bit Whether to force the use of 32-bit functionality + * (primarily for testing purposes) + * @param bool $forceNoBigNumber Whether to disable the use of moontoast/math + * `BigNumber` (primarily for testing purposes) + * @param bool $ignoreSystemNode Whether to disable attempts to check for + * the system host ID (primarily for testing purposes) + * @param bool $enablePecl Whether to enable the use of the `PeclUuidTimeGenerator` + * to generate version 1 UUIDs + */ + public function __construct( + $useGuids = false, + $force32Bit = false, + $forceNoBigNumber = false, + $ignoreSystemNode = false, + $enablePecl = false + ) { + $this->disableBigNumber = $forceNoBigNumber; + $this->disable64Bit = $force32Bit; + $this->ignoreSystemNode = $ignoreSystemNode; + $this->enablePecl = $enablePecl; + + $this->numberConverter = $this->buildNumberConverter(); + $this->builder = $this->buildUuidBuilder(); + $this->codec = $this->buildCodec($useGuids); + $this->nodeProvider = $this->buildNodeProvider(); + $this->randomGenerator = $this->buildRandomGenerator(); + $this->setTimeProvider(new SystemTimeProvider()); + } + + /** + * Returns the builder configured for this environment + * + * @return UuidBuilderInterface + */ + public function getBuilder() + { + return $this->builder; + } + + /** + * Returns the UUID UUID coder-decoder configured for this environment + * + * @return CodecInterface + */ + public function getCodec() + { + return $this->codec; + } + + /** + * Returns the system node ID provider configured for this environment + * + * @return NodeProviderInterface + */ + public function getNodeProvider() + { + return $this->nodeProvider; + } + + /** + * Returns the number converter configured for this environment + * + * @return NumberConverterInterface + */ + public function getNumberConverter() + { + return $this->numberConverter; + } + + /** + * Returns the random UUID generator configured for this environment + * + * @return RandomGeneratorInterface + */ + public function getRandomGenerator() + { + return $this->randomGenerator; + } + + /** + * Returns the time-based UUID generator configured for this environment + * + * @return TimeGeneratorInterface + */ + public function getTimeGenerator() + { + return $this->timeGenerator; + } + + /** + * Sets the time provider for use in this environment + * + * @param TimeProviderInterface $timeProvider + */ + public function setTimeProvider(TimeProviderInterface $timeProvider) + { + $this->timeGenerator = $this->buildTimeGenerator($timeProvider); + } + + /** + * Determines which UUID coder-decoder to use and returns the configured + * codec for this environment + * + * @param bool $useGuids Whether to build UUIDs using the `GuidStringCodec` + * @return CodecInterface + */ + protected function buildCodec($useGuids = false) + { + if ($useGuids) { + return new GuidStringCodec($this->builder); + } + + return new StringCodec($this->builder); + } + + /** + * Determines which system node ID provider to use and returns the configured + * system node ID provider for this environment + * + * @return NodeProviderInterface + */ + protected function buildNodeProvider() + { + if ($this->ignoreSystemNode) { + return new RandomNodeProvider(); + } + + return new FallbackNodeProvider([ + new SystemNodeProvider(), + new RandomNodeProvider() + ]); + } + + /** + * Determines which number converter to use and returns the configured + * number converter for this environment + * + * @return NumberConverterInterface + */ + protected function buildNumberConverter() + { + if ($this->hasBigNumber()) { + return new BigNumberConverter(); + } + + return new DegradedNumberConverter(); + } + + /** + * Determines which random UUID generator to use and returns the configured + * random UUID generator for this environment + * + * @return RandomGeneratorInterface + */ + protected function buildRandomGenerator() + { + return (new RandomGeneratorFactory())->getGenerator(); + } + + /** + * Determines which time-based UUID generator to use and returns the configured + * time-based UUID generator for this environment + * + * @param TimeProviderInterface $timeProvider + * @return TimeGeneratorInterface + */ + protected function buildTimeGenerator(TimeProviderInterface $timeProvider) + { + if ($this->enablePecl) { + return new PeclUuidTimeGenerator(); + } + + return (new TimeGeneratorFactory( + $this->nodeProvider, + $this->buildTimeConverter(), + $timeProvider + ))->getGenerator(); + } + + /** + * Determines which time converter to use and returns the configured + * time converter for this environment + * + * @return TimeConverterInterface + */ + protected function buildTimeConverter() + { + if ($this->is64BitSystem()) { + return new PhpTimeConverter(); + } elseif ($this->hasBigNumber()) { + return new BigNumberTimeConverter(); + } + + return new DegradedTimeConverter(); + } + + /** + * Determines which UUID builder to use and returns the configured UUID + * builder for this environment + * + * @return UuidBuilderInterface + */ + protected function buildUuidBuilder() + { + if ($this->is64BitSystem()) { + return new DefaultUuidBuilder($this->numberConverter); + } + + return new DegradedUuidBuilder($this->numberConverter); + } + + /** + * Returns true if the system has `Moontoast\Math\BigNumber` + * + * @return bool + */ + protected function hasBigNumber() + { + return class_exists('Moontoast\Math\BigNumber') && !$this->disableBigNumber; + } + + /** + * Returns true if the system is 64-bit, false otherwise + * + * @return bool + */ + protected function is64BitSystem() + { + return PHP_INT_SIZE == 8 && !$this->disable64Bit; + } +} diff --git a/vendor/ramsey/uuid/src/Generator/CombGenerator.php b/vendor/ramsey/uuid/src/Generator/CombGenerator.php new file mode 100644 index 000000000..7a9482318 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/CombGenerator.php @@ -0,0 +1,88 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Converter\NumberConverterInterface; + +/** + * CombGenerator provides functionality to generate COMB (combined GUID/timestamp) + * sequential UUIDs + * + * @link https://en.wikipedia.org/wiki/Globally_unique_identifier#Sequential_algorithms + */ +class CombGenerator implements RandomGeneratorInterface +{ + const TIMESTAMP_BYTES = 6; + + /** + * @var RandomGeneratorInterface + */ + private $randomGenerator; + + /** + * @var NumberConverterInterface + */ + private $converter; + + /** + * Constructs a `CombGenerator` using a random-number generator and a number converter + * + * @param RandomGeneratorInterface $generator Random-number generator for the non-time part. + * @param NumberConverterInterface $numberConverter Instance of number converter. + */ + public function __construct(RandomGeneratorInterface $generator, NumberConverterInterface $numberConverter) + { + $this->converter = $numberConverter; + $this->randomGenerator = $generator; + } + + /** + * Generates a string of binary data of the specified length + * + * @param integer $length The number of bytes of random binary data to generate + * @return string A binary string + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + * @throws \InvalidArgumentException if length is not a positive integer + * @throws \Exception + */ + public function generate($length) + { + if ($length < self::TIMESTAMP_BYTES || $length < 0) { + throw new \InvalidArgumentException('Length must be a positive integer.'); + } + + $hash = ''; + + if (self::TIMESTAMP_BYTES > 0 && $length > self::TIMESTAMP_BYTES) { + $hash = $this->randomGenerator->generate($length - self::TIMESTAMP_BYTES); + } + + $lsbTime = str_pad($this->converter->toHex($this->timestamp()), self::TIMESTAMP_BYTES * 2, '0', STR_PAD_LEFT); + + return hex2bin(str_pad(bin2hex($hash), $length - self::TIMESTAMP_BYTES, '0') . $lsbTime); + } + + /** + * Returns current timestamp as integer, precise to 0.00001 seconds + * + * @return string + */ + private function timestamp() + { + $time = explode(' ', microtime(false)); + + return $time[1] . substr($time[0], 2, 5); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php b/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php new file mode 100644 index 000000000..c9969b3af --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php @@ -0,0 +1,138 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\BinaryUtils; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Provider\TimeProviderInterface; + +/** + * DefaultTimeGenerator provides functionality to generate strings of binary + * data for version 1 UUIDs based on a host ID, sequence number, and the current + * time + */ +class DefaultTimeGenerator implements TimeGeneratorInterface +{ + /** + * @var NodeProviderInterface + */ + private $nodeProvider; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * @var TimeProviderInterface + */ + private $timeProvider; + + /** + * Constructs a `DefaultTimeGenerator` using a node provider, time converter, + * and time provider + * + * @param NodeProviderInterface $nodeProvider + * @param TimeConverterInterface $timeConverter + * @param TimeProviderInterface $timeProvider + */ + public function __construct( + NodeProviderInterface $nodeProvider, + TimeConverterInterface $timeConverter, + TimeProviderInterface $timeProvider + ) { + $this->nodeProvider = $nodeProvider; + $this->timeConverter = $timeConverter; + $this->timeProvider = $timeProvider; + } + + /** + * Generate a version 1 UUID from a host ID, sequence number, and the current time + * + * If $node is not given, we will attempt to obtain the local hardware + * address. If $clockSeq is given, it is used as the sequence number; + * otherwise a random 14-bit sequence number is chosen. + * + * @param int|string $node A 48-bit number representing the hardware address + * This number may be represented as an integer or a hexadecimal string. + * @param int $clockSeq A 14-bit number used to help avoid duplicates that + * could arise when the clock is set backwards in time or if the node ID + * changes. + * @return string A binary string + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if called on a 32-bit system and + * `Moontoast\Math\BigNumber` is not present + * @throws \InvalidArgumentException + * @throws \Exception if it was not possible to gather sufficient entropy + */ + public function generate($node = null, $clockSeq = null) + { + $node = $this->getValidNode($node); + + if ($clockSeq === null) { + // Not using "stable storage"; see RFC 4122, Section 4.2.1.1 + $clockSeq = random_int(0, 0x3fff); + } + + // Create a 60-bit time value as a count of 100-nanosecond intervals + // since 00:00:00.00, 15 October 1582 + $timeOfDay = $this->timeProvider->currentTime(); + $uuidTime = $this->timeConverter->calculateTime($timeOfDay['sec'], $timeOfDay['usec']); + + $timeHi = BinaryUtils::applyVersion($uuidTime['hi'], 1); + $clockSeqHi = BinaryUtils::applyVariant($clockSeq >> 8); + + $hex = vsprintf( + '%08s%04s%04s%02s%02s%012s', + array( + $uuidTime['low'], + $uuidTime['mid'], + sprintf('%04x', $timeHi), + sprintf('%02x', $clockSeqHi), + sprintf('%02x', $clockSeq & 0xff), + $node, + ) + ); + + return hex2bin($hex); + } + + /** + * Uses the node provider given when constructing this instance to get + * the node ID (usually a MAC address) + * + * @param string|int $node A node value that may be used to override the node provider + * @return string Hexadecimal representation of the node ID + * @throws \InvalidArgumentException + * @throws \Exception + */ + protected function getValidNode($node) + { + if ($node === null) { + $node = $this->nodeProvider->getNode(); + } + + // Convert the node to hex, if it is still an integer + if (is_int($node)) { + $node = sprintf('%012x', $node); + } + + if (!ctype_xdigit($node) || strlen($node) > 12) { + throw new \InvalidArgumentException('Invalid node value'); + } + + return strtolower(sprintf('%012s', $node)); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/MtRandGenerator.php b/vendor/ramsey/uuid/src/Generator/MtRandGenerator.php new file mode 100644 index 000000000..f58b78357 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/MtRandGenerator.php @@ -0,0 +1,41 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +/** + * MtRandRandomGenerator provides functionality to generate strings of random + * binary data using the `mt_rand()` PHP function + * + * @link http://php.net/mt_rand + */ +class MtRandGenerator implements RandomGeneratorInterface +{ + /** + * Generates a string of random binary data of the specified length + * + * @param integer $length The number of bytes of random binary data to generate + * @return string A binary string + */ + public function generate($length) + { + $bytes = ''; + + for ($i = 1; $i <= $length; $i++) { + $bytes = chr(mt_rand(0, 255)) . $bytes; + } + + return $bytes; + } +} diff --git a/vendor/ramsey/uuid/src/Generator/OpenSslGenerator.php b/vendor/ramsey/uuid/src/Generator/OpenSslGenerator.php new file mode 100644 index 000000000..e8ec6a4d8 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/OpenSslGenerator.php @@ -0,0 +1,38 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +/** + * OpenSslRandomGenerator provides functionality to generate strings of random + * binary data using the `openssl_random_pseudo_bytes()` PHP function + * + * The use of this generator requires PHP to be compiled using the + * `--with-openssl` option. + * + * @link http://php.net/openssl_random_pseudo_bytes + */ +class OpenSslGenerator implements RandomGeneratorInterface +{ + /** + * Generates a string of random binary data of the specified length + * + * @param integer $length The number of bytes of random binary data to generate + * @return string A binary string + */ + public function generate($length) + { + return openssl_random_pseudo_bytes($length); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php b/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php new file mode 100644 index 000000000..fc2ef7e4d --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php @@ -0,0 +1,37 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +/** + * PeclUuidRandomGenerator provides functionality to generate strings of random + * binary data using the PECL UUID PHP extension + * + * @link https://pecl.php.net/package/uuid + */ +class PeclUuidRandomGenerator implements RandomGeneratorInterface +{ + /** + * Generates a string of random binary data of the specified length + * + * @param integer $length The number of bytes of random binary data to generate + * @return string A binary string + */ + public function generate($length) + { + $uuid = uuid_create(UUID_TYPE_RANDOM); + + return uuid_parse($uuid); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/PeclUuidTimeGenerator.php b/vendor/ramsey/uuid/src/Generator/PeclUuidTimeGenerator.php new file mode 100644 index 000000000..7ccf16fd9 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/PeclUuidTimeGenerator.php @@ -0,0 +1,38 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +/** + * PeclUuidTimeGenerator provides functionality to generate strings of binary + * data for version 1 UUIDs using the PECL UUID PHP extension + * + * @link https://pecl.php.net/package/uuid + */ +class PeclUuidTimeGenerator implements TimeGeneratorInterface +{ + /** + * Generate a version 1 UUID using the PECL UUID extension + * + * @param int|string $node Not used in this context + * @param int $clockSeq Not used in this context + * @return string A binary string + */ + public function generate($node = null, $clockSeq = null) + { + $uuid = uuid_create(UUID_TYPE_TIME); + + return uuid_parse($uuid); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php b/vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php new file mode 100644 index 000000000..aaa285df0 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php @@ -0,0 +1,37 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +/** + * RandomBytesGenerator provides functionality to generate strings of random + * binary data using `random_bytes()` function in PHP 7+ or paragonie/random_compat + * + * @link http://php.net/random_bytes + * @link https://github.com/paragonie/random_compat + */ +class RandomBytesGenerator implements RandomGeneratorInterface +{ + /** + * Generates a string of random binary data of the specified length + * + * @param integer $length The number of bytes of random binary data to generate + * @return string A binary string + * @throws \Exception if it was not possible to gather sufficient entropy + */ + public function generate($length) + { + return random_bytes($length); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php b/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php new file mode 100644 index 000000000..39110622f --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php @@ -0,0 +1,31 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +/** + * A factory for retrieving a random generator, based on the environment + */ +class RandomGeneratorFactory +{ + /** + * Returns a default random generator, based on the current environment + * + * @return RandomGeneratorInterface + */ + public static function getGenerator() + { + return new RandomBytesGenerator(); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php b/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php new file mode 100644 index 000000000..3a1bcae7e --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php @@ -0,0 +1,33 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +/** + * RandomGeneratorInterface provides functionality to generate strings of random + * binary data + */ +interface RandomGeneratorInterface +{ + /** + * Generates a string of random binary data of the specified length + * + * @param integer $length The number of bytes of random binary data to generate + * @return string A binary string + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + * @throws \InvalidArgumentException + * @throws \Exception if it was not possible to gather sufficient entropy + */ + public function generate($length); +} diff --git a/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php b/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php new file mode 100644 index 000000000..25b54a834 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php @@ -0,0 +1,62 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +use RandomLib\Generator; +use RandomLib\Factory; + +/** + * RandomLibAdapter provides functionality to generate strings of random + * binary data using the ircmaxell/random-lib library + * + * @link https://packagist.org/packages/ircmaxell/random-lib + */ +class RandomLibAdapter implements RandomGeneratorInterface +{ + /** + * @var Generator + */ + private $generator; + + /** + * Constructs a `RandomLibAdapter` using a `RandomLib\Generator` + * + * By default, if no `Generator` is passed in, this creates a medium-strength + * generator to use when generating random binary data. + * + * @param Generator $generator An ircmaxell/random-lib `Generator` + */ + public function __construct(Generator $generator = null) + { + $this->generator = $generator; + + if ($this->generator === null) { + $factory = new Factory(); + + $this->generator = $factory->getMediumStrengthGenerator(); + } + } + + /** + * Generates a string of random binary data of the specified length + * + * @param integer $length The number of bytes of random binary data to generate + * @return string A binary string + */ + public function generate($length) + { + return $this->generator->generate($length); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/SodiumRandomGenerator.php b/vendor/ramsey/uuid/src/Generator/SodiumRandomGenerator.php new file mode 100644 index 000000000..6b08f5402 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/SodiumRandomGenerator.php @@ -0,0 +1,36 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +/** + * SodiumRandomGenerator provides functionality to generate strings of random + * binary data using the PECL libsodium extension + * + * @link http://pecl.php.net/package/libsodium + * @link https://paragonie.com/book/pecl-libsodium + */ +class SodiumRandomGenerator implements RandomGeneratorInterface +{ + /** + * Generates a string of random binary data of the specified length + * + * @param integer $length The number of bytes of random binary data to generate + * @return string A binary string + */ + public function generate($length) + { + return \Sodium\randombytes_buf($length); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php b/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php new file mode 100644 index 000000000..24d501bbf --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php @@ -0,0 +1,72 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Provider\TimeProviderInterface; + +/** + * A factory for retrieving a time generator, based on the environment + */ +class TimeGeneratorFactory +{ + /** + * @var NodeProviderInterface + */ + private $nodeProvider; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * @var TimeProviderInterface + */ + private $timeProvider; + + /** + * Constructs a `TimeGeneratorFactory` using a node provider, time converter, + * and time provider + * + * @param NodeProviderInterface $nodeProvider + * @param TimeConverterInterface $timeConverter + * @param TimeProviderInterface $timeProvider + */ + public function __construct( + NodeProviderInterface $nodeProvider, + TimeConverterInterface $timeConverter, + TimeProviderInterface $timeProvider + ) { + $this->nodeProvider = $nodeProvider; + $this->timeConverter = $timeConverter; + $this->timeProvider = $timeProvider; + } + + /** + * Returns a default time generator, based on the current environment + * + * @return TimeGeneratorInterface + */ + public function getGenerator() + { + return new DefaultTimeGenerator( + $this->nodeProvider, + $this->timeConverter, + $this->timeProvider + ); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/TimeGeneratorInterface.php b/vendor/ramsey/uuid/src/Generator/TimeGeneratorInterface.php new file mode 100644 index 000000000..cb182ea00 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/TimeGeneratorInterface.php @@ -0,0 +1,39 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Generator; + +/** + * TimeGeneratorInterface provides functionality to generate strings of binary + * data for version 1 UUIDs based on a host ID, sequence number, and the current + * time + */ +interface TimeGeneratorInterface +{ + /** + * Generate a version 1 UUID from a host ID, sequence number, and the current time + * + * @param int|string $node A 48-bit number representing the hardware address + * This number may be represented as an integer or a hexadecimal string. + * @param int $clockSeq A 14-bit number used to help avoid duplicates that + * could arise when the clock is set backwards in time or if the node ID + * changes. + * @return string A binary string + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if called on a 32-bit system and + * `Moontoast\Math\BigNumber` is not present + * @throws \InvalidArgumentException + * @throws \Exception if it was not possible to gather sufficient entropy + */ + public function generate($node = null, $clockSeq = null); +} diff --git a/vendor/ramsey/uuid/src/Provider/Node/FallbackNodeProvider.php b/vendor/ramsey/uuid/src/Provider/Node/FallbackNodeProvider.php new file mode 100644 index 000000000..289fddeae --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Node/FallbackNodeProvider.php @@ -0,0 +1,58 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Provider\Node; + +use Ramsey\Uuid\Provider\NodeProviderInterface; + +/** + * FallbackNodeProvider attempts to gain the system host ID from an array of + * providers, falling back to the next in line in the event a host ID can not be + * obtained + */ +class FallbackNodeProvider implements NodeProviderInterface +{ + /** + * @var NodeProviderInterface[] + */ + private $nodeProviders; + + /** + * Constructs a `FallbackNodeProvider` using an array of node providers + * + * @param NodeProviderInterface[] $providers Array of node providers + */ + public function __construct(array $providers) + { + $this->nodeProviders = $providers; + } + + /** + * Returns the system node ID by iterating over an array of node providers + * and returning the first non-empty value found + * + * @return string System node ID as a hexadecimal string + * @throws \Exception + */ + public function getNode() + { + foreach ($this->nodeProviders as $provider) { + if ($node = $provider->getNode()) { + return $node; + } + } + + return null; + } +} diff --git a/vendor/ramsey/uuid/src/Provider/Node/RandomNodeProvider.php b/vendor/ramsey/uuid/src/Provider/Node/RandomNodeProvider.php new file mode 100644 index 000000000..76c570d7f --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Node/RandomNodeProvider.php @@ -0,0 +1,42 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Provider\Node; + +use Ramsey\Uuid\Provider\NodeProviderInterface; + +/** + * RandomNodeProvider provides functionality to generate a random node ID, in + * the event that the node ID could not be obtained from the host system + * + * @link http://tools.ietf.org/html/rfc4122#section-4.5 + */ +class RandomNodeProvider implements NodeProviderInterface +{ + /** + * Returns the system node ID + * + * @return string System node ID as a hexadecimal string + * @throws \Exception if it was not possible to gather sufficient entropy + */ + public function getNode() + { + $node = hexdec(bin2hex(random_bytes(6))); + + // Set the multicast bit; see RFC 4122, section 4.5. + $node = $node | 0x010000000000; + + return str_pad(dechex($node), 12, '0', STR_PAD_LEFT); + } +} diff --git a/vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php b/vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php new file mode 100644 index 000000000..ae6a09eaa --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php @@ -0,0 +1,125 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Provider\Node; + +use Ramsey\Uuid\Provider\NodeProviderInterface; + +/** + * SystemNodeProvider provides functionality to get the system node ID (MAC + * address) using external system calls + */ +class SystemNodeProvider implements NodeProviderInterface +{ + /** + * Returns the system node ID + * + * @return string|false System node ID as a hexadecimal string, or false if it is not found + */ + public function getNode() + { + static $node = null; + + if ($node !== null) { + return $node; + } + + $pattern = '/[^:]([0-9A-Fa-f]{2}([:-])[0-9A-Fa-f]{2}(\2[0-9A-Fa-f]{2}){4})[^:]/'; + $matches = array(); + + // first try a linux specific way + $node = $this->getSysfs(); + + // Search the ifconfig output for all MAC addresses and return + // the first one found + if ($node === false) { + if (preg_match_all($pattern, $this->getIfconfig(), $matches, PREG_PATTERN_ORDER)) { + $node = $matches[1][0]; + } + } + if ($node !== false) { + $node = str_replace([':', '-'], '', $node); + } + return $node; + } + + /** + * Returns the network interface configuration for the system + * + * @codeCoverageIgnore + * @return string + */ + protected function getIfconfig() + { + if (strpos(strtolower(ini_get('disable_functions')), 'passthru') !== false) { + return ''; + } + + ob_start(); + switch (strtoupper(substr(php_uname('a'), 0, 3))) { + case 'WIN': + passthru('ipconfig /all 2>&1'); + break; + case 'DAR': + passthru('ifconfig 2>&1'); + break; + case 'FRE': + passthru('netstat -i -f link 2>&1'); + break; + case 'LIN': + default: + passthru('netstat -ie 2>&1'); + break; + } + + return ob_get_clean(); + } + + /** + * Returns mac address from the first system interface via the sysfs interface + * + * @return string|bool + */ + protected function getSysfs() + { + $mac = false; + + if (strtoupper(php_uname('s')) === 'LINUX') { + $addressPaths = glob('/sys/class/net/*/address', GLOB_NOSORT); + + if (empty($addressPaths)) { + return false; + } + + array_walk($addressPaths, function ($addressPath) use (&$macs) { + $macs[] = file_get_contents($addressPath); + }); + + $macs = array_map('trim', $macs); + + // remove invalid entries + $macs = array_filter($macs, function ($mac) { + return + // localhost adapter + $mac !== '00:00:00:00:00:00' && + // must match mac adress + preg_match('/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i', $mac); + }); + + $mac = reset($macs); + } + + return $mac; + } +} diff --git a/vendor/ramsey/uuid/src/Provider/NodeProviderInterface.php b/vendor/ramsey/uuid/src/Provider/NodeProviderInterface.php new file mode 100644 index 000000000..14f747bea --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/NodeProviderInterface.php @@ -0,0 +1,30 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Provider; + +/** + * NodeProviderInterface provides functionality to get the node ID (or host ID + * in the form of the system's MAC address) from a specific type of node provider + */ +interface NodeProviderInterface +{ + /** + * Returns the system node ID + * + * @return string System node ID as a hexadecimal string + * @throws \Exception if it was not possible to gather sufficient entropy + */ + public function getNode(); +} diff --git a/vendor/ramsey/uuid/src/Provider/Time/FixedTimeProvider.php b/vendor/ramsey/uuid/src/Provider/Time/FixedTimeProvider.php new file mode 100644 index 000000000..a62d39c62 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Time/FixedTimeProvider.php @@ -0,0 +1,76 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Provider\Time; + +use Ramsey\Uuid\Provider\TimeProviderInterface; + +/** + * FixedTimeProvider uses an previously-generated timestamp to provide the time + * + * This provider allows the use of a previously-generated timestamp, such as one + * stored in a database, when creating version 1 UUIDs. + */ +class FixedTimeProvider implements TimeProviderInterface +{ + /** + * @var int[] Array containing `sec` and `usec` components of a timestamp + */ + private $fixedTime; + + /** + * Constructs a `FixedTimeProvider` using the provided `$timestamp` + * + * @param int[] Array containing `sec` and `usec` components of a timestamp + * @throws \InvalidArgumentException if the `$timestamp` does not contain `sec` or `usec` components + */ + public function __construct(array $timestamp) + { + if (!array_key_exists('sec', $timestamp) || !array_key_exists('usec', $timestamp)) { + throw new \InvalidArgumentException('Array must contain sec and usec keys.'); + } + + $this->fixedTime = $timestamp; + } + + /** + * Sets the `usec` component of the timestamp + * + * @param int $value The `usec` value to set + */ + public function setUsec($value) + { + $this->fixedTime['usec'] = $value; + } + + /** + * Sets the `sec` component of the timestamp + * + * @param int $value The `sec` value to set + */ + public function setSec($value) + { + $this->fixedTime['sec'] = $value; + } + + /** + * Returns a timestamp array + * + * @return int[] Array containing `sec` and `usec` components of a timestamp + */ + public function currentTime() + { + return $this->fixedTime; + } +} diff --git a/vendor/ramsey/uuid/src/Provider/Time/SystemTimeProvider.php b/vendor/ramsey/uuid/src/Provider/Time/SystemTimeProvider.php new file mode 100644 index 000000000..6442985fa --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Time/SystemTimeProvider.php @@ -0,0 +1,33 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Provider\Time; + +use Ramsey\Uuid\Provider\TimeProviderInterface; + +/** + * SystemTimeProvider uses built-in PHP functions to provide the time + */ +class SystemTimeProvider implements TimeProviderInterface +{ + /** + * Returns a timestamp array + * + * @return int[] Array containing `sec` and `usec` components of a timestamp + */ + public function currentTime() + { + return gettimeofday(); + } +} diff --git a/vendor/ramsey/uuid/src/Provider/TimeProviderInterface.php b/vendor/ramsey/uuid/src/Provider/TimeProviderInterface.php new file mode 100644 index 000000000..ef8099dd1 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/TimeProviderInterface.php @@ -0,0 +1,29 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid\Provider; + +/** + * TimeProviderInterface provides functionality to get the time from a specific + * type of time provider + */ +interface TimeProviderInterface +{ + /** + * Returns a timestamp array + * + * @return int[] Array guaranteed to contain `sec` and `usec` components of a timestamp + */ + public function currentTime(); +} diff --git a/vendor/ramsey/uuid/src/Uuid.php b/vendor/ramsey/uuid/src/Uuid.php new file mode 100644 index 000000000..45f9fa448 --- /dev/null +++ b/vendor/ramsey/uuid/src/Uuid.php @@ -0,0 +1,740 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid; + +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Exception\UnsupportedOperationException; + +/** + * Represents a universally unique identifier (UUID), according to RFC 4122. + * + * This class provides immutable UUID objects (the Uuid class) and the static + * methods `uuid1()`, `uuid3()`, `uuid4()`, and `uuid5()` for generating version + * 1, 3, 4, and 5 UUIDs as specified in RFC 4122. + * + * If all you want is a unique ID, you should probably call `uuid1()` or `uuid4()`. + * Note that `uuid1()` may compromise privacy since it creates a UUID containing + * the computerโs network address. `uuid4()` creates a random UUID. + * + * @link http://tools.ietf.org/html/rfc4122 + * @link http://en.wikipedia.org/wiki/Universally_unique_identifier + * @link http://docs.python.org/3/library/uuid.html + * @link http://docs.oracle.com/javase/6/docs/api/java/util/UUID.html + */ +class Uuid implements UuidInterface +{ + /** + * When this namespace is specified, the name string is a fully-qualified domain name. + * @link http://tools.ietf.org/html/rfc4122#appendix-C + */ + const NAMESPACE_DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; + + /** + * When this namespace is specified, the name string is a URL. + * @link http://tools.ietf.org/html/rfc4122#appendix-C + */ + const NAMESPACE_URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'; + + /** + * When this namespace is specified, the name string is an ISO OID. + * @link http://tools.ietf.org/html/rfc4122#appendix-C + */ + const NAMESPACE_OID = '6ba7b812-9dad-11d1-80b4-00c04fd430c8'; + + /** + * When this namespace is specified, the name string is an X.500 DN in DER or a text output format. + * @link http://tools.ietf.org/html/rfc4122#appendix-C + */ + const NAMESPACE_X500 = '6ba7b814-9dad-11d1-80b4-00c04fd430c8'; + + /** + * The nil UUID is special form of UUID that is specified to have all 128 bits set to zero. + * @link http://tools.ietf.org/html/rfc4122#section-4.1.7 + */ + const NIL = '00000000-0000-0000-0000-000000000000'; + + /** + * Reserved for NCS compatibility. + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + const RESERVED_NCS = 0; + + /** + * Specifies the UUID layout given in RFC 4122. + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + const RFC_4122 = 2; + + /** + * Reserved for Microsoft compatibility. + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + const RESERVED_MICROSOFT = 6; + + /** + * Reserved for future definition. + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + const RESERVED_FUTURE = 7; + + /** + * Regular expression pattern for matching a valid UUID of any variant. + */ + const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$'; + + /** + * Version 1 (time-based) UUID object constant identifier + */ + const UUID_TYPE_TIME = 1; + + /** + * Version 2 (identifier-based) UUID object constant identifier + */ + const UUID_TYPE_IDENTIFIER = 2; + + /** + * Version 3 (name-based and hashed with MD5) UUID object constant identifier + */ + const UUID_TYPE_HASH_MD5 = 3; + + /** + * Version 4 (random) UUID object constant identifier + */ + const UUID_TYPE_RANDOM = 4; + + /** + * Version 5 (name-based and hashed with SHA1) UUID object constant identifier + */ + const UUID_TYPE_HASH_SHA1 = 5; + + /** + * The factory to use when creating UUIDs. + * @var UuidFactoryInterface + */ + private static $factory = null; + + /** + * The codec to use when encoding or decoding UUID strings. + * @var CodecInterface + */ + protected $codec; + + /** + * The fields that make up this UUID. + * + * This is initialized to the nil value. + * + * @var array + * @see UuidInterface::getFieldsHex() + */ + protected $fields = array( + 'time_low' => '00000000', + 'time_mid' => '0000', + 'time_hi_and_version' => '0000', + 'clock_seq_hi_and_reserved' => '00', + 'clock_seq_low' => '00', + 'node' => '000000000000', + ); + + /** + * The number converter to use for converting hex values to/from integers. + * @var NumberConverterInterface + */ + protected $converter; + + /** + * Creates a universally unique identifier (UUID) from an array of fields. + * + * Unless you're making advanced use of this library to generate identifiers + * that deviate from RFC 4122, you probably do not want to instantiate a + * UUID directly. Use the static methods, instead: + * + * ``` + * use Ramsey\Uuid\Uuid; + * + * $timeBasedUuid = Uuid::uuid1(); + * $namespaceMd5Uuid = Uuid::uuid3(Uuid::NAMESPACE_URL, 'http://php.net/'); + * $randomUuid = Uuid::uuid4(); + * $namespaceSha1Uuid = Uuid::uuid5(Uuid::NAMESPACE_URL, 'http://php.net/'); + * ``` + * + * @param array $fields An array of fields from which to construct a UUID; + * see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure. + * @param NumberConverterInterface $converter The number converter to use + * for converting hex values to/from integers. + * @param CodecInterface $codec The codec to use when encoding or decoding + * UUID strings. + */ + public function __construct( + array $fields, + NumberConverterInterface $converter, + CodecInterface $codec + ) { + $this->fields = $fields; + $this->codec = $codec; + $this->converter = $converter; + } + + /** + * Converts this UUID object to a string when the object is used in any + * string context. + * + * @return string + * @link http://www.php.net/manual/en/language.oop5.magic.php#object.tostring + */ + public function __toString() + { + return $this->toString(); + } + + /** + * Converts this UUID object to a string when the object is serialized + * with `json_encode()` + * + * @return string + * @link http://php.net/manual/en/class.jsonserializable.php + */ + public function jsonSerialize() + { + return $this->toString(); + } + + /** + * Converts this UUID object to a string when the object is serialized + * with `serialize()` + * + * @return string + * @link http://php.net/manual/en/class.serializable.php + */ + public function serialize() + { + return $this->toString(); + } + + /** + * Re-constructs the object from its serialized form. + * + * @param string $serialized + * @link http://php.net/manual/en/class.serializable.php + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function unserialize($serialized) + { + $uuid = self::fromString($serialized); + $this->codec = $uuid->codec; + $this->converter = $uuid->converter; + $this->fields = $uuid->fields; + } + + public function compareTo(UuidInterface $other) + { + $comparison = 0; + + if ($this->getMostSignificantBitsHex() < $other->getMostSignificantBitsHex()) { + $comparison = -1; + } elseif ($this->getMostSignificantBitsHex() > $other->getMostSignificantBitsHex()) { + $comparison = 1; + } elseif ($this->getLeastSignificantBitsHex() < $other->getLeastSignificantBitsHex()) { + $comparison = -1; + } elseif ($this->getLeastSignificantBitsHex() > $other->getLeastSignificantBitsHex()) { + $comparison = 1; + } + + return $comparison; + } + + public function equals($other) + { + if (!($other instanceof UuidInterface)) { + return false; + } + + return ($this->compareTo($other) == 0); + } + + public function getBytes() + { + return $this->codec->encodeBinary($this); + } + + /** + * Returns the high field of the clock sequence multiplexed with the variant + * (bits 65-72 of the UUID). + * + * @return int Unsigned 8-bit integer value of clock_seq_hi_and_reserved + */ + public function getClockSeqHiAndReserved() + { + return hexdec($this->getClockSeqHiAndReservedHex()); + } + + public function getClockSeqHiAndReservedHex() + { + return $this->fields['clock_seq_hi_and_reserved']; + } + + /** + * Returns the low field of the clock sequence (bits 73-80 of the UUID). + * + * @return int Unsigned 8-bit integer value of clock_seq_low + */ + public function getClockSeqLow() + { + return hexdec($this->getClockSeqLowHex()); + } + + public function getClockSeqLowHex() + { + return $this->fields['clock_seq_low']; + } + + /** + * Returns the clock sequence value associated with this UUID. + * + * For UUID version 1, the clock sequence is used to help avoid + * duplicates that could arise when the clock is set backwards in time + * or if the node ID changes. + * + * For UUID version 3 or 5, the clock sequence is a 14-bit value + * constructed from a name as described in RFC 4122, Section 4.3. + * + * For UUID version 4, clock sequence is a randomly or pseudo-randomly + * generated 14-bit value as described in RFC 4122, Section 4.4. + * + * @return int Unsigned 14-bit integer value of clock sequence + * @link http://tools.ietf.org/html/rfc4122#section-4.1.5 + */ + public function getClockSequence() + { + return (($this->getClockSeqHiAndReserved() & 0x3f) << 8) + | $this->getClockSeqLow(); + } + + public function getClockSequenceHex() + { + return sprintf('%04x', $this->getClockSequence()); + } + + public function getNumberConverter() + { + return $this->converter; + } + + /** + * @inheritdoc + */ + public function getDateTime() + { + if ($this->getVersion() != 1) { + throw new UnsupportedOperationException('Not a time-based UUID'); + } + + $unixTime = ($this->getTimestamp() - 0x01b21dd213814000) / 1e7; + $unixTime = number_format($unixTime, 0, '', ''); + + return new \DateTime("@{$unixTime}"); + } + + /** + * Returns an array of the fields of this UUID, with keys named according + * to the RFC 4122 names for the fields. + * + * * **time_low**: The low field of the timestamp, an unsigned 32-bit integer + * * **time_mid**: The middle field of the timestamp, an unsigned 16-bit integer + * * **time_hi_and_version**: The high field of the timestamp multiplexed with + * the version number, an unsigned 16-bit integer + * * **clock_seq_hi_and_reserved**: The high field of the clock sequence + * multiplexed with the variant, an unsigned 8-bit integer + * * **clock_seq_low**: The low field of the clock sequence, an unsigned + * 8-bit integer + * * **node**: The spatially unique node identifier, an unsigned 48-bit + * integer + * + * @return array The UUID fields represented as integer values + * @link http://tools.ietf.org/html/rfc4122#section-4.1.2 + */ + public function getFields() + { + return array( + 'time_low' => $this->getTimeLow(), + 'time_mid' => $this->getTimeMid(), + 'time_hi_and_version' => $this->getTimeHiAndVersion(), + 'clock_seq_hi_and_reserved' => $this->getClockSeqHiAndReserved(), + 'clock_seq_low' => $this->getClockSeqLow(), + 'node' => $this->getNode(), + ); + } + + public function getFieldsHex() + { + return $this->fields; + } + + public function getHex() + { + return str_replace('-', '', $this->toString()); + } + + /** + * @inheritdoc + */ + public function getInteger() + { + return $this->converter->fromHex($this->getHex()); + } + + /** + * Returns the least significant 64 bits of this UUID's 128 bit value. + * + * @return mixed Converted representation of the unsigned 64-bit integer value + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + */ + public function getLeastSignificantBits() + { + return $this->converter->fromHex($this->getLeastSignificantBitsHex()); + } + + public function getLeastSignificantBitsHex() + { + return sprintf( + '%02s%02s%012s', + $this->fields['clock_seq_hi_and_reserved'], + $this->fields['clock_seq_low'], + $this->fields['node'] + ); + } + + /** + * Returns the most significant 64 bits of this UUID's 128 bit value. + * + * @return mixed Converted representation of the unsigned 64-bit integer value + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + */ + public function getMostSignificantBits() + { + return $this->converter->fromHex($this->getMostSignificantBitsHex()); + } + + public function getMostSignificantBitsHex() + { + return sprintf( + '%08s%04s%04s', + $this->fields['time_low'], + $this->fields['time_mid'], + $this->fields['time_hi_and_version'] + ); + } + + /** + * Returns the node value associated with this UUID + * + * For UUID version 1, the node field consists of an IEEE 802 MAC + * address, usually the host address. For systems with multiple IEEE + * 802 addresses, any available one can be used. The lowest addressed + * octet (octet number 10) contains the global/local bit and the + * unicast/multicast bit, and is the first octet of the address + * transmitted on an 802.3 LAN. + * + * For systems with no IEEE address, a randomly or pseudo-randomly + * generated value may be used; see RFC 4122, Section 4.5. The + * multicast bit must be set in such addresses, in order that they + * will never conflict with addresses obtained from network cards. + * + * For UUID version 3 or 5, the node field is a 48-bit value constructed + * from a name as described in RFC 4122, Section 4.3. + * + * For UUID version 4, the node field is a randomly or pseudo-randomly + * generated 48-bit value as described in RFC 4122, Section 4.4. + * + * @return int Unsigned 48-bit integer value of node + * @link http://tools.ietf.org/html/rfc4122#section-4.1.6 + */ + public function getNode() + { + return hexdec($this->getNodeHex()); + } + + public function getNodeHex() + { + return $this->fields['node']; + } + + /** + * Returns the high field of the timestamp multiplexed with the version + * number (bits 49-64 of the UUID). + * + * @return int Unsigned 16-bit integer value of time_hi_and_version + */ + public function getTimeHiAndVersion() + { + return hexdec($this->getTimeHiAndVersionHex()); + } + + public function getTimeHiAndVersionHex() + { + return $this->fields['time_hi_and_version']; + } + + /** + * Returns the low field of the timestamp (the first 32 bits of the UUID). + * + * @return int Unsigned 32-bit integer value of time_low + */ + public function getTimeLow() + { + return hexdec($this->getTimeLowHex()); + } + + public function getTimeLowHex() + { + return $this->fields['time_low']; + } + + /** + * Returns the middle field of the timestamp (bits 33-48 of the UUID). + * + * @return int Unsigned 16-bit integer value of time_mid + */ + public function getTimeMid() + { + return hexdec($this->getTimeMidHex()); + } + + public function getTimeMidHex() + { + return $this->fields['time_mid']; + } + + /** + * Returns the timestamp value associated with this UUID. + * + * The 60 bit timestamp value is constructed from the time_low, + * time_mid, and time_hi fields of this UUID. The resulting + * timestamp is measured in 100-nanosecond units since midnight, + * October 15, 1582 UTC. + * + * The timestamp value is only meaningful in a time-based UUID, which + * has version type 1. If this UUID is not a time-based UUID then + * this method throws UnsupportedOperationException. + * + * @return int Unsigned 60-bit integer value of the timestamp + * @throws UnsupportedOperationException If this UUID is not a version 1 UUID + * @link http://tools.ietf.org/html/rfc4122#section-4.1.4 + */ + public function getTimestamp() + { + if ($this->getVersion() != 1) { + throw new UnsupportedOperationException('Not a time-based UUID'); + } + + return hexdec($this->getTimestampHex()); + } + + /** + * @inheritdoc + */ + public function getTimestampHex() + { + if ($this->getVersion() != 1) { + throw new UnsupportedOperationException('Not a time-based UUID'); + } + + return sprintf( + '%03x%04s%08s', + ($this->getTimeHiAndVersion() & 0x0fff), + $this->fields['time_mid'], + $this->fields['time_low'] + ); + } + + public function getUrn() + { + return 'urn:uuid:' . $this->toString(); + } + + public function getVariant() + { + $clockSeq = $this->getClockSeqHiAndReserved(); + if (0 === ($clockSeq & 0x80)) { + $variant = self::RESERVED_NCS; + } elseif (0 === ($clockSeq & 0x40)) { + $variant = self::RFC_4122; + } elseif (0 === ($clockSeq & 0x20)) { + $variant = self::RESERVED_MICROSOFT; + } else { + $variant = self::RESERVED_FUTURE; + } + + return $variant; + } + + public function getVersion() + { + if ($this->getVariant() == self::RFC_4122) { + return (int) (($this->getTimeHiAndVersion() >> 12) & 0x0f); + } + + return null; + } + + public function toString() + { + return $this->codec->encode($this); + } + + /** + * Returns the currently set factory used to create UUIDs. + * + * @return UuidFactoryInterface + */ + public static function getFactory() + { + if (!self::$factory) { + self::$factory = new UuidFactory(); + } + + return self::$factory; + } + + /** + * Sets the factory used to create UUIDs. + * + * @param UuidFactoryInterface $factory + */ + public static function setFactory(UuidFactoryInterface $factory) + { + self::$factory = $factory; + } + + /** + * Creates a UUID from a byte string. + * + * @param string $bytes + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + * @throws \InvalidArgumentException + */ + public static function fromBytes($bytes) + { + return self::getFactory()->fromBytes($bytes); + } + + /** + * Creates a UUID from the string standard representation. + * + * @param string $name A string that specifies a UUID + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public static function fromString($name) + { + return self::getFactory()->fromString($name); + } + + /** + * Creates a UUID from a 128-bit integer string. + * + * @param string $integer String representation of 128-bit integer + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public static function fromInteger($integer) + { + return self::getFactory()->fromInteger($integer); + } + + /** + * Check if a string is a valid UUID. + * + * @param string $uuid The string UUID to test + * @return boolean + */ + public static function isValid($uuid) + { + $uuid = str_replace(array('urn:', 'uuid:', '{', '}'), '', $uuid); + + if ($uuid == self::NIL) { + return true; + } + + if (!preg_match('/' . self::VALID_PATTERN . '/D', $uuid)) { + return false; + } + + return true; + } + + /** + * Generate a version 1 UUID from a host ID, sequence number, and the current time. + * + * @param int|string $node A 48-bit number representing the hardware address + * This number may be represented as an integer or a hexadecimal string. + * @param int $clockSeq A 14-bit number used to help avoid duplicates that + * could arise when the clock is set backwards in time or if the node ID + * changes. + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if called on a 32-bit system and + * `Moontoast\Math\BigNumber` is not present + * @throws \InvalidArgumentException + * @throws \Exception if it was not possible to gather sufficient entropy + */ + public static function uuid1($node = null, $clockSeq = null) + { + return self::getFactory()->uuid1($node, $clockSeq); + } + + /** + * Generate a version 3 UUID based on the MD5 hash of a namespace identifier + * (which is a UUID) and a name (which is a string). + * + * @param string $ns The UUID namespace in which to create the named UUID + * @param string $name The name to create a UUID for + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public static function uuid3($ns, $name) + { + return self::getFactory()->uuid3($ns, $name); + } + + /** + * Generate a version 4 (random) UUID. + * + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + * @throws \InvalidArgumentException + * @throws \Exception + */ + public static function uuid4() + { + return self::getFactory()->uuid4(); + } + + /** + * Generate a version 5 UUID based on the SHA-1 hash of a namespace + * identifier (which is a UUID) and a name (which is a string). + * + * @param string $ns The UUID namespace in which to create the named UUID + * @param string $name The name to create a UUID for + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public static function uuid5($ns, $name) + { + return self::getFactory()->uuid5($ns, $name); + } +} diff --git a/vendor/ramsey/uuid/src/UuidFactory.php b/vendor/ramsey/uuid/src/UuidFactory.php new file mode 100644 index 000000000..99644d4b4 --- /dev/null +++ b/vendor/ramsey/uuid/src/UuidFactory.php @@ -0,0 +1,314 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid; + +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Generator\RandomGeneratorInterface; +use Ramsey\Uuid\Generator\TimeGeneratorInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Builder\UuidBuilderInterface; + +class UuidFactory implements UuidFactoryInterface +{ + /** + * @var CodecInterface + */ + private $codec = null; + + /** + * @var NodeProviderInterface + */ + private $nodeProvider = null; + + /** + * @var NumberConverterInterface + */ + private $numberConverter = null; + + /** + * @var RandomGeneratorInterface + */ + private $randomGenerator = null; + + /** + * @var TimeGeneratorInterface + */ + private $timeGenerator = null; + + /** + * @var UuidBuilderInterface + */ + private $uuidBuilder = null; + + /** + * Constructs a `UuidFactory` for creating `Ramsey\Uuid\UuidInterface` instances + * + * @param FeatureSet $features A set of features for use when creating UUIDs + */ + public function __construct(FeatureSet $features = null) + { + $features = $features ?: new FeatureSet(); + + $this->codec = $features->getCodec(); + $this->nodeProvider = $features->getNodeProvider(); + $this->numberConverter = $features->getNumberConverter(); + $this->randomGenerator = $features->getRandomGenerator(); + $this->timeGenerator = $features->getTimeGenerator(); + $this->uuidBuilder = $features->getBuilder(); + } + + /** + * Returns the UUID coder-decoder used by this factory + * + * @return CodecInterface + */ + public function getCodec() + { + return $this->codec; + } + + /** + * Sets the UUID coder-decoder used by this factory + * + * @param CodecInterface $codec + */ + public function setCodec(CodecInterface $codec) + { + $this->codec = $codec; + } + + /** + * Returns the system node ID provider used by this factory + * + * @return NodeProviderInterface + */ + public function getNodeProvider() + { + return $this->nodeProvider; + } + + /** + * Returns the random UUID generator used by this factory + * + * @return RandomGeneratorInterface + */ + public function getRandomGenerator() + { + return $this->randomGenerator; + } + + /** + * Returns the time-based UUID generator used by this factory + * + * @return TimeGeneratorInterface + */ + public function getTimeGenerator() + { + return $this->timeGenerator; + } + + /** + * Sets the time-based UUID generator this factory will use to generate version 1 UUIDs + * + * @param TimeGeneratorInterface $generator + */ + public function setTimeGenerator(TimeGeneratorInterface $generator) + { + $this->timeGenerator = $generator; + } + + /** + * Returns the number converter used by this factory + * + * @return NumberConverterInterface + */ + public function getNumberConverter() + { + return $this->numberConverter; + } + + /** + * Sets the random UUID generator this factory will use to generate version 4 UUIDs + * + * @param RandomGeneratorInterface $generator + */ + public function setRandomGenerator(RandomGeneratorInterface $generator) + { + $this->randomGenerator = $generator; + } + + /** + * Sets the number converter this factory will use + * + * @param NumberConverterInterface $converter + */ + public function setNumberConverter(NumberConverterInterface $converter) + { + $this->numberConverter = $converter; + } + + /** + * Returns the UUID builder this factory uses when creating `Uuid` instances + * + * @return UuidBuilderInterface $builder + */ + public function getUuidBuilder() + { + return $this->uuidBuilder; + } + + /** + * Sets the UUID builder this factory will use when creating `Uuid` instances + * + * @param UuidBuilderInterface $builder + */ + public function setUuidBuilder(UuidBuilderInterface $builder) + { + $this->uuidBuilder = $builder; + } + + /** + * @inheritdoc + */ + public function fromBytes($bytes) + { + return $this->codec->decodeBytes($bytes); + } + + /** + * @inheritdoc + */ + public function fromString($uuid) + { + $uuid = strtolower($uuid); + return $this->codec->decode($uuid); + } + + /** + * @inheritdoc + */ + public function fromInteger($integer) + { + $hex = $this->numberConverter->toHex($integer); + $hex = str_pad($hex, 32, '0', STR_PAD_LEFT); + + return $this->fromString($hex); + } + + /** + * @inheritdoc + */ + public function uuid1($node = null, $clockSeq = null) + { + $bytes = $this->timeGenerator->generate($node, $clockSeq); + $hex = bin2hex($bytes); + + return $this->uuidFromHashedName($hex, 1); + } + + /** + * @inheritdoc + */ + public function uuid3($ns, $name) + { + return $this->uuidFromNsAndName($ns, $name, 3, 'md5'); + } + + /** + * @inheritdoc + */ + public function uuid4() + { + $bytes = $this->randomGenerator->generate(16); + + // When converting the bytes to hex, it turns into a 32-character + // hexadecimal string that looks a lot like an MD5 hash, so at this + // point, we can just pass it to uuidFromHashedName. + $hex = bin2hex($bytes); + + return $this->uuidFromHashedName($hex, 4); + } + + /** + * @inheritdoc + */ + public function uuid5($ns, $name) + { + return $this->uuidFromNsAndName($ns, $name, 5, 'sha1'); + } + + /** + * Returns a `Uuid` + * + * Uses the configured builder and codec and the provided array of hexadecimal + * value UUID fields to construct a `Uuid` object. + * + * @param array $fields An array of fields from which to construct a UUID; + * see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure. + * @return UuidInterface + */ + public function uuid(array $fields) + { + return $this->uuidBuilder->build($this->codec, $fields); + } + + /** + * Returns a version 3 or 5 namespaced `Uuid` + * + * @param string|UuidInterface $ns The UUID namespace to use + * @param string $name The string to hash together with the namespace + * @param int $version The version of UUID to create (3 or 5) + * @param string $hashFunction The hash function to use when hashing together + * the namespace and name + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + protected function uuidFromNsAndName($ns, $name, $version, $hashFunction) + { + if (!($ns instanceof UuidInterface)) { + $ns = $this->codec->decode($ns); + } + + $hash = call_user_func($hashFunction, ($ns->getBytes() . $name)); + + return $this->uuidFromHashedName($hash, $version); + } + + /** + * Returns a `Uuid` created from `$hash` with the version field set to `$version` + * and the variant field set for RFC 4122 + * + * @param string $hash The hash to use when creating the UUID + * @param int $version The UUID version to set for this hash (1, 3, 4, or 5) + * @return UuidInterface + */ + protected function uuidFromHashedName($hash, $version) + { + $timeHi = BinaryUtils::applyVersion(substr($hash, 12, 4), $version); + $clockSeqHi = BinaryUtils::applyVariant(hexdec(substr($hash, 16, 2))); + + $fields = array( + 'time_low' => substr($hash, 0, 8), + 'time_mid' => substr($hash, 8, 4), + 'time_hi_and_version' => str_pad(dechex($timeHi), 4, '0', STR_PAD_LEFT), + 'clock_seq_hi_and_reserved' => str_pad(dechex($clockSeqHi), 2, '0', STR_PAD_LEFT), + 'clock_seq_low' => substr($hash, 18, 2), + 'node' => substr($hash, 20, 12), + ); + + return $this->uuid($fields); + } +} diff --git a/vendor/ramsey/uuid/src/UuidFactoryInterface.php b/vendor/ramsey/uuid/src/UuidFactoryInterface.php new file mode 100644 index 000000000..a228f5bc7 --- /dev/null +++ b/vendor/ramsey/uuid/src/UuidFactoryInterface.php @@ -0,0 +1,103 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid; + +/** + * UuidFactoryInterface defines common functionality all `UuidFactory` instances + * must implement + */ +interface UuidFactoryInterface +{ + /** + * Generate a version 1 UUID from a host ID, sequence number, and the current time. + * + * @param int|string|null $node A 48-bit number representing the hardware address + * This number may be represented as an integer or a hexadecimal string. + * @param int|null $clockSeq A 14-bit number used to help avoid duplicates that + * could arise when the clock is set backwards in time or if the node ID + * changes. + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if called on a 32-bit system and + * `Moontoast\Math\BigNumber` is not present + * @throws \InvalidArgumentException + * @throws \Exception if it was not possible to gather sufficient entropy + */ + public function uuid1($node = null, $clockSeq = null); + + /** + * Generate a version 3 UUID based on the MD5 hash of a namespace identifier + * (which is a UUID) and a name (which is a string). + * + * @param string $ns The UUID namespace in which to create the named UUID + * @param string $name The name to create a UUID for + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function uuid3($ns, $name); + + /** + * Generate a version 4 (random) UUID. + * + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + * @throws \InvalidArgumentException + * @throws \Exception + */ + public function uuid4(); + + /** + * Generate a version 5 UUID based on the SHA-1 hash of a namespace + * identifier (which is a UUID) and a name (which is a string). + * + * @param string $ns The UUID namespace in which to create the named UUID + * @param string $name The name to create a UUID for + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function uuid5($ns, $name); + + /** + * Creates a UUID from a byte string. + * + * @param string $bytes A 16-byte string representation of a UUID + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + * @throws \InvalidArgumentException if string has not 16 characters + */ + public function fromBytes($bytes); + + /** + * Creates a UUID from the string standard representation + * + * @param string $uuid A string representation of a UUID + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function fromString($uuid); + + /** + * Creates a `Uuid` from an integer representation + * + * The integer representation may be a real integer, a string integer, or + * an integer representation supported by a configured number converter. + * + * @param mixed $integer The integer to use when creating a `Uuid` from an + * integer; may be of any type understood by the configured number converter + * @return UuidInterface + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException + */ + public function fromInteger($integer); +} diff --git a/vendor/ramsey/uuid/src/UuidInterface.php b/vendor/ramsey/uuid/src/UuidInterface.php new file mode 100644 index 000000000..ea3a46fb2 --- /dev/null +++ b/vendor/ramsey/uuid/src/UuidInterface.php @@ -0,0 +1,270 @@ +<?php +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + * @link https://benramsey.com/projects/ramsey-uuid/ Documentation + * @link https://packagist.org/packages/ramsey/uuid Packagist + * @link https://github.com/ramsey/uuid GitHub + */ + +namespace Ramsey\Uuid; + +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Exception\UnsupportedOperationException; + +/** + * UuidInterface defines common functionality for all universally unique + * identifiers (UUIDs) + */ +interface UuidInterface extends \JsonSerializable, \Serializable +{ + /** + * Compares this UUID to the specified UUID. + * + * The first of two UUIDs is greater than the second if the most + * significant field in which the UUIDs differ is greater for the first + * UUID. + * + * * Q. What's the value of being able to sort UUIDs? + * * A. Use them as keys in a B-Tree or similar mapping. + * + * @param UuidInterface $other UUID to which this UUID is compared + * @return int -1, 0 or 1 as this UUID is less than, equal to, or greater than `$uuid` + */ + public function compareTo(UuidInterface $other); + + /** + * Compares this object to the specified object. + * + * The result is true if and only if the argument is not null, is a UUID + * object, has the same variant, and contains the same value, bit for bit, + * as this UUID. + * + * @param object $other + * @return bool True if `$other` is equal to this UUID + */ + public function equals($other); + + /** + * Returns the UUID as a 16-byte string (containing the six integer fields + * in big-endian byte order). + * + * @return string + */ + public function getBytes(); + + /** + * Returns the number converter to use for converting hex values to/from integers. + * + * @return NumberConverterInterface + */ + public function getNumberConverter(); + + /** + * Returns the hexadecimal value of the UUID. + * + * @return string + */ + public function getHex(); + + /** + * Returns an array of the fields of this UUID, with keys named according + * to the RFC 4122 names for the fields. + * + * * **time_low**: The low field of the timestamp, an unsigned 32-bit integer + * * **time_mid**: The middle field of the timestamp, an unsigned 16-bit integer + * * **time_hi_and_version**: The high field of the timestamp multiplexed with + * the version number, an unsigned 16-bit integer + * * **clock_seq_hi_and_reserved**: The high field of the clock sequence + * multiplexed with the variant, an unsigned 8-bit integer + * * **clock_seq_low**: The low field of the clock sequence, an unsigned + * 8-bit integer + * * **node**: The spatially unique node identifier, an unsigned 48-bit + * integer + * + * @return array The UUID fields represented as hexadecimal values + */ + public function getFieldsHex(); + + /** + * Returns the high field of the clock sequence multiplexed with the variant + * (bits 65-72 of the UUID). + * + * @return string Hexadecimal value of clock_seq_hi_and_reserved + */ + public function getClockSeqHiAndReservedHex(); + + /** + * Returns the low field of the clock sequence (bits 73-80 of the UUID). + * + * @return string Hexadecimal value of clock_seq_low + */ + public function getClockSeqLowHex(); + + /** + * Returns the clock sequence value associated with this UUID. + * + * @return string Hexadecimal value of clock sequence + */ + public function getClockSequenceHex(); + + /** + * Returns a PHP `DateTime` object representing the timestamp associated + * with this UUID. + * + * The timestamp value is only meaningful in a time-based UUID, which + * has version type 1. If this UUID is not a time-based UUID then + * this method throws `UnsupportedOperationException`. + * + * @return \DateTime A PHP DateTime representation of the date + * @throws UnsupportedOperationException If this UUID is not a version 1 UUID + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if called in a 32-bit system and + * `Moontoast\Math\BigNumber` is not present + */ + public function getDateTime(); + + /** + * Returns the integer value of the UUID, converted to an appropriate number + * representation. + * + * @return mixed Converted representation of the unsigned 128-bit integer value + * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present + */ + public function getInteger(); + + /** + * Returns the least significant 64 bits of this UUID's 128 bit value. + * + * @return string Hexadecimal value of least significant bits + */ + public function getLeastSignificantBitsHex(); + + /** + * Returns the most significant 64 bits of this UUID's 128 bit value. + * + * @return string Hexadecimal value of most significant bits + */ + public function getMostSignificantBitsHex(); + + /** + * Returns the node value associated with this UUID + * + * For UUID version 1, the node field consists of an IEEE 802 MAC + * address, usually the host address. For systems with multiple IEEE + * 802 addresses, any available one can be used. The lowest addressed + * octet (octet number 10) contains the global/local bit and the + * unicast/multicast bit, and is the first octet of the address + * transmitted on an 802.3 LAN. + * + * For systems with no IEEE address, a randomly or pseudo-randomly + * generated value may be used; see RFC 4122, Section 4.5. The + * multicast bit must be set in such addresses, in order that they + * will never conflict with addresses obtained from network cards. + * + * For UUID version 3 or 5, the node field is a 48-bit value constructed + * from a name as described in RFC 4122, Section 4.3. + * + * For UUID version 4, the node field is a randomly or pseudo-randomly + * generated 48-bit value as described in RFC 4122, Section 4.4. + * + * @return string Hexadecimal value of node + * @link http://tools.ietf.org/html/rfc4122#section-4.1.6 + */ + public function getNodeHex(); + + /** + * Returns the high field of the timestamp multiplexed with the version + * number (bits 49-64 of the UUID). + * + * @return string Hexadecimal value of time_hi_and_version + */ + public function getTimeHiAndVersionHex(); + + /** + * Returns the low field of the timestamp (the first 32 bits of the UUID). + * + * @return string Hexadecimal value of time_low + */ + public function getTimeLowHex(); + + /** + * Returns the middle field of the timestamp (bits 33-48 of the UUID). + * + * @return string Hexadecimal value of time_mid + */ + public function getTimeMidHex(); + + /** + * Returns the timestamp value associated with this UUID. + * + * The 60 bit timestamp value is constructed from the time_low, + * time_mid, and time_hi fields of this UUID. The resulting + * timestamp is measured in 100-nanosecond units since midnight, + * October 15, 1582 UTC. + * + * The timestamp value is only meaningful in a time-based UUID, which + * has version type 1. If this UUID is not a time-based UUID then + * this method throws UnsupportedOperationException. + * + * @return string Hexadecimal value of the timestamp + * @throws UnsupportedOperationException If this UUID is not a version 1 UUID + * @link http://tools.ietf.org/html/rfc4122#section-4.1.4 + */ + public function getTimestampHex(); + + /** + * Returns the string representation of the UUID as a URN. + * + * @return string + * @link http://en.wikipedia.org/wiki/Uniform_Resource_Name + */ + public function getUrn(); + + /** + * Returns the variant number associated with this UUID. + * + * The variant number describes the layout of the UUID. The variant + * number has the following meaning: + * + * * 0 - Reserved for NCS backward compatibility + * * 2 - The RFC 4122 variant (used by this class) + * * 6 - Reserved, Microsoft Corporation backward compatibility + * * 7 - Reserved for future definition + * + * @return int + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + public function getVariant(); + + /** + * Returns the version number associated with this UUID. + * + * The version number describes how this UUID was generated and has the + * following meaning: + * + * * 1 - Time-based UUID + * * 2 - DCE security UUID + * * 3 - Name-based UUID hashed with MD5 + * * 4 - Randomly generated UUID + * * 5 - Name-based UUID hashed with SHA-1 + * + * Returns null if this UUID is not an RFC 4122 variant, since version + * is only meaningful for this variant. + * + * @return int|null + * @link http://tools.ietf.org/html/rfc4122#section-4.1.3 + */ + public function getVersion(); + + /** + * Converts this UUID into a string representation. + * + * @return string + */ + public function toString(); +} |