From c7fafb77b10982402d31ae793122d73c3530cccc Mon Sep 17 00:00:00 2001 From: Fatih Toprak Date: Tue, 15 Feb 2022 16:00:51 +0300 Subject: [PATCH] Version 2.9.2 released --- composer.json | 3 +- core/library/Moka_Init.php | 2 +- core/library/Optimisthub_Ajax.php | 8 +- index.php | 2 +- readme.md | 4 + vendor/brick/math/CHANGELOG.md | 415 ++++++ vendor/brick/math/LICENSE | 20 + vendor/brick/math/SECURITY.md | 17 + vendor/brick/math/composer.json | 35 + vendor/brick/math/src/BigDecimal.php | 895 +++++++++++++ vendor/brick/math/src/BigInteger.php | 1184 +++++++++++++++++ vendor/brick/math/src/BigNumber.php | 572 ++++++++ vendor/brick/math/src/BigRational.php | 523 ++++++++ .../src/Exception/DivisionByZeroException.php | 41 + .../Exception/IntegerOverflowException.php | 27 + .../math/src/Exception/MathException.php | 14 + .../src/Exception/NegativeNumberException.php | 12 + .../src/Exception/NumberFormatException.php | 35 + .../Exception/RoundingNecessaryException.php | 21 + vendor/brick/math/src/Internal/Calculator.php | 756 +++++++++++ .../Internal/Calculator/BcMathCalculator.php | 116 ++ .../src/Internal/Calculator/GmpCalculator.php | 156 +++ .../Internal/Calculator/NativeCalculator.php | 634 +++++++++ vendor/brick/math/src/RoundingMode.php | 107 ++ vendor/composer/InstalledVersions.php | 143 +- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_files.php | 7 +- vendor/composer/autoload_psr4.php | 11 + vendor/composer/autoload_static.php | 72 +- vendor/composer/installed.json | 996 +++++++++++++- vendor/composer/installed.php | 143 +- vendor/composer/platform_check.php | 4 +- vendor/psr/container/.gitignore | 3 + vendor/psr/container/LICENSE | 21 + vendor/psr/container/README.md | 13 + vendor/psr/container/composer.json | 22 + .../src/ContainerExceptionInterface.php | 12 + .../psr/container/src/ContainerInterface.php | 36 + .../src/NotFoundExceptionInterface.php | 10 + vendor/ramsey/collection/LICENSE | 19 + vendor/ramsey/collection/README.md | 82 ++ vendor/ramsey/collection/SECURITY.md | 113 ++ vendor/ramsey/collection/composer.json | 102 ++ .../ramsey/collection/src/AbstractArray.php | 209 +++ .../collection/src/AbstractCollection.php | 318 +++++ vendor/ramsey/collection/src/AbstractSet.php | 50 + .../ramsey/collection/src/ArrayInterface.php | 51 + vendor/ramsey/collection/src/Collection.php | 106 ++ .../collection/src/CollectionInterface.php | 205 +++ .../collection/src/DoubleEndedQueue.php | 187 +++ .../src/DoubleEndedQueueInterface.php | 316 +++++ .../Exception/CollectionMismatchException.php | 22 + .../Exception/InvalidArgumentException.php | 22 + .../Exception/InvalidSortOrderException.php | 22 + .../src/Exception/NoSuchElementException.php | 22 + .../src/Exception/OutOfBoundsException.php | 22 + .../UnsupportedOperationException.php | 22 + .../Exception/ValueExtractionException.php | 22 + vendor/ramsey/collection/src/GenericArray.php | 24 + .../ramsey/collection/src/Map/AbstractMap.php | 162 +++ .../collection/src/Map/AbstractTypedMap.php | 69 + .../src/Map/AssociativeArrayMap.php | 25 + .../collection/src/Map/MapInterface.php | 149 +++ .../collection/src/Map/NamedParameterMap.php | 120 ++ vendor/ramsey/collection/src/Map/TypedMap.php | 137 ++ .../collection/src/Map/TypedMapInterface.php | 35 + vendor/ramsey/collection/src/Queue.php | 169 +++ .../ramsey/collection/src/QueueInterface.php | 203 +++ vendor/ramsey/collection/src/Set.php | 69 + .../ramsey/collection/src/Tool/TypeTrait.php | 73 + .../src/Tool/ValueExtractorTrait.php | 58 + .../src/Tool/ValueToStringTrait.php | 94 ++ vendor/ramsey/uuid/LICENSE | 19 + vendor/ramsey/uuid/README.md | 83 ++ vendor/ramsey/uuid/composer.json | 107 ++ vendor/ramsey/uuid/src/BinaryUtils.php | 63 + .../uuid/src/Builder/BuilderCollection.php | 80 ++ .../uuid/src/Builder/DefaultUuidBuilder.php | 26 + .../uuid/src/Builder/DegradedUuidBuilder.php | 76 ++ .../uuid/src/Builder/FallbackBuilder.php | 74 ++ .../uuid/src/Builder/UuidBuilderInterface.php | 39 + .../ramsey/uuid/src/Codec/CodecInterface.php | 71 + .../ramsey/uuid/src/Codec/GuidStringCodec.php | 55 + .../uuid/src/Codec/OrderedTimeCodec.php | 113 ++ vendor/ramsey/uuid/src/Codec/StringCodec.php | 138 ++ .../src/Codec/TimestampFirstCombCodec.php | 113 ++ .../uuid/src/Codec/TimestampLastCombCodec.php | 51 + .../Converter/Number/BigNumberConverter.php | 57 + .../Number/DegradedNumberConverter.php | 25 + .../Number/GenericNumberConverter.php | 63 + .../Converter/NumberConverterInterface.php | 57 + .../Converter/Time/BigNumberTimeConverter.php | 51 + .../Converter/Time/DegradedTimeConverter.php | 25 + .../Converter/Time/GenericTimeConverter.php | 124 ++ .../src/Converter/Time/PhpTimeConverter.php | 183 +++ .../src/Converter/TimeConverterInterface.php | 58 + vendor/ramsey/uuid/src/DegradedUuid.php | 25 + .../uuid/src/DeprecatedUuidInterface.php | 147 ++ .../uuid/src/DeprecatedUuidMethodsTrait.php | 370 ++++++ .../Exception/BuilderNotFoundException.php | 24 + .../uuid/src/Exception/DateTimeException.php | 24 + .../src/Exception/DceSecurityException.php | 25 + .../Exception/InvalidArgumentException.php | 24 + .../src/Exception/InvalidBytesException.php | 24 + .../Exception/InvalidUuidStringException.php | 25 + .../uuid/src/Exception/NameException.php | 25 + .../uuid/src/Exception/NodeException.php | 24 + .../src/Exception/RandomSourceException.php | 27 + .../src/Exception/TimeSourceException.php | 24 + .../Exception/UnableToBuildUuidException.php | 24 + .../UnsupportedOperationException.php | 24 + .../src/Exception/UuidExceptionInterface.php | 21 + vendor/ramsey/uuid/src/FeatureSet.php | 449 +++++++ .../uuid/src/Fields/FieldsInterface.php | 32 + .../src/Fields/SerializableFieldsTrait.php | 86 ++ .../uuid/src/Generator/CombGenerator.php | 127 ++ .../src/Generator/DceSecurityGenerator.php | 160 +++ .../DceSecurityGeneratorInterface.php | 53 + .../src/Generator/DefaultNameGenerator.php | 48 + .../src/Generator/DefaultTimeGenerator.php | 147 ++ .../src/Generator/NameGeneratorFactory.php | 30 + .../src/Generator/NameGeneratorInterface.php | 38 + .../src/Generator/PeclUuidNameGenerator.php | 54 + .../src/Generator/PeclUuidRandomGenerator.php | 35 + .../src/Generator/PeclUuidTimeGenerator.php | 39 + .../src/Generator/RandomBytesGenerator.php | 45 + .../src/Generator/RandomGeneratorFactory.php | 30 + .../Generator/RandomGeneratorInterface.php | 30 + .../uuid/src/Generator/RandomLibAdapter.php | 55 + .../src/Generator/TimeGeneratorFactory.php | 63 + .../src/Generator/TimeGeneratorInterface.php | 38 + vendor/ramsey/uuid/src/Guid/Fields.php | 194 +++ vendor/ramsey/uuid/src/Guid/Guid.php | 61 + vendor/ramsey/uuid/src/Guid/GuidBuilder.php | 89 ++ .../uuid/src/Lazy/LazyUuidFromString.php | 575 ++++++++ .../uuid/src/Math/BrickMathCalculator.php | 144 ++ .../uuid/src/Math/CalculatorInterface.php | 106 ++ vendor/ramsey/uuid/src/Math/RoundingMode.php | 146 ++ vendor/ramsey/uuid/src/Nonstandard/Fields.php | 133 ++ vendor/ramsey/uuid/src/Nonstandard/Uuid.php | 37 + .../uuid/src/Nonstandard/UuidBuilder.php | 88 ++ vendor/ramsey/uuid/src/Nonstandard/UuidV6.php | 133 ++ .../Dce/SystemDceSecurityProvider.php | 234 ++++ .../Provider/DceSecurityProviderInterface.php | 41 + .../Provider/Node/FallbackNodeProvider.php | 60 + .../Provider/Node/NodeProviderCollection.php | 61 + .../src/Provider/Node/RandomNodeProvider.php | 69 + .../src/Provider/Node/StaticNodeProvider.php | 76 ++ .../src/Provider/Node/SystemNodeProvider.php | 173 +++ .../src/Provider/NodeProviderInterface.php | 30 + .../src/Provider/Time/FixedTimeProvider.php | 63 + .../src/Provider/Time/SystemTimeProvider.php | 33 + .../src/Provider/TimeProviderInterface.php | 28 + vendor/ramsey/uuid/src/Rfc4122/Fields.php | 194 +++ .../uuid/src/Rfc4122/FieldsInterface.php | 126 ++ vendor/ramsey/uuid/src/Rfc4122/NilTrait.php | 41 + vendor/ramsey/uuid/src/Rfc4122/NilUuid.php | 27 + .../ramsey/uuid/src/Rfc4122/UuidBuilder.php | 111 ++ .../ramsey/uuid/src/Rfc4122/UuidInterface.php | 36 + vendor/ramsey/uuid/src/Rfc4122/UuidV1.php | 92 ++ vendor/ramsey/uuid/src/Rfc4122/UuidV2.php | 143 ++ vendor/ramsey/uuid/src/Rfc4122/UuidV3.php | 58 + vendor/ramsey/uuid/src/Rfc4122/UuidV4.php | 58 + vendor/ramsey/uuid/src/Rfc4122/UuidV5.php | 58 + vendor/ramsey/uuid/src/Rfc4122/Validator.php | 49 + .../ramsey/uuid/src/Rfc4122/VariantTrait.php | 90 ++ .../ramsey/uuid/src/Rfc4122/VersionTrait.php | 57 + vendor/ramsey/uuid/src/Type/Decimal.php | 137 ++ vendor/ramsey/uuid/src/Type/Hexadecimal.php | 116 ++ vendor/ramsey/uuid/src/Type/Integer.php | 153 +++ .../ramsey/uuid/src/Type/NumberInterface.php | 28 + vendor/ramsey/uuid/src/Type/Time.php | 139 ++ vendor/ramsey/uuid/src/Type/TypeInterface.php | 30 + vendor/ramsey/uuid/src/Uuid.php | 664 +++++++++ vendor/ramsey/uuid/src/UuidFactory.php | 493 +++++++ .../ramsey/uuid/src/UuidFactoryInterface.php | 182 +++ vendor/ramsey/uuid/src/UuidInterface.php | 99 ++ .../uuid/src/Validator/GenericValidator.php | 50 + .../uuid/src/Validator/ValidatorInterface.php | 41 + vendor/ramsey/uuid/src/functions.php | 123 ++ .../spatie/backtrace/.php-cs-fixer.dist.php | 40 + vendor/spatie/backtrace/CHANGELOG.md | 23 + vendor/spatie/backtrace/LICENSE.md | 21 + vendor/spatie/backtrace/README.md | 157 +++ vendor/spatie/backtrace/composer.json | 57 + vendor/spatie/backtrace/src/Backtrace.php | 219 +++ vendor/spatie/backtrace/src/CodeSnippet.php | 72 + vendor/spatie/backtrace/src/File.php | 41 + vendor/spatie/backtrace/src/Frame.php | 65 + vendor/spatie/macroable/CHANGELOG.md | 12 + vendor/spatie/macroable/CONTRIBUTING.md | 55 + vendor/spatie/macroable/LICENSE.md | 21 + vendor/spatie/macroable/README.md | 135 ++ vendor/spatie/macroable/composer.json | 40 + vendor/spatie/macroable/config/.gitkeep | 0 vendor/spatie/macroable/src/Macroable.php | 77 ++ vendor/spatie/ray/.php_cs.dist.php | 40 + vendor/spatie/ray/CHANGELOG.md | 396 ++++++ vendor/spatie/ray/LICENSE.md | 21 + vendor/spatie/ray/README.md | 48 + vendor/spatie/ray/composer.json | 70 + vendor/spatie/ray/phpstan-baseline.neon | 42 + vendor/spatie/ray/phpstan.neon.dist | 11 + vendor/spatie/ray/src/ArgumentConverter.php | 36 + vendor/spatie/ray/src/Client.php | 168 +++ vendor/spatie/ray/src/Concerns/RayColors.php | 37 + .../ray/src/Concerns/RayScreenColors.php | 37 + vendor/spatie/ray/src/Concerns/RaySizes.php | 17 + .../ray/src/Concerns/RemovesRayFrames.php | 37 + .../src/Exceptions/CouldNotConnectToRay.php | 13 + .../src/Exceptions/StopExecutionRequested.php | 13 + .../ray/src/Origin/DefaultOriginFactory.php | 84 ++ vendor/spatie/ray/src/Origin/Hostname.php | 18 + vendor/spatie/ray/src/Origin/Origin.php | 43 + .../spatie/ray/src/Origin/OriginFactory.php | 8 + vendor/spatie/ray/src/PayloadFactory.php | 66 + .../src/Payloads/ApplicationLogPayload.php | 31 + .../spatie/ray/src/Payloads/BoolPayload.php | 27 + .../spatie/ray/src/Payloads/CallerPayload.php | 42 + .../spatie/ray/src/Payloads/CarbonPayload.php | 35 + .../ray/src/Payloads/ClearAllPayload.php | 11 + .../spatie/ray/src/Payloads/ColorPayload.php | 26 + .../ray/src/Payloads/CreateLockPayload.php | 26 + .../spatie/ray/src/Payloads/CustomPayload.php | 32 + .../ray/src/Payloads/DecodedJsonPayload.php | 31 + .../ray/src/Payloads/ExceptionPayload.php | 56 + .../ray/src/Payloads/FileContentsPayload.php | 44 + .../ray/src/Payloads/HideAppPayload.php | 11 + .../spatie/ray/src/Payloads/HidePayload.php | 11 + .../spatie/ray/src/Payloads/HtmlPayload.php | 27 + .../spatie/ray/src/Payloads/ImagePayload.php | 54 + .../ray/src/Payloads/JsonStringPayload.php | 26 + .../spatie/ray/src/Payloads/LabelPayload.php | 26 + vendor/spatie/ray/src/Payloads/LogPayload.php | 41 + .../ray/src/Payloads/MeasurePayload.php | 71 + .../ray/src/Payloads/NewScreenPayload.php | 26 + .../spatie/ray/src/Payloads/NotifyPayload.php | 26 + .../spatie/ray/src/Payloads/NullPayload.php | 22 + vendor/spatie/ray/src/Payloads/Payload.php | 62 + .../ray/src/Payloads/PhpInfoPayload.php | 45 + .../spatie/ray/src/Payloads/RemovePayload.php | 11 + .../ray/src/Payloads/ScreenColorPayload.php | 26 + .../ray/src/Payloads/SeparatorPayload.php | 11 + .../ray/src/Payloads/ShowAppPayload.php | 11 + .../spatie/ray/src/Payloads/SizePayload.php | 26 + .../spatie/ray/src/Payloads/TablePayload.php | 38 + .../spatie/ray/src/Payloads/TextPayload.php | 34 + .../spatie/ray/src/Payloads/TracePayload.php | 63 + vendor/spatie/ray/src/Payloads/XmlPayload.php | 62 + vendor/spatie/ray/src/Ray.php | 791 +++++++++++ vendor/spatie/ray/src/Request.php | 44 + vendor/spatie/ray/src/Settings/Settings.php | 68 + .../ray/src/Settings/SettingsFactory.php | 74 ++ vendor/spatie/ray/src/Support/CacheStore.php | 61 + vendor/spatie/ray/src/Support/Clock.php | 10 + vendor/spatie/ray/src/Support/Counters.php | 45 + .../ray/src/Support/ExceptionHandler.php | 148 +++ .../spatie/ray/src/Support/IgnoredValue.php | 11 + vendor/spatie/ray/src/Support/Limiters.php | 50 + vendor/spatie/ray/src/Support/RateLimiter.php | 106 ++ vendor/spatie/ray/src/Support/SystemClock.php | 13 + vendor/spatie/ray/src/helpers.php | 64 + .../symfony/deprecation-contracts/.gitignore | 3 + .../deprecation-contracts/CHANGELOG.md | 5 + vendor/symfony/deprecation-contracts/LICENSE | 19 + .../symfony/deprecation-contracts/README.md | 26 + .../deprecation-contracts/composer.json | 35 + .../deprecation-contracts/function.php | 27 + vendor/symfony/polyfill-ctype/Ctype.php | 232 ++++ vendor/symfony/polyfill-ctype/LICENSE | 19 + vendor/symfony/polyfill-ctype/README.md | 12 + vendor/symfony/polyfill-ctype/bootstrap.php | 50 + vendor/symfony/polyfill-ctype/bootstrap80.php | 46 + vendor/symfony/polyfill-ctype/composer.json | 41 + vendor/symfony/polyfill-mbstring/Mbstring.php | 5 +- .../symfony/polyfill-mbstring/composer.json | 3 + .../Resources/stubs/UnhandledMatchError.php | 6 +- .../Resources/stubs/ValueError.php | 6 +- vendor/symfony/polyfill-php81/LICENSE | 19 + vendor/symfony/polyfill-php81/Php81.php | 37 + vendor/symfony/polyfill-php81/README.md | 16 + .../Resources/stubs/ReturnTypeWillChange.php | 11 + vendor/symfony/polyfill-php81/bootstrap.php | 28 + vendor/symfony/polyfill-php81/composer.json | 36 + vendor/symfony/service-contracts/.gitignore | 3 + .../service-contracts/Attribute/Required.php | 25 + .../Attribute/SubscribedService.php | 33 + vendor/symfony/service-contracts/CHANGELOG.md | 5 + vendor/symfony/service-contracts/LICENSE | 19 + vendor/symfony/service-contracts/README.md | 9 + .../service-contracts/ResetInterface.php | 30 + .../service-contracts/ServiceLocatorTrait.php | 128 ++ .../ServiceProviderInterface.php | 36 + .../ServiceSubscriberInterface.php | 53 + .../ServiceSubscriberTrait.php | 115 ++ .../Test/ServiceLocatorTest.php | 95 ++ .../symfony/service-contracts/composer.json | 42 + vendor/symfony/stopwatch/CHANGELOG.md | 24 + vendor/symfony/stopwatch/LICENSE | 19 + vendor/symfony/stopwatch/README.md | 42 + vendor/symfony/stopwatch/Section.php | 185 +++ vendor/symfony/stopwatch/Stopwatch.php | 166 +++ vendor/symfony/stopwatch/StopwatchEvent.php | 258 ++++ vendor/symfony/stopwatch/StopwatchPeriod.php | 81 ++ vendor/symfony/stopwatch/composer.json | 29 + .../ContextProviderInterface.php | 3 - vendor/symfony/var-dumper/LICENSE | 2 +- .../collect/.github/workflows/run-tests.yml | 7 +- vendor/tightenco/collect/composer.json | 2 +- .../src/Collect/Support/Collection.php | 54 +- .../src/Collect/Support/LazyCollection.php | 24 + .../Support/Traits/EnumeratesValues.php | 16 + .../collect/src/Collect/Support/helpers.php | 66 +- 313 files changed, 27439 insertions(+), 158 deletions(-) create mode 100644 vendor/brick/math/CHANGELOG.md create mode 100644 vendor/brick/math/LICENSE create mode 100644 vendor/brick/math/SECURITY.md create mode 100644 vendor/brick/math/composer.json create mode 100644 vendor/brick/math/src/BigDecimal.php create mode 100644 vendor/brick/math/src/BigInteger.php create mode 100644 vendor/brick/math/src/BigNumber.php create mode 100644 vendor/brick/math/src/BigRational.php create mode 100644 vendor/brick/math/src/Exception/DivisionByZeroException.php create mode 100644 vendor/brick/math/src/Exception/IntegerOverflowException.php create mode 100644 vendor/brick/math/src/Exception/MathException.php create mode 100644 vendor/brick/math/src/Exception/NegativeNumberException.php create mode 100644 vendor/brick/math/src/Exception/NumberFormatException.php create mode 100644 vendor/brick/math/src/Exception/RoundingNecessaryException.php create mode 100644 vendor/brick/math/src/Internal/Calculator.php create mode 100644 vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php create mode 100644 vendor/brick/math/src/Internal/Calculator/GmpCalculator.php create mode 100644 vendor/brick/math/src/Internal/Calculator/NativeCalculator.php create mode 100644 vendor/brick/math/src/RoundingMode.php create mode 100644 vendor/psr/container/.gitignore create mode 100644 vendor/psr/container/LICENSE create mode 100644 vendor/psr/container/README.md create mode 100644 vendor/psr/container/composer.json create mode 100644 vendor/psr/container/src/ContainerExceptionInterface.php create mode 100644 vendor/psr/container/src/ContainerInterface.php create mode 100644 vendor/psr/container/src/NotFoundExceptionInterface.php create mode 100644 vendor/ramsey/collection/LICENSE create mode 100644 vendor/ramsey/collection/README.md create mode 100644 vendor/ramsey/collection/SECURITY.md create mode 100644 vendor/ramsey/collection/composer.json create mode 100644 vendor/ramsey/collection/src/AbstractArray.php create mode 100644 vendor/ramsey/collection/src/AbstractCollection.php create mode 100644 vendor/ramsey/collection/src/AbstractSet.php create mode 100644 vendor/ramsey/collection/src/ArrayInterface.php create mode 100644 vendor/ramsey/collection/src/Collection.php create mode 100644 vendor/ramsey/collection/src/CollectionInterface.php create mode 100644 vendor/ramsey/collection/src/DoubleEndedQueue.php create mode 100644 vendor/ramsey/collection/src/DoubleEndedQueueInterface.php create mode 100644 vendor/ramsey/collection/src/Exception/CollectionMismatchException.php create mode 100644 vendor/ramsey/collection/src/Exception/InvalidArgumentException.php create mode 100644 vendor/ramsey/collection/src/Exception/InvalidSortOrderException.php create mode 100644 vendor/ramsey/collection/src/Exception/NoSuchElementException.php create mode 100644 vendor/ramsey/collection/src/Exception/OutOfBoundsException.php create mode 100644 vendor/ramsey/collection/src/Exception/UnsupportedOperationException.php create mode 100644 vendor/ramsey/collection/src/Exception/ValueExtractionException.php create mode 100644 vendor/ramsey/collection/src/GenericArray.php create mode 100644 vendor/ramsey/collection/src/Map/AbstractMap.php create mode 100644 vendor/ramsey/collection/src/Map/AbstractTypedMap.php create mode 100644 vendor/ramsey/collection/src/Map/AssociativeArrayMap.php create mode 100644 vendor/ramsey/collection/src/Map/MapInterface.php create mode 100644 vendor/ramsey/collection/src/Map/NamedParameterMap.php create mode 100644 vendor/ramsey/collection/src/Map/TypedMap.php create mode 100644 vendor/ramsey/collection/src/Map/TypedMapInterface.php create mode 100644 vendor/ramsey/collection/src/Queue.php create mode 100644 vendor/ramsey/collection/src/QueueInterface.php create mode 100644 vendor/ramsey/collection/src/Set.php create mode 100644 vendor/ramsey/collection/src/Tool/TypeTrait.php create mode 100644 vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php create mode 100644 vendor/ramsey/collection/src/Tool/ValueToStringTrait.php create mode 100644 vendor/ramsey/uuid/LICENSE create mode 100644 vendor/ramsey/uuid/README.md create mode 100644 vendor/ramsey/uuid/composer.json create mode 100644 vendor/ramsey/uuid/src/BinaryUtils.php create mode 100644 vendor/ramsey/uuid/src/Builder/BuilderCollection.php create mode 100644 vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php create mode 100644 vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php create mode 100644 vendor/ramsey/uuid/src/Builder/FallbackBuilder.php create mode 100644 vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php create mode 100644 vendor/ramsey/uuid/src/Codec/CodecInterface.php create mode 100644 vendor/ramsey/uuid/src/Codec/GuidStringCodec.php create mode 100644 vendor/ramsey/uuid/src/Codec/OrderedTimeCodec.php create mode 100644 vendor/ramsey/uuid/src/Codec/StringCodec.php create mode 100644 vendor/ramsey/uuid/src/Codec/TimestampFirstCombCodec.php create mode 100644 vendor/ramsey/uuid/src/Codec/TimestampLastCombCodec.php create mode 100644 vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php create mode 100644 vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php create mode 100644 vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php create mode 100644 vendor/ramsey/uuid/src/Converter/NumberConverterInterface.php create mode 100644 vendor/ramsey/uuid/src/Converter/Time/BigNumberTimeConverter.php create mode 100644 vendor/ramsey/uuid/src/Converter/Time/DegradedTimeConverter.php create mode 100644 vendor/ramsey/uuid/src/Converter/Time/GenericTimeConverter.php create mode 100644 vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php create mode 100644 vendor/ramsey/uuid/src/Converter/TimeConverterInterface.php create mode 100644 vendor/ramsey/uuid/src/DegradedUuid.php create mode 100644 vendor/ramsey/uuid/src/DeprecatedUuidInterface.php create mode 100644 vendor/ramsey/uuid/src/DeprecatedUuidMethodsTrait.php create mode 100644 vendor/ramsey/uuid/src/Exception/BuilderNotFoundException.php create mode 100644 vendor/ramsey/uuid/src/Exception/DateTimeException.php create mode 100644 vendor/ramsey/uuid/src/Exception/DceSecurityException.php create mode 100644 vendor/ramsey/uuid/src/Exception/InvalidArgumentException.php create mode 100644 vendor/ramsey/uuid/src/Exception/InvalidBytesException.php create mode 100644 vendor/ramsey/uuid/src/Exception/InvalidUuidStringException.php create mode 100644 vendor/ramsey/uuid/src/Exception/NameException.php create mode 100644 vendor/ramsey/uuid/src/Exception/NodeException.php create mode 100644 vendor/ramsey/uuid/src/Exception/RandomSourceException.php create mode 100644 vendor/ramsey/uuid/src/Exception/TimeSourceException.php create mode 100644 vendor/ramsey/uuid/src/Exception/UnableToBuildUuidException.php create mode 100644 vendor/ramsey/uuid/src/Exception/UnsupportedOperationException.php create mode 100644 vendor/ramsey/uuid/src/Exception/UuidExceptionInterface.php create mode 100644 vendor/ramsey/uuid/src/FeatureSet.php create mode 100644 vendor/ramsey/uuid/src/Fields/FieldsInterface.php create mode 100644 vendor/ramsey/uuid/src/Fields/SerializableFieldsTrait.php create mode 100644 vendor/ramsey/uuid/src/Generator/CombGenerator.php create mode 100644 vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php create mode 100644 vendor/ramsey/uuid/src/Generator/DceSecurityGeneratorInterface.php create mode 100644 vendor/ramsey/uuid/src/Generator/DefaultNameGenerator.php create mode 100644 vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php create mode 100644 vendor/ramsey/uuid/src/Generator/NameGeneratorFactory.php create mode 100644 vendor/ramsey/uuid/src/Generator/NameGeneratorInterface.php create mode 100644 vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php create mode 100644 vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php create mode 100644 vendor/ramsey/uuid/src/Generator/PeclUuidTimeGenerator.php create mode 100644 vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php create mode 100644 vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php create mode 100644 vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php create mode 100644 vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php create mode 100644 vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php create mode 100644 vendor/ramsey/uuid/src/Generator/TimeGeneratorInterface.php create mode 100644 vendor/ramsey/uuid/src/Guid/Fields.php create mode 100644 vendor/ramsey/uuid/src/Guid/Guid.php create mode 100644 vendor/ramsey/uuid/src/Guid/GuidBuilder.php create mode 100644 vendor/ramsey/uuid/src/Lazy/LazyUuidFromString.php create mode 100644 vendor/ramsey/uuid/src/Math/BrickMathCalculator.php create mode 100644 vendor/ramsey/uuid/src/Math/CalculatorInterface.php create mode 100644 vendor/ramsey/uuid/src/Math/RoundingMode.php create mode 100644 vendor/ramsey/uuid/src/Nonstandard/Fields.php create mode 100644 vendor/ramsey/uuid/src/Nonstandard/Uuid.php create mode 100644 vendor/ramsey/uuid/src/Nonstandard/UuidBuilder.php create mode 100644 vendor/ramsey/uuid/src/Nonstandard/UuidV6.php create mode 100644 vendor/ramsey/uuid/src/Provider/Dce/SystemDceSecurityProvider.php create mode 100644 vendor/ramsey/uuid/src/Provider/DceSecurityProviderInterface.php create mode 100644 vendor/ramsey/uuid/src/Provider/Node/FallbackNodeProvider.php create mode 100644 vendor/ramsey/uuid/src/Provider/Node/NodeProviderCollection.php create mode 100644 vendor/ramsey/uuid/src/Provider/Node/RandomNodeProvider.php create mode 100644 vendor/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php create mode 100644 vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php create mode 100644 vendor/ramsey/uuid/src/Provider/NodeProviderInterface.php create mode 100644 vendor/ramsey/uuid/src/Provider/Time/FixedTimeProvider.php create mode 100644 vendor/ramsey/uuid/src/Provider/Time/SystemTimeProvider.php create mode 100644 vendor/ramsey/uuid/src/Provider/TimeProviderInterface.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/Fields.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/NilTrait.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/NilUuid.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/UuidV1.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/UuidV2.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/UuidV3.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/UuidV4.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/UuidV5.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/Validator.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php create mode 100644 vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php create mode 100644 vendor/ramsey/uuid/src/Type/Decimal.php create mode 100644 vendor/ramsey/uuid/src/Type/Hexadecimal.php create mode 100644 vendor/ramsey/uuid/src/Type/Integer.php create mode 100644 vendor/ramsey/uuid/src/Type/NumberInterface.php create mode 100644 vendor/ramsey/uuid/src/Type/Time.php create mode 100644 vendor/ramsey/uuid/src/Type/TypeInterface.php create mode 100644 vendor/ramsey/uuid/src/Uuid.php create mode 100644 vendor/ramsey/uuid/src/UuidFactory.php create mode 100644 vendor/ramsey/uuid/src/UuidFactoryInterface.php create mode 100644 vendor/ramsey/uuid/src/UuidInterface.php create mode 100644 vendor/ramsey/uuid/src/Validator/GenericValidator.php create mode 100644 vendor/ramsey/uuid/src/Validator/ValidatorInterface.php create mode 100644 vendor/ramsey/uuid/src/functions.php create mode 100644 vendor/spatie/backtrace/.php-cs-fixer.dist.php create mode 100644 vendor/spatie/backtrace/CHANGELOG.md create mode 100644 vendor/spatie/backtrace/LICENSE.md create mode 100644 vendor/spatie/backtrace/README.md create mode 100644 vendor/spatie/backtrace/composer.json create mode 100644 vendor/spatie/backtrace/src/Backtrace.php create mode 100644 vendor/spatie/backtrace/src/CodeSnippet.php create mode 100644 vendor/spatie/backtrace/src/File.php create mode 100644 vendor/spatie/backtrace/src/Frame.php create mode 100644 vendor/spatie/macroable/CHANGELOG.md create mode 100644 vendor/spatie/macroable/CONTRIBUTING.md create mode 100644 vendor/spatie/macroable/LICENSE.md create mode 100644 vendor/spatie/macroable/README.md create mode 100644 vendor/spatie/macroable/composer.json create mode 100644 vendor/spatie/macroable/config/.gitkeep create mode 100644 vendor/spatie/macroable/src/Macroable.php create mode 100644 vendor/spatie/ray/.php_cs.dist.php create mode 100644 vendor/spatie/ray/CHANGELOG.md create mode 100644 vendor/spatie/ray/LICENSE.md create mode 100644 vendor/spatie/ray/README.md create mode 100644 vendor/spatie/ray/composer.json create mode 100644 vendor/spatie/ray/phpstan-baseline.neon create mode 100644 vendor/spatie/ray/phpstan.neon.dist create mode 100644 vendor/spatie/ray/src/ArgumentConverter.php create mode 100644 vendor/spatie/ray/src/Client.php create mode 100644 vendor/spatie/ray/src/Concerns/RayColors.php create mode 100644 vendor/spatie/ray/src/Concerns/RayScreenColors.php create mode 100644 vendor/spatie/ray/src/Concerns/RaySizes.php create mode 100644 vendor/spatie/ray/src/Concerns/RemovesRayFrames.php create mode 100644 vendor/spatie/ray/src/Exceptions/CouldNotConnectToRay.php create mode 100644 vendor/spatie/ray/src/Exceptions/StopExecutionRequested.php create mode 100644 vendor/spatie/ray/src/Origin/DefaultOriginFactory.php create mode 100644 vendor/spatie/ray/src/Origin/Hostname.php create mode 100644 vendor/spatie/ray/src/Origin/Origin.php create mode 100644 vendor/spatie/ray/src/Origin/OriginFactory.php create mode 100644 vendor/spatie/ray/src/PayloadFactory.php create mode 100644 vendor/spatie/ray/src/Payloads/ApplicationLogPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/BoolPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/CallerPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/CarbonPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/ClearAllPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/ColorPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/CreateLockPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/CustomPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/DecodedJsonPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/ExceptionPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/FileContentsPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/HideAppPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/HidePayload.php create mode 100644 vendor/spatie/ray/src/Payloads/HtmlPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/ImagePayload.php create mode 100644 vendor/spatie/ray/src/Payloads/JsonStringPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/LabelPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/LogPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/MeasurePayload.php create mode 100644 vendor/spatie/ray/src/Payloads/NewScreenPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/NotifyPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/NullPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/Payload.php create mode 100644 vendor/spatie/ray/src/Payloads/PhpInfoPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/RemovePayload.php create mode 100644 vendor/spatie/ray/src/Payloads/ScreenColorPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/SeparatorPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/ShowAppPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/SizePayload.php create mode 100644 vendor/spatie/ray/src/Payloads/TablePayload.php create mode 100644 vendor/spatie/ray/src/Payloads/TextPayload.php create mode 100644 vendor/spatie/ray/src/Payloads/TracePayload.php create mode 100644 vendor/spatie/ray/src/Payloads/XmlPayload.php create mode 100644 vendor/spatie/ray/src/Ray.php create mode 100644 vendor/spatie/ray/src/Request.php create mode 100644 vendor/spatie/ray/src/Settings/Settings.php create mode 100644 vendor/spatie/ray/src/Settings/SettingsFactory.php create mode 100644 vendor/spatie/ray/src/Support/CacheStore.php create mode 100644 vendor/spatie/ray/src/Support/Clock.php create mode 100644 vendor/spatie/ray/src/Support/Counters.php create mode 100644 vendor/spatie/ray/src/Support/ExceptionHandler.php create mode 100644 vendor/spatie/ray/src/Support/IgnoredValue.php create mode 100644 vendor/spatie/ray/src/Support/Limiters.php create mode 100644 vendor/spatie/ray/src/Support/RateLimiter.php create mode 100644 vendor/spatie/ray/src/Support/SystemClock.php create mode 100644 vendor/spatie/ray/src/helpers.php create mode 100644 vendor/symfony/deprecation-contracts/.gitignore create mode 100644 vendor/symfony/deprecation-contracts/CHANGELOG.md create mode 100644 vendor/symfony/deprecation-contracts/LICENSE create mode 100644 vendor/symfony/deprecation-contracts/README.md create mode 100644 vendor/symfony/deprecation-contracts/composer.json create mode 100644 vendor/symfony/deprecation-contracts/function.php create mode 100644 vendor/symfony/polyfill-ctype/Ctype.php create mode 100644 vendor/symfony/polyfill-ctype/LICENSE create mode 100644 vendor/symfony/polyfill-ctype/README.md create mode 100644 vendor/symfony/polyfill-ctype/bootstrap.php create mode 100644 vendor/symfony/polyfill-ctype/bootstrap80.php create mode 100644 vendor/symfony/polyfill-ctype/composer.json create mode 100644 vendor/symfony/polyfill-php81/LICENSE create mode 100644 vendor/symfony/polyfill-php81/Php81.php create mode 100644 vendor/symfony/polyfill-php81/README.md create mode 100644 vendor/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php create mode 100644 vendor/symfony/polyfill-php81/bootstrap.php create mode 100644 vendor/symfony/polyfill-php81/composer.json create mode 100644 vendor/symfony/service-contracts/.gitignore create mode 100644 vendor/symfony/service-contracts/Attribute/Required.php create mode 100644 vendor/symfony/service-contracts/Attribute/SubscribedService.php create mode 100644 vendor/symfony/service-contracts/CHANGELOG.md create mode 100644 vendor/symfony/service-contracts/LICENSE create mode 100644 vendor/symfony/service-contracts/README.md create mode 100644 vendor/symfony/service-contracts/ResetInterface.php create mode 100644 vendor/symfony/service-contracts/ServiceLocatorTrait.php create mode 100644 vendor/symfony/service-contracts/ServiceProviderInterface.php create mode 100644 vendor/symfony/service-contracts/ServiceSubscriberInterface.php create mode 100644 vendor/symfony/service-contracts/ServiceSubscriberTrait.php create mode 100644 vendor/symfony/service-contracts/Test/ServiceLocatorTest.php create mode 100644 vendor/symfony/service-contracts/composer.json create mode 100644 vendor/symfony/stopwatch/CHANGELOG.md create mode 100644 vendor/symfony/stopwatch/LICENSE create mode 100644 vendor/symfony/stopwatch/README.md create mode 100644 vendor/symfony/stopwatch/Section.php create mode 100644 vendor/symfony/stopwatch/Stopwatch.php create mode 100644 vendor/symfony/stopwatch/StopwatchEvent.php create mode 100644 vendor/symfony/stopwatch/StopwatchPeriod.php create mode 100644 vendor/symfony/stopwatch/composer.json diff --git a/composer.json b/composer.json index a882458..771870d 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "require": { "php": ">=7.1", "rappasoft/laravel-helpers": "^2.0", - "tightenco/collect": "^8.68" + "tightenco/collect": "^8.68", + "spatie/ray": "^1.33" }, "autoload": { "files": [ diff --git a/core/library/Moka_Init.php b/core/library/Moka_Init.php index fb2f7af..61792bf 100644 --- a/core/library/Moka_Init.php +++ b/core/library/Moka_Init.php @@ -3,7 +3,7 @@ exit; } -define('OPTIMISTHUB_MOKA_PAY_VERSION', '2.9.1'); +define('OPTIMISTHUB_MOKA_PAY_VERSION', '2.9.2'); global $mokaVersion; $mokaVersion = OPTIMISTHUB_MOKA_PAY_VERSION; diff --git a/core/library/Optimisthub_Ajax.php b/core/library/Optimisthub_Ajax.php index 02b9014..dbc09e2 100644 --- a/core/library/Optimisthub_Ajax.php +++ b/core/library/Optimisthub_Ajax.php @@ -145,8 +145,12 @@ private function fetchInstallment() */ private function renderedHtml( $params ) { - global $woocommerce; - $total = data_get($woocommerce, 'cart.total'); + global $woocommerce; + + $orderId = $woocommerce->session->order_awaiting_payment; + $order = new WC_Order($orderId); + + $total = $order->get_total(); $maxInstallment = data_get($params, 'card.MaxInstallmentNumber'); $installmentRates = data_get($params, 'installments.rates'); $orderTotal = $total; diff --git a/index.php b/index.php index f2be2df..35496e0 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: Moka Payment Gateway for WooCommerce * Plugin URI: https://github.com/optimisthub/moka-woocommerce * Description: Moka Payment gateway for woocommerce - * Version: 2.9.1 + * Version: 2.9.2 * Author: Optimist Hub * Author URI: https://optimisthub.com?ref=mokaPayment * Domain Path: /languages/ diff --git a/readme.md b/readme.md index 894c1bf..a543ea7 100644 --- a/readme.md +++ b/readme.md @@ -72,6 +72,10 @@ Moka Pos, Moka Pay plugin; ### Changelog +#### Version 2.9.2 +- Issue : Installment issues. +- Feature : Added, ray package for remote debugging. + #### Version 2.9.1 - Issue : Amount Issues Fixed. diff --git a/vendor/brick/math/CHANGELOG.md b/vendor/brick/math/CHANGELOG.md new file mode 100644 index 0000000..03c3d82 --- /dev/null +++ b/vendor/brick/math/CHANGELOG.md @@ -0,0 +1,415 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [0.9.3](https://github.com/brick/math/releases/tag/0.9.3) - 2021-08-15 + +🚀 **Compatibility with PHP 8.1** + +- Support for custom object serialization; this removes a warning on PHP 8.1 due to the `Serializable` interface being deprecated (thanks @TRowbotham) + +## [0.9.2](https://github.com/brick/math/releases/tag/0.9.2) - 2021-01-20 + +🐛 **Bug fix** + +- Incorrect results could be returned when using the BCMath calculator, with a default scale set with `bcscale()`, on PHP >= 7.2 (#55). + +## [0.9.1](https://github.com/brick/math/releases/tag/0.9.1) - 2020-08-19 + +✨ New features + +- `BigInteger::not()` returns the bitwise `NOT` value + +🐛 **Bug fixes** + +- `BigInteger::toBytes()` could return an incorrect binary representation for some numbers +- The bitwise operations `and()`, `or()`, `xor()` on `BigInteger` could return an incorrect result when the GMP extension is not available + +## [0.9.0](https://github.com/brick/math/releases/tag/0.9.0) - 2020-08-18 + +👌 **Improvements** + +- `BigNumber::of()` now accepts `.123` and `123.` formats, both of which return a `BigDecimal` + +💥 **Breaking changes** + +- Deprecated method `BigInteger::powerMod()` has been removed - use `modPow()` instead +- Deprecated method `BigInteger::parse()` has been removed - use `fromBase()` instead + +## [0.8.17](https://github.com/brick/math/releases/tag/0.8.17) - 2020-08-19 + +🐛 **Bug fix** + +- `BigInteger::toBytes()` could return an incorrect binary representation for some numbers +- The bitwise operations `and()`, `or()`, `xor()` on `BigInteger` could return an incorrect result when the GMP extension is not available + +## [0.8.16](https://github.com/brick/math/releases/tag/0.8.16) - 2020-08-18 + +🚑 **Critical fix** + +- This version reintroduces the deprecated `BigInteger::parse()` method, that has been removed by mistake in version `0.8.9` and should have lasted for the whole `0.8` release cycle. + +✨ **New features** + +- `BigInteger::modInverse()` calculates a modular multiplicative inverse +- `BigInteger::fromBytes()` creates a `BigInteger` from a byte string +- `BigInteger::toBytes()` converts a `BigInteger` to a byte string +- `BigInteger::randomBits()` creates a pseudo-random `BigInteger` of a given bit length +- `BigInteger::randomRange()` creates a pseudo-random `BigInteger` between two bounds + +💩 **Deprecations** + +- `BigInteger::powerMod()` is now deprecated in favour of `modPow()` + +## [0.8.15](https://github.com/brick/math/releases/tag/0.8.15) - 2020-04-15 + +🐛 **Fixes** + +- added missing `ext-json` requirement, due to `BigNumber` implementing `JsonSerializable` + +⚡️ **Optimizations** + +- additional optimization in `BigInteger::remainder()` + +## [0.8.14](https://github.com/brick/math/releases/tag/0.8.14) - 2020-02-18 + +✨ **New features** + +- `BigInteger::getLowestSetBit()` returns the index of the rightmost one bit + +## [0.8.13](https://github.com/brick/math/releases/tag/0.8.13) - 2020-02-16 + +✨ **New features** + +- `BigInteger::isEven()` tests whether the number is even +- `BigInteger::isOdd()` tests whether the number is odd +- `BigInteger::testBit()` tests if a bit is set +- `BigInteger::getBitLength()` returns the number of bits in the minimal representation of the number + +## [0.8.12](https://github.com/brick/math/releases/tag/0.8.12) - 2020-02-03 + +🛠️ **Maintenance release** + +Classes are now annotated for better static analysis with [psalm](https://psalm.dev/). + +This is a maintenance release: no bug fixes, no new features, no breaking changes. + +## [0.8.11](https://github.com/brick/math/releases/tag/0.8.11) - 2020-01-23 + +✨ **New feature** + +`BigInteger::powerMod()` performs a power-with-modulo operation. Useful for crypto. + +## [0.8.10](https://github.com/brick/math/releases/tag/0.8.10) - 2020-01-21 + +✨ **New feature** + +`BigInteger::mod()` returns the **modulo** of two numbers. The *modulo* differs from the *remainder* when the signs of the operands are different. + +## [0.8.9](https://github.com/brick/math/releases/tag/0.8.9) - 2020-01-08 + +⚡️ **Performance improvements** + +A few additional optimizations in `BigInteger` and `BigDecimal` when one of the operands can be returned as is. Thanks to @tomtomsen in #24. + +## [0.8.8](https://github.com/brick/math/releases/tag/0.8.8) - 2019-04-25 + +🐛 **Bug fixes** + +- `BigInteger::toBase()` could return an empty string for zero values (BCMath & Native calculators only, GMP calculator unaffected) + +✨ **New features** + +- `BigInteger::toArbitraryBase()` converts a number to an arbitrary base, using a custom alphabet +- `BigInteger::fromArbitraryBase()` converts a string in an arbitrary base, using a custom alphabet, back to a number + +These methods can be used as the foundation to convert strings between different bases/alphabets, using BigInteger as an intermediate representation. + +💩 **Deprecations** + +- `BigInteger::parse()` is now deprecated in favour of `fromBase()` + +`BigInteger::fromBase()` works the same way as `parse()`, with 2 minor differences: + +- the `$base` parameter is required, it does not default to `10` +- it throws a `NumberFormatException` instead of an `InvalidArgumentException` when the number is malformed + +## [0.8.7](https://github.com/brick/math/releases/tag/0.8.7) - 2019-04-20 + +**Improvements** + +- Safer conversion from `float` when using custom locales +- **Much faster** `NativeCalculator` implementation 🚀 + +You can expect **at least a 3x performance improvement** for common arithmetic operations when using the library on systems without GMP or BCMath; it gets exponentially faster on multiplications with a high number of digits. This is due to calculations now being performed on whole blocks of digits (the block size depending on the platform, 32-bit or 64-bit) instead of digit-by-digit as before. + +## [0.8.6](https://github.com/brick/math/releases/tag/0.8.6) - 2019-04-11 + +**New method** + +`BigNumber::sum()` returns the sum of one or more numbers. + +## [0.8.5](https://github.com/brick/math/releases/tag/0.8.5) - 2019-02-12 + +**Bug fix**: `of()` factory methods could fail when passing a `float` in environments using a `LC_NUMERIC` locale with a decimal separator other than `'.'` (#20). + +Thanks @manowark 👍 + +## [0.8.4](https://github.com/brick/math/releases/tag/0.8.4) - 2018-12-07 + +**New method** + +`BigDecimal::sqrt()` calculates the square root of a decimal number, to a given scale. + +## [0.8.3](https://github.com/brick/math/releases/tag/0.8.3) - 2018-12-06 + +**New method** + +`BigInteger::sqrt()` calculates the square root of a number (thanks @peter279k). + +**New exception** + +`NegativeNumberException` is thrown when calling `sqrt()` on a negative number. + +## [0.8.2](https://github.com/brick/math/releases/tag/0.8.2) - 2018-11-08 + +**Performance update** + +- Further improvement of `toInt()` performance +- `NativeCalculator` can now perform some multiplications more efficiently + +## [0.8.1](https://github.com/brick/math/releases/tag/0.8.1) - 2018-11-07 + +Performance optimization of `toInt()` methods. + +## [0.8.0](https://github.com/brick/math/releases/tag/0.8.0) - 2018-10-13 + +**Breaking changes** + +The following deprecated methods have been removed. Use the new method name instead: + +| Method removed | Replacement method | +| --- | --- | +| `BigDecimal::getIntegral()` | `BigDecimal::getIntegralPart()` | +| `BigDecimal::getFraction()` | `BigDecimal::getFractionalPart()` | + +--- + +**New features** + +`BigInteger` has been augmented with 5 new methods for bitwise operations: + +| New method | Description | +| --- | --- | +| `and()` | performs a bitwise `AND` operation on two numbers | +| `or()` | performs a bitwise `OR` operation on two numbers | +| `xor()` | performs a bitwise `XOR` operation on two numbers | +| `shiftedLeft()` | returns the number shifted left by a number of bits | +| `shiftedRight()` | returns the number shifted right by a number of bits | + +Thanks to @DASPRiD 👍 + +## [0.7.3](https://github.com/brick/math/releases/tag/0.7.3) - 2018-08-20 + +**New method:** `BigDecimal::hasNonZeroFractionalPart()` + +**Renamed/deprecated methods:** + +- `BigDecimal::getIntegral()` has been renamed to `getIntegralPart()` and is now deprecated +- `BigDecimal::getFraction()` has been renamed to `getFractionalPart()` and is now deprecated + +## [0.7.2](https://github.com/brick/math/releases/tag/0.7.2) - 2018-07-21 + +**Performance update** + +`BigInteger::parse()` and `toBase()` now use GMP's built-in base conversion features when available. + +## [0.7.1](https://github.com/brick/math/releases/tag/0.7.1) - 2018-03-01 + +This is a maintenance release, no code has been changed. + +- When installed with `--no-dev`, the autoloader does not autoload tests anymore +- Tests and other files unnecessary for production are excluded from the dist package + +This will help make installations more compact. + +## [0.7.0](https://github.com/brick/math/releases/tag/0.7.0) - 2017-10-02 + +Methods renamed: + +- `BigNumber:sign()` has been renamed to `getSign()` +- `BigDecimal::unscaledValue()` has been renamed to `getUnscaledValue()` +- `BigDecimal::scale()` has been renamed to `getScale()` +- `BigDecimal::integral()` has been renamed to `getIntegral()` +- `BigDecimal::fraction()` has been renamed to `getFraction()` +- `BigRational::numerator()` has been renamed to `getNumerator()` +- `BigRational::denominator()` has been renamed to `getDenominator()` + +Classes renamed: + +- `ArithmeticException` has been renamed to `MathException` + +## [0.6.2](https://github.com/brick/math/releases/tag/0.6.2) - 2017-10-02 + +The base class for all exceptions is now `MathException`. +`ArithmeticException` has been deprecated, and will be removed in 0.7.0. + +## [0.6.1](https://github.com/brick/math/releases/tag/0.6.1) - 2017-10-02 + +A number of methods have been renamed: + +- `BigNumber:sign()` is deprecated; use `getSign()` instead +- `BigDecimal::unscaledValue()` is deprecated; use `getUnscaledValue()` instead +- `BigDecimal::scale()` is deprecated; use `getScale()` instead +- `BigDecimal::integral()` is deprecated; use `getIntegral()` instead +- `BigDecimal::fraction()` is deprecated; use `getFraction()` instead +- `BigRational::numerator()` is deprecated; use `getNumerator()` instead +- `BigRational::denominator()` is deprecated; use `getDenominator()` instead + +The old methods will be removed in version 0.7.0. + +## [0.6.0](https://github.com/brick/math/releases/tag/0.6.0) - 2017-08-25 + +- Minimum PHP version is now [7.1](https://gophp71.org/); for PHP 5.6 and PHP 7.0 support, use version `0.5` +- Deprecated method `BigDecimal::withScale()` has been removed; use `toScale()` instead +- Method `BigNumber::toInteger()` has been renamed to `toInt()` + +## [0.5.4](https://github.com/brick/math/releases/tag/0.5.4) - 2016-10-17 + +`BigNumber` classes now implement [JsonSerializable](http://php.net/manual/en/class.jsonserializable.php). +The JSON output is always a string. + +## [0.5.3](https://github.com/brick/math/releases/tag/0.5.3) - 2016-03-31 + +This is a bugfix release. Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6. + +## [0.5.2](https://github.com/brick/math/releases/tag/0.5.2) - 2015-08-06 + +The `$scale` parameter of `BigDecimal::dividedBy()` is now optional again. + +## [0.5.1](https://github.com/brick/math/releases/tag/0.5.1) - 2015-07-05 + +**New method: `BigNumber::toScale()`** + +This allows to convert any `BigNumber` to a `BigDecimal` with a given scale, using rounding if necessary. + +## [0.5.0](https://github.com/brick/math/releases/tag/0.5.0) - 2015-07-04 + +**New features** +- Common `BigNumber` interface for all classes, with the following methods: + - `sign()` and derived methods (`isZero()`, `isPositive()`, ...) + - `compareTo()` and derived methods (`isEqualTo()`, `isGreaterThan()`, ...) that work across different `BigNumber` types + - `toBigInteger()`, `toBigDecimal()`, `toBigRational`() conversion methods + - `toInteger()` and `toFloat()` conversion methods to native types +- Unified `of()` behaviour: every class now accepts any type of number, provided that it can be safely converted to the current type +- New method: `BigDecimal::exactlyDividedBy()`; this method automatically computes the scale of the result, provided that the division yields a finite number of digits +- New methods: `BigRational::quotient()` and `remainder()` +- Fine-grained exceptions: `DivisionByZeroException`, `RoundingNecessaryException`, `NumberFormatException` +- Factory methods `zero()`, `one()` and `ten()` available in all classes +- Rounding mode reintroduced in `BigInteger::dividedBy()` + +This release also comes with many performance improvements. + +--- + +**Breaking changes** +- `BigInteger`: + - `getSign()` is renamed to `sign()` + - `toString()` is renamed to `toBase()` + - `BigInteger::dividedBy()` now throws an exception by default if the remainder is not zero; use `quotient()` to get the previous behaviour +- `BigDecimal`: + - `getSign()` is renamed to `sign()` + - `getUnscaledValue()` is renamed to `unscaledValue()` + - `getScale()` is renamed to `scale()` + - `getIntegral()` is renamed to `integral()` + - `getFraction()` is renamed to `fraction()` + - `divideAndRemainder()` is renamed to `quotientAndRemainder()` + - `dividedBy()` now takes a **mandatory** `$scale` parameter **before** the rounding mode + - `toBigInteger()` does not accept a `$roundingMode` parameter any more + - `toBigRational()` does not simplify the fraction any more; explicitly add `->simplified()` to get the previous behaviour +- `BigRational`: + - `getSign()` is renamed to `sign()` + - `getNumerator()` is renamed to `numerator()` + - `getDenominator()` is renamed to `denominator()` + - `of()` is renamed to `nd()`, while `parse()` is renamed to `of()` +- Miscellaneous: + - `ArithmeticException` is moved to an `Exception\` sub-namespace + - `of()` factory methods now throw `NumberFormatException` instead of `InvalidArgumentException` + +## [0.4.3](https://github.com/brick/math/releases/tag/0.4.3) - 2016-03-31 + +Backport of two bug fixes from the 0.5 branch: +- `BigInteger::parse()` did not always throw `InvalidArgumentException` as expected +- Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6. + +## [0.4.2](https://github.com/brick/math/releases/tag/0.4.2) - 2015-06-16 + +New method: `BigDecimal::stripTrailingZeros()` + +## [0.4.1](https://github.com/brick/math/releases/tag/0.4.1) - 2015-06-12 + +Introducing a `BigRational` class, to perform calculations on fractions of any size. + +## [0.4.0](https://github.com/brick/math/releases/tag/0.4.0) - 2015-06-12 + +Rounding modes have been removed from `BigInteger`, and are now a concept specific to `BigDecimal`. + +`BigInteger::dividedBy()` now always returns the quotient of the division. + +## [0.3.5](https://github.com/brick/math/releases/tag/0.3.5) - 2016-03-31 + +Backport of two bug fixes from the 0.5 branch: + +- `BigInteger::parse()` did not always throw `InvalidArgumentException` as expected +- Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6. + +## [0.3.4](https://github.com/brick/math/releases/tag/0.3.4) - 2015-06-11 + +New methods: +- `BigInteger::remainder()` returns the remainder of a division only +- `BigInteger::gcd()` returns the greatest common divisor of two numbers + +## [0.3.3](https://github.com/brick/math/releases/tag/0.3.3) - 2015-06-07 + +Fix `toString()` not handling negative numbers. + +## [0.3.2](https://github.com/brick/math/releases/tag/0.3.2) - 2015-06-07 + +`BigInteger` and `BigDecimal` now have a `getSign()` method that returns: +- `-1` if the number is negative +- `0` if the number is zero +- `1` if the number is positive + +## [0.3.1](https://github.com/brick/math/releases/tag/0.3.1) - 2015-06-05 + +Minor performance improvements + +## [0.3.0](https://github.com/brick/math/releases/tag/0.3.0) - 2015-06-04 + +The `$roundingMode` and `$scale` parameters have been swapped in `BigDecimal::dividedBy()`. + +## [0.2.2](https://github.com/brick/math/releases/tag/0.2.2) - 2015-06-04 + +Stronger immutability guarantee for `BigInteger` and `BigDecimal`. + +So far, it would have been possible to break immutability of these classes by calling the `unserialize()` internal function. This release fixes that. + +## [0.2.1](https://github.com/brick/math/releases/tag/0.2.1) - 2015-06-02 + +Added `BigDecimal::divideAndRemainder()` + +## [0.2.0](https://github.com/brick/math/releases/tag/0.2.0) - 2015-05-22 + +- `min()` and `max()` do not accept an `array` any more, but a variable number of parameters +- **minimum PHP version is now 5.6** +- continuous integration with PHP 7 + +## [0.1.1](https://github.com/brick/math/releases/tag/0.1.1) - 2014-09-01 + +- Added `BigInteger::power()` +- Added HHVM support + +## [0.1.0](https://github.com/brick/math/releases/tag/0.1.0) - 2014-08-31 + +First beta release. + diff --git a/vendor/brick/math/LICENSE b/vendor/brick/math/LICENSE new file mode 100644 index 0000000..f9b724f --- /dev/null +++ b/vendor/brick/math/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013-present Benjamin Morel + +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/brick/math/SECURITY.md b/vendor/brick/math/SECURITY.md new file mode 100644 index 0000000..cc8289b --- /dev/null +++ b/vendor/brick/math/SECURITY.md @@ -0,0 +1,17 @@ +# Security Policy + +## Supported Versions + +Only the last two release streams are supported. + +| Version | Supported | +| ------- | ------------------ | +| 0.9.x | :white_check_mark: | +| 0.8.x | :white_check_mark: | +| < 0.8 | :x: | + +## Reporting a Vulnerability + +To report a security vulnerability, please use the +[Tidelift security contact](https://tidelift.com/security). +Tidelift will coordinate the fix and disclosure. diff --git a/vendor/brick/math/composer.json b/vendor/brick/math/composer.json new file mode 100644 index 0000000..ec19663 --- /dev/null +++ b/vendor/brick/math/composer.json @@ -0,0 +1,35 @@ +{ + "name": "brick/math", + "description": "Arbitrary-precision arithmetic library", + "type": "library", + "keywords": [ + "Brick", + "Math", + "Arbitrary-precision", + "Arithmetic", + "BigInteger", + "BigDecimal", + "BigRational", + "Bignum" + ], + "license": "MIT", + "require": { + "php": "^7.1 || ^8.0", + "ext-json": "*" + }, + "require-dev": { + "phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.0", + "php-coveralls/php-coveralls": "^2.2", + "vimeo/psalm": "4.9.2" + }, + "autoload": { + "psr-4": { + "Brick\\Math\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Brick\\Math\\Tests\\": "tests/" + } + } +} diff --git a/vendor/brick/math/src/BigDecimal.php b/vendor/brick/math/src/BigDecimal.php new file mode 100644 index 0000000..7824650 --- /dev/null +++ b/vendor/brick/math/src/BigDecimal.php @@ -0,0 +1,895 @@ +value = $value; + $this->scale = $scale; + } + + /** + * Creates a BigDecimal of the given value. + * + * @param BigNumber|int|float|string $value + * + * @return BigDecimal + * + * @throws MathException If the value cannot be converted to a BigDecimal. + * + * @psalm-pure + */ + public static function of($value) : BigNumber + { + return parent::of($value)->toBigDecimal(); + } + + /** + * Creates a BigDecimal from an unscaled value and a scale. + * + * Example: `(12345, 3)` will result in the BigDecimal `12.345`. + * + * @param BigNumber|int|float|string $value The unscaled value. Must be convertible to a BigInteger. + * @param int $scale The scale of the number, positive or zero. + * + * @return BigDecimal + * + * @throws \InvalidArgumentException If the scale is negative. + * + * @psalm-pure + */ + public static function ofUnscaledValue($value, int $scale = 0) : BigDecimal + { + if ($scale < 0) { + throw new \InvalidArgumentException('The scale cannot be negative.'); + } + + return new BigDecimal((string) BigInteger::of($value), $scale); + } + + /** + * Returns a BigDecimal representing zero, with a scale of zero. + * + * @return BigDecimal + * + * @psalm-pure + */ + public static function zero() : BigDecimal + { + /** + * @psalm-suppress ImpureStaticVariable + * @var BigDecimal|null $zero + */ + static $zero; + + if ($zero === null) { + $zero = new BigDecimal('0'); + } + + return $zero; + } + + /** + * Returns a BigDecimal representing one, with a scale of zero. + * + * @return BigDecimal + * + * @psalm-pure + */ + public static function one() : BigDecimal + { + /** + * @psalm-suppress ImpureStaticVariable + * @var BigDecimal|null $one + */ + static $one; + + if ($one === null) { + $one = new BigDecimal('1'); + } + + return $one; + } + + /** + * Returns a BigDecimal representing ten, with a scale of zero. + * + * @return BigDecimal + * + * @psalm-pure + */ + public static function ten() : BigDecimal + { + /** + * @psalm-suppress ImpureStaticVariable + * @var BigDecimal|null $ten + */ + static $ten; + + if ($ten === null) { + $ten = new BigDecimal('10'); + } + + return $ten; + } + + /** + * Returns the sum of this number and the given one. + * + * The result has a scale of `max($this->scale, $that->scale)`. + * + * @param BigNumber|int|float|string $that The number to add. Must be convertible to a BigDecimal. + * + * @return BigDecimal The result. + * + * @throws MathException If the number is not valid, or is not convertible to a BigDecimal. + */ + public function plus($that) : BigDecimal + { + $that = BigDecimal::of($that); + + if ($that->value === '0' && $that->scale <= $this->scale) { + return $this; + } + + if ($this->value === '0' && $this->scale <= $that->scale) { + return $that; + } + + [$a, $b] = $this->scaleValues($this, $that); + + $value = Calculator::get()->add($a, $b); + $scale = $this->scale > $that->scale ? $this->scale : $that->scale; + + return new BigDecimal($value, $scale); + } + + /** + * Returns the difference of this number and the given one. + * + * The result has a scale of `max($this->scale, $that->scale)`. + * + * @param BigNumber|int|float|string $that The number to subtract. Must be convertible to a BigDecimal. + * + * @return BigDecimal The result. + * + * @throws MathException If the number is not valid, or is not convertible to a BigDecimal. + */ + public function minus($that) : BigDecimal + { + $that = BigDecimal::of($that); + + if ($that->value === '0' && $that->scale <= $this->scale) { + return $this; + } + + [$a, $b] = $this->scaleValues($this, $that); + + $value = Calculator::get()->sub($a, $b); + $scale = $this->scale > $that->scale ? $this->scale : $that->scale; + + return new BigDecimal($value, $scale); + } + + /** + * Returns the product of this number and the given one. + * + * The result has a scale of `$this->scale + $that->scale`. + * + * @param BigNumber|int|float|string $that The multiplier. Must be convertible to a BigDecimal. + * + * @return BigDecimal The result. + * + * @throws MathException If the multiplier is not a valid number, or is not convertible to a BigDecimal. + */ + public function multipliedBy($that) : BigDecimal + { + $that = BigDecimal::of($that); + + if ($that->value === '1' && $that->scale === 0) { + return $this; + } + + if ($this->value === '1' && $this->scale === 0) { + return $that; + } + + $value = Calculator::get()->mul($this->value, $that->value); + $scale = $this->scale + $that->scale; + + return new BigDecimal($value, $scale); + } + + /** + * Returns the result of the division of this number by the given one, at the given scale. + * + * @param BigNumber|int|float|string $that The divisor. + * @param int|null $scale The desired scale, or null to use the scale of this number. + * @param int $roundingMode An optional rounding mode. + * + * @return BigDecimal + * + * @throws \InvalidArgumentException If the scale or rounding mode is invalid. + * @throws MathException If the number is invalid, is zero, or rounding was necessary. + */ + public function dividedBy($that, ?int $scale = null, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal + { + $that = BigDecimal::of($that); + + if ($that->isZero()) { + throw DivisionByZeroException::divisionByZero(); + } + + if ($scale === null) { + $scale = $this->scale; + } elseif ($scale < 0) { + throw new \InvalidArgumentException('Scale cannot be negative.'); + } + + if ($that->value === '1' && $that->scale === 0 && $scale === $this->scale) { + return $this; + } + + $p = $this->valueWithMinScale($that->scale + $scale); + $q = $that->valueWithMinScale($this->scale - $scale); + + $result = Calculator::get()->divRound($p, $q, $roundingMode); + + return new BigDecimal($result, $scale); + } + + /** + * Returns the exact result of the division of this number by the given one. + * + * The scale of the result is automatically calculated to fit all the fraction digits. + * + * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal. + * + * @return BigDecimal The result. + * + * @throws MathException If the divisor is not a valid number, is not convertible to a BigDecimal, is zero, + * or the result yields an infinite number of digits. + */ + public function exactlyDividedBy($that) : BigDecimal + { + $that = BigDecimal::of($that); + + if ($that->value === '0') { + throw DivisionByZeroException::divisionByZero(); + } + + [, $b] = $this->scaleValues($this, $that); + + $d = \rtrim($b, '0'); + $scale = \strlen($b) - \strlen($d); + + $calculator = Calculator::get(); + + foreach ([5, 2] as $prime) { + for (;;) { + $lastDigit = (int) $d[-1]; + + if ($lastDigit % $prime !== 0) { + break; + } + + $d = $calculator->divQ($d, (string) $prime); + $scale++; + } + } + + return $this->dividedBy($that, $scale)->stripTrailingZeros(); + } + + /** + * Returns this number exponentiated to the given value. + * + * The result has a scale of `$this->scale * $exponent`. + * + * @param int $exponent The exponent. + * + * @return BigDecimal The result. + * + * @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000. + */ + public function power(int $exponent) : BigDecimal + { + if ($exponent === 0) { + return BigDecimal::one(); + } + + if ($exponent === 1) { + return $this; + } + + if ($exponent < 0 || $exponent > Calculator::MAX_POWER) { + throw new \InvalidArgumentException(\sprintf( + 'The exponent %d is not in the range 0 to %d.', + $exponent, + Calculator::MAX_POWER + )); + } + + return new BigDecimal(Calculator::get()->pow($this->value, $exponent), $this->scale * $exponent); + } + + /** + * Returns the quotient of the division of this number by this given one. + * + * The quotient has a scale of `0`. + * + * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal. + * + * @return BigDecimal The quotient. + * + * @throws MathException If the divisor is not a valid decimal number, or is zero. + */ + public function quotient($that) : BigDecimal + { + $that = BigDecimal::of($that); + + if ($that->isZero()) { + throw DivisionByZeroException::divisionByZero(); + } + + $p = $this->valueWithMinScale($that->scale); + $q = $that->valueWithMinScale($this->scale); + + $quotient = Calculator::get()->divQ($p, $q); + + return new BigDecimal($quotient, 0); + } + + /** + * Returns the remainder of the division of this number by this given one. + * + * The remainder has a scale of `max($this->scale, $that->scale)`. + * + * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal. + * + * @return BigDecimal The remainder. + * + * @throws MathException If the divisor is not a valid decimal number, or is zero. + */ + public function remainder($that) : BigDecimal + { + $that = BigDecimal::of($that); + + if ($that->isZero()) { + throw DivisionByZeroException::divisionByZero(); + } + + $p = $this->valueWithMinScale($that->scale); + $q = $that->valueWithMinScale($this->scale); + + $remainder = Calculator::get()->divR($p, $q); + + $scale = $this->scale > $that->scale ? $this->scale : $that->scale; + + return new BigDecimal($remainder, $scale); + } + + /** + * Returns the quotient and remainder of the division of this number by the given one. + * + * The quotient has a scale of `0`, and the remainder has a scale of `max($this->scale, $that->scale)`. + * + * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal. + * + * @return BigDecimal[] An array containing the quotient and the remainder. + * + * @throws MathException If the divisor is not a valid decimal number, or is zero. + */ + public function quotientAndRemainder($that) : array + { + $that = BigDecimal::of($that); + + if ($that->isZero()) { + throw DivisionByZeroException::divisionByZero(); + } + + $p = $this->valueWithMinScale($that->scale); + $q = $that->valueWithMinScale($this->scale); + + [$quotient, $remainder] = Calculator::get()->divQR($p, $q); + + $scale = $this->scale > $that->scale ? $this->scale : $that->scale; + + $quotient = new BigDecimal($quotient, 0); + $remainder = new BigDecimal($remainder, $scale); + + return [$quotient, $remainder]; + } + + /** + * Returns the square root of this number, rounded down to the given number of decimals. + * + * @param int $scale + * + * @return BigDecimal + * + * @throws \InvalidArgumentException If the scale is negative. + * @throws NegativeNumberException If this number is negative. + */ + public function sqrt(int $scale) : BigDecimal + { + if ($scale < 0) { + throw new \InvalidArgumentException('Scale cannot be negative.'); + } + + if ($this->value === '0') { + return new BigDecimal('0', $scale); + } + + if ($this->value[0] === '-') { + throw new NegativeNumberException('Cannot calculate the square root of a negative number.'); + } + + $value = $this->value; + $addDigits = 2 * $scale - $this->scale; + + if ($addDigits > 0) { + // add zeros + $value .= \str_repeat('0', $addDigits); + } elseif ($addDigits < 0) { + // trim digits + if (-$addDigits >= \strlen($this->value)) { + // requesting a scale too low, will always yield a zero result + return new BigDecimal('0', $scale); + } + + $value = \substr($value, 0, $addDigits); + } + + $value = Calculator::get()->sqrt($value); + + return new BigDecimal($value, $scale); + } + + /** + * Returns a copy of this BigDecimal with the decimal point moved $n places to the left. + * + * @param int $n + * + * @return BigDecimal + */ + public function withPointMovedLeft(int $n) : BigDecimal + { + if ($n === 0) { + return $this; + } + + if ($n < 0) { + return $this->withPointMovedRight(-$n); + } + + return new BigDecimal($this->value, $this->scale + $n); + } + + /** + * Returns a copy of this BigDecimal with the decimal point moved $n places to the right. + * + * @param int $n + * + * @return BigDecimal + */ + public function withPointMovedRight(int $n) : BigDecimal + { + if ($n === 0) { + return $this; + } + + if ($n < 0) { + return $this->withPointMovedLeft(-$n); + } + + $value = $this->value; + $scale = $this->scale - $n; + + if ($scale < 0) { + if ($value !== '0') { + $value .= \str_repeat('0', -$scale); + } + $scale = 0; + } + + return new BigDecimal($value, $scale); + } + + /** + * Returns a copy of this BigDecimal with any trailing zeros removed from the fractional part. + * + * @return BigDecimal + */ + public function stripTrailingZeros() : BigDecimal + { + if ($this->scale === 0) { + return $this; + } + + $trimmedValue = \rtrim($this->value, '0'); + + if ($trimmedValue === '') { + return BigDecimal::zero(); + } + + $trimmableZeros = \strlen($this->value) - \strlen($trimmedValue); + + if ($trimmableZeros === 0) { + return $this; + } + + if ($trimmableZeros > $this->scale) { + $trimmableZeros = $this->scale; + } + + $value = \substr($this->value, 0, -$trimmableZeros); + $scale = $this->scale - $trimmableZeros; + + return new BigDecimal($value, $scale); + } + + /** + * Returns the absolute value of this number. + * + * @return BigDecimal + */ + public function abs() : BigDecimal + { + return $this->isNegative() ? $this->negated() : $this; + } + + /** + * Returns the negated value of this number. + * + * @return BigDecimal + */ + public function negated() : BigDecimal + { + return new BigDecimal(Calculator::get()->neg($this->value), $this->scale); + } + + /** + * {@inheritdoc} + */ + public function compareTo($that) : int + { + $that = BigNumber::of($that); + + if ($that instanceof BigInteger) { + $that = $that->toBigDecimal(); + } + + if ($that instanceof BigDecimal) { + [$a, $b] = $this->scaleValues($this, $that); + + return Calculator::get()->cmp($a, $b); + } + + return - $that->compareTo($this); + } + + /** + * {@inheritdoc} + */ + public function getSign() : int + { + return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1); + } + + /** + * @return BigInteger + */ + public function getUnscaledValue() : BigInteger + { + return BigInteger::create($this->value); + } + + /** + * @return int + */ + public function getScale() : int + { + return $this->scale; + } + + /** + * Returns a string representing the integral part of this decimal number. + * + * Example: `-123.456` => `-123`. + * + * @return string + */ + public function getIntegralPart() : string + { + if ($this->scale === 0) { + return $this->value; + } + + $value = $this->getUnscaledValueWithLeadingZeros(); + + return \substr($value, 0, -$this->scale); + } + + /** + * Returns a string representing the fractional part of this decimal number. + * + * If the scale is zero, an empty string is returned. + * + * Examples: `-123.456` => '456', `123` => ''. + * + * @return string + */ + public function getFractionalPart() : string + { + if ($this->scale === 0) { + return ''; + } + + $value = $this->getUnscaledValueWithLeadingZeros(); + + return \substr($value, -$this->scale); + } + + /** + * Returns whether this decimal number has a non-zero fractional part. + * + * @return bool + */ + public function hasNonZeroFractionalPart() : bool + { + return $this->getFractionalPart() !== \str_repeat('0', $this->scale); + } + + /** + * {@inheritdoc} + */ + public function toBigInteger() : BigInteger + { + $zeroScaleDecimal = $this->scale === 0 ? $this : $this->dividedBy(1, 0); + + return BigInteger::create($zeroScaleDecimal->value); + } + + /** + * {@inheritdoc} + */ + public function toBigDecimal() : BigDecimal + { + return $this; + } + + /** + * {@inheritdoc} + */ + public function toBigRational() : BigRational + { + $numerator = BigInteger::create($this->value); + $denominator = BigInteger::create('1' . \str_repeat('0', $this->scale)); + + return BigRational::create($numerator, $denominator, false); + } + + /** + * {@inheritdoc} + */ + public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal + { + if ($scale === $this->scale) { + return $this; + } + + return $this->dividedBy(BigDecimal::one(), $scale, $roundingMode); + } + + /** + * {@inheritdoc} + */ + public function toInt() : int + { + return $this->toBigInteger()->toInt(); + } + + /** + * {@inheritdoc} + */ + public function toFloat() : float + { + return (float) (string) $this; + } + + /** + * {@inheritdoc} + */ + public function __toString() : string + { + if ($this->scale === 0) { + return $this->value; + } + + $value = $this->getUnscaledValueWithLeadingZeros(); + + return \substr($value, 0, -$this->scale) . '.' . \substr($value, -$this->scale); + } + + /** + * This method is required for serializing the object and SHOULD NOT be accessed directly. + * + * @internal + * + * @return array{value: string, scale: int} + */ + public function __serialize(): array + { + return ['value' => $this->value, 'scale' => $this->scale]; + } + + /** + * This method is only here to allow unserializing the object and cannot be accessed directly. + * + * @internal + * @psalm-suppress RedundantPropertyInitializationCheck + * + * @param array{value: string, scale: int} $data + * + * @return void + * + * @throws \LogicException + */ + public function __unserialize(array $data): void + { + if (isset($this->value)) { + throw new \LogicException('__unserialize() is an internal function, it must not be called directly.'); + } + + $this->value = $data['value']; + $this->scale = $data['scale']; + } + + /** + * This method is required by interface Serializable and SHOULD NOT be accessed directly. + * + * @internal + * + * @return string + */ + public function serialize() : string + { + return $this->value . ':' . $this->scale; + } + + /** + * This method is only here to implement interface Serializable and cannot be accessed directly. + * + * @internal + * @psalm-suppress RedundantPropertyInitializationCheck + * + * @param string $value + * + * @return void + * + * @throws \LogicException + */ + public function unserialize($value) : void + { + if (isset($this->value)) { + throw new \LogicException('unserialize() is an internal function, it must not be called directly.'); + } + + [$value, $scale] = \explode(':', $value); + + $this->value = $value; + $this->scale = (int) $scale; + } + + /** + * Puts the internal values of the given decimal numbers on the same scale. + * + * @param BigDecimal $x The first decimal number. + * @param BigDecimal $y The second decimal number. + * + * @return array{string, string} The scaled integer values of $x and $y. + */ + private function scaleValues(BigDecimal $x, BigDecimal $y) : array + { + $a = $x->value; + $b = $y->value; + + if ($b !== '0' && $x->scale > $y->scale) { + $b .= \str_repeat('0', $x->scale - $y->scale); + } elseif ($a !== '0' && $x->scale < $y->scale) { + $a .= \str_repeat('0', $y->scale - $x->scale); + } + + return [$a, $b]; + } + + /** + * @param int $scale + * + * @return string + */ + private function valueWithMinScale(int $scale) : string + { + $value = $this->value; + + if ($this->value !== '0' && $scale > $this->scale) { + $value .= \str_repeat('0', $scale - $this->scale); + } + + return $value; + } + + /** + * Adds leading zeros if necessary to the unscaled value to represent the full decimal number. + * + * @return string + */ + private function getUnscaledValueWithLeadingZeros() : string + { + $value = $this->value; + $targetLength = $this->scale + 1; + $negative = ($value[0] === '-'); + $length = \strlen($value); + + if ($negative) { + $length--; + } + + if ($length >= $targetLength) { + return $this->value; + } + + if ($negative) { + $value = \substr($value, 1); + } + + $value = \str_pad($value, $targetLength, '0', STR_PAD_LEFT); + + if ($negative) { + $value = '-' . $value; + } + + return $value; + } +} diff --git a/vendor/brick/math/src/BigInteger.php b/vendor/brick/math/src/BigInteger.php new file mode 100644 index 0000000..f213fbe --- /dev/null +++ b/vendor/brick/math/src/BigInteger.php @@ -0,0 +1,1184 @@ +value = $value; + } + + /** + * Creates a BigInteger of the given value. + * + * @param BigNumber|int|float|string $value + * + * @return BigInteger + * + * @throws MathException If the value cannot be converted to a BigInteger. + * + * @psalm-pure + */ + public static function of($value) : BigNumber + { + return parent::of($value)->toBigInteger(); + } + + /** + * Creates a number from a string in a given base. + * + * The string can optionally be prefixed with the `+` or `-` sign. + * + * Bases greater than 36 are not supported by this method, as there is no clear consensus on which of the lowercase + * or uppercase characters should come first. Instead, this method accepts any base up to 36, and does not + * differentiate lowercase and uppercase characters, which are considered equal. + * + * For bases greater than 36, and/or custom alphabets, use the fromArbitraryBase() method. + * + * @param string $number The number to convert, in the given base. + * @param int $base The base of the number, between 2 and 36. + * + * @return BigInteger + * + * @throws NumberFormatException If the number is empty, or contains invalid chars for the given base. + * @throws \InvalidArgumentException If the base is out of range. + * + * @psalm-pure + */ + public static function fromBase(string $number, int $base) : BigInteger + { + if ($number === '') { + throw new NumberFormatException('The number cannot be empty.'); + } + + if ($base < 2 || $base > 36) { + throw new \InvalidArgumentException(\sprintf('Base %d is not in range 2 to 36.', $base)); + } + + if ($number[0] === '-') { + $sign = '-'; + $number = \substr($number, 1); + } elseif ($number[0] === '+') { + $sign = ''; + $number = \substr($number, 1); + } else { + $sign = ''; + } + + if ($number === '') { + throw new NumberFormatException('The number cannot be empty.'); + } + + $number = \ltrim($number, '0'); + + if ($number === '') { + // The result will be the same in any base, avoid further calculation. + return BigInteger::zero(); + } + + if ($number === '1') { + // The result will be the same in any base, avoid further calculation. + return new BigInteger($sign . '1'); + } + + $pattern = '/[^' . \substr(Calculator::ALPHABET, 0, $base) . ']/'; + + if (\preg_match($pattern, \strtolower($number), $matches) === 1) { + throw new NumberFormatException(\sprintf('"%s" is not a valid character in base %d.', $matches[0], $base)); + } + + if ($base === 10) { + // The number is usable as is, avoid further calculation. + return new BigInteger($sign . $number); + } + + $result = Calculator::get()->fromBase($number, $base); + + return new BigInteger($sign . $result); + } + + /** + * Parses a string containing an integer in an arbitrary base, using a custom alphabet. + * + * Because this method accepts an alphabet with any character, including dash, it does not handle negative numbers. + * + * @param string $number The number to parse. + * @param string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8. + * + * @return BigInteger + * + * @throws NumberFormatException If the given number is empty or contains invalid chars for the given alphabet. + * @throws \InvalidArgumentException If the alphabet does not contain at least 2 chars. + * + * @psalm-pure + */ + public static function fromArbitraryBase(string $number, string $alphabet) : BigInteger + { + if ($number === '') { + throw new NumberFormatException('The number cannot be empty.'); + } + + $base = \strlen($alphabet); + + if ($base < 2) { + throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.'); + } + + $pattern = '/[^' . \preg_quote($alphabet, '/') . ']/'; + + if (\preg_match($pattern, $number, $matches) === 1) { + throw NumberFormatException::charNotInAlphabet($matches[0]); + } + + $number = Calculator::get()->fromArbitraryBase($number, $alphabet, $base); + + return new BigInteger($number); + } + + /** + * Translates a string of bytes containing the binary representation of a BigInteger into a BigInteger. + * + * The input string is assumed to be in big-endian byte-order: the most significant byte is in the zeroth element. + * + * If `$signed` is true, the input is assumed to be in two's-complement representation, and the leading bit is + * interpreted as a sign bit. If `$signed` is false, the input is interpreted as an unsigned number, and the + * resulting BigInteger will always be positive or zero. + * + * This method can be used to retrieve a number exported by `toBytes()`, as long as the `$signed` flags match. + * + * @param string $value The byte string. + * @param bool $signed Whether to interpret as a signed number in two's-complement representation with a leading + * sign bit. + * + * @return BigInteger + * + * @throws NumberFormatException If the string is empty. + */ + public static function fromBytes(string $value, bool $signed = true) : BigInteger + { + if ($value === '') { + throw new NumberFormatException('The byte string must not be empty.'); + } + + $twosComplement = false; + + if ($signed) { + $x = \ord($value[0]); + + if (($twosComplement = ($x >= 0x80))) { + $value = ~$value; + } + } + + $number = self::fromBase(\bin2hex($value), 16); + + if ($twosComplement) { + return $number->plus(1)->negated(); + } + + return $number; + } + + /** + * Generates a pseudo-random number in the range 0 to 2^numBits - 1. + * + * Using the default random bytes generator, this method is suitable for cryptographic use. + * + * @psalm-param callable(int): string $randomBytesGenerator + * + * @param int $numBits The number of bits. + * @param callable|null $randomBytesGenerator A function that accepts a number of bytes as an integer, and returns a + * string of random bytes of the given length. Defaults to the + * `random_bytes()` function. + * + * @return BigInteger + * + * @throws \InvalidArgumentException If $numBits is negative. + */ + public static function randomBits(int $numBits, ?callable $randomBytesGenerator = null) : BigInteger + { + if ($numBits < 0) { + throw new \InvalidArgumentException('The number of bits cannot be negative.'); + } + + if ($numBits === 0) { + return BigInteger::zero(); + } + + if ($randomBytesGenerator === null) { + $randomBytesGenerator = 'random_bytes'; + } + + $byteLength = \intdiv($numBits - 1, 8) + 1; + + $extraBits = ($byteLength * 8 - $numBits); + $bitmask = \chr(0xFF >> $extraBits); + + $randomBytes = $randomBytesGenerator($byteLength); + $randomBytes[0] = $randomBytes[0] & $bitmask; + + return self::fromBytes($randomBytes, false); + } + + /** + * Generates a pseudo-random number between `$min` and `$max`. + * + * Using the default random bytes generator, this method is suitable for cryptographic use. + * + * @psalm-param (callable(int): string)|null $randomBytesGenerator + * + * @param BigNumber|int|float|string $min The lower bound. Must be convertible to a BigInteger. + * @param BigNumber|int|float|string $max The upper bound. Must be convertible to a BigInteger. + * @param callable|null $randomBytesGenerator A function that accepts a number of bytes as an integer, + * and returns a string of random bytes of the given length. + * Defaults to the `random_bytes()` function. + * + * @return BigInteger + * + * @throws MathException If one of the parameters cannot be converted to a BigInteger, + * or `$min` is greater than `$max`. + */ + public static function randomRange($min, $max, ?callable $randomBytesGenerator = null) : BigInteger + { + $min = BigInteger::of($min); + $max = BigInteger::of($max); + + if ($min->isGreaterThan($max)) { + throw new MathException('$min cannot be greater than $max.'); + } + + if ($min->isEqualTo($max)) { + return $min; + } + + $diff = $max->minus($min); + $bitLength = $diff->getBitLength(); + + // try until the number is in range (50% to 100% chance of success) + do { + $randomNumber = self::randomBits($bitLength, $randomBytesGenerator); + } while ($randomNumber->isGreaterThan($diff)); + + return $randomNumber->plus($min); + } + + /** + * Returns a BigInteger representing zero. + * + * @return BigInteger + * + * @psalm-pure + */ + public static function zero() : BigInteger + { + /** + * @psalm-suppress ImpureStaticVariable + * @var BigInteger|null $zero + */ + static $zero; + + if ($zero === null) { + $zero = new BigInteger('0'); + } + + return $zero; + } + + /** + * Returns a BigInteger representing one. + * + * @return BigInteger + * + * @psalm-pure + */ + public static function one() : BigInteger + { + /** + * @psalm-suppress ImpureStaticVariable + * @var BigInteger|null $one + */ + static $one; + + if ($one === null) { + $one = new BigInteger('1'); + } + + return $one; + } + + /** + * Returns a BigInteger representing ten. + * + * @return BigInteger + * + * @psalm-pure + */ + public static function ten() : BigInteger + { + /** + * @psalm-suppress ImpureStaticVariable + * @var BigInteger|null $ten + */ + static $ten; + + if ($ten === null) { + $ten = new BigInteger('10'); + } + + return $ten; + } + + /** + * Returns the sum of this number and the given one. + * + * @param BigNumber|int|float|string $that The number to add. Must be convertible to a BigInteger. + * + * @return BigInteger The result. + * + * @throws MathException If the number is not valid, or is not convertible to a BigInteger. + */ + public function plus($that) : BigInteger + { + $that = BigInteger::of($that); + + if ($that->value === '0') { + return $this; + } + + if ($this->value === '0') { + return $that; + } + + $value = Calculator::get()->add($this->value, $that->value); + + return new BigInteger($value); + } + + /** + * Returns the difference of this number and the given one. + * + * @param BigNumber|int|float|string $that The number to subtract. Must be convertible to a BigInteger. + * + * @return BigInteger The result. + * + * @throws MathException If the number is not valid, or is not convertible to a BigInteger. + */ + public function minus($that) : BigInteger + { + $that = BigInteger::of($that); + + if ($that->value === '0') { + return $this; + } + + $value = Calculator::get()->sub($this->value, $that->value); + + return new BigInteger($value); + } + + /** + * Returns the product of this number and the given one. + * + * @param BigNumber|int|float|string $that The multiplier. Must be convertible to a BigInteger. + * + * @return BigInteger The result. + * + * @throws MathException If the multiplier is not a valid number, or is not convertible to a BigInteger. + */ + public function multipliedBy($that) : BigInteger + { + $that = BigInteger::of($that); + + if ($that->value === '1') { + return $this; + } + + if ($this->value === '1') { + return $that; + } + + $value = Calculator::get()->mul($this->value, $that->value); + + return new BigInteger($value); + } + + /** + * Returns the result of the division of this number by the given one. + * + * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger. + * @param int $roundingMode An optional rounding mode. + * + * @return BigInteger The result. + * + * @throws MathException If the divisor is not a valid number, is not convertible to a BigInteger, is zero, + * or RoundingMode::UNNECESSARY is used and the remainder is not zero. + */ + public function dividedBy($that, int $roundingMode = RoundingMode::UNNECESSARY) : BigInteger + { + $that = BigInteger::of($that); + + if ($that->value === '1') { + return $this; + } + + if ($that->value === '0') { + throw DivisionByZeroException::divisionByZero(); + } + + $result = Calculator::get()->divRound($this->value, $that->value, $roundingMode); + + return new BigInteger($result); + } + + /** + * Returns this number exponentiated to the given value. + * + * @param int $exponent The exponent. + * + * @return BigInteger The result. + * + * @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000. + */ + public function power(int $exponent) : BigInteger + { + if ($exponent === 0) { + return BigInteger::one(); + } + + if ($exponent === 1) { + return $this; + } + + if ($exponent < 0 || $exponent > Calculator::MAX_POWER) { + throw new \InvalidArgumentException(\sprintf( + 'The exponent %d is not in the range 0 to %d.', + $exponent, + Calculator::MAX_POWER + )); + } + + return new BigInteger(Calculator::get()->pow($this->value, $exponent)); + } + + /** + * Returns the quotient of the division of this number by the given one. + * + * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger. + * + * @return BigInteger + * + * @throws DivisionByZeroException If the divisor is zero. + */ + public function quotient($that) : BigInteger + { + $that = BigInteger::of($that); + + if ($that->value === '1') { + return $this; + } + + if ($that->value === '0') { + throw DivisionByZeroException::divisionByZero(); + } + + $quotient = Calculator::get()->divQ($this->value, $that->value); + + return new BigInteger($quotient); + } + + /** + * Returns the remainder of the division of this number by the given one. + * + * The remainder, when non-zero, has the same sign as the dividend. + * + * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger. + * + * @return BigInteger + * + * @throws DivisionByZeroException If the divisor is zero. + */ + public function remainder($that) : BigInteger + { + $that = BigInteger::of($that); + + if ($that->value === '1') { + return BigInteger::zero(); + } + + if ($that->value === '0') { + throw DivisionByZeroException::divisionByZero(); + } + + $remainder = Calculator::get()->divR($this->value, $that->value); + + return new BigInteger($remainder); + } + + /** + * Returns the quotient and remainder of the division of this number by the given one. + * + * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger. + * + * @return BigInteger[] An array containing the quotient and the remainder. + * + * @throws DivisionByZeroException If the divisor is zero. + */ + public function quotientAndRemainder($that) : array + { + $that = BigInteger::of($that); + + if ($that->value === '0') { + throw DivisionByZeroException::divisionByZero(); + } + + [$quotient, $remainder] = Calculator::get()->divQR($this->value, $that->value); + + return [ + new BigInteger($quotient), + new BigInteger($remainder) + ]; + } + + /** + * Returns the modulo of this number and the given one. + * + * The modulo operation yields the same result as the remainder operation when both operands are of the same sign, + * and may differ when signs are different. + * + * The result of the modulo operation, when non-zero, has the same sign as the divisor. + * + * @param BigNumber|int|float|string $that The divisor. Must be convertible to a BigInteger. + * + * @return BigInteger + * + * @throws DivisionByZeroException If the divisor is zero. + */ + public function mod($that) : BigInteger + { + $that = BigInteger::of($that); + + if ($that->value === '0') { + throw DivisionByZeroException::modulusMustNotBeZero(); + } + + $value = Calculator::get()->mod($this->value, $that->value); + + return new BigInteger($value); + } + + /** + * Returns the modular multiplicative inverse of this BigInteger modulo $m. + * + * @param BigInteger $m + * + * @return BigInteger + * + * @throws DivisionByZeroException If $m is zero. + * @throws NegativeNumberException If $m is negative. + * @throws MathException If this BigInteger has no multiplicative inverse mod m (that is, this BigInteger + * is not relatively prime to m). + */ + public function modInverse(BigInteger $m) : BigInteger + { + if ($m->value === '0') { + throw DivisionByZeroException::modulusMustNotBeZero(); + } + + if ($m->isNegative()) { + throw new NegativeNumberException('Modulus must not be negative.'); + } + + if ($m->value === '1') { + return BigInteger::zero(); + } + + $value = Calculator::get()->modInverse($this->value, $m->value); + + if ($value === null) { + throw new MathException('Unable to compute the modInverse for the given modulus.'); + } + + return new BigInteger($value); + } + + /** + * Returns this number raised into power with modulo. + * + * This operation only works on positive numbers. + * + * @param BigNumber|int|float|string $exp The exponent. Must be positive or zero. + * @param BigNumber|int|float|string $mod The modulus. Must be strictly positive. + * + * @return BigInteger + * + * @throws NegativeNumberException If any of the operands is negative. + * @throws DivisionByZeroException If the modulus is zero. + */ + public function modPow($exp, $mod) : BigInteger + { + $exp = BigInteger::of($exp); + $mod = BigInteger::of($mod); + + if ($this->isNegative() || $exp->isNegative() || $mod->isNegative()) { + throw new NegativeNumberException('The operands cannot be negative.'); + } + + if ($mod->isZero()) { + throw DivisionByZeroException::modulusMustNotBeZero(); + } + + $result = Calculator::get()->modPow($this->value, $exp->value, $mod->value); + + return new BigInteger($result); + } + + /** + * Returns the greatest common divisor of this number and the given one. + * + * The GCD is always positive, unless both operands are zero, in which case it is zero. + * + * @param BigNumber|int|float|string $that The operand. Must be convertible to an integer number. + * + * @return BigInteger + */ + public function gcd($that) : BigInteger + { + $that = BigInteger::of($that); + + if ($that->value === '0' && $this->value[0] !== '-') { + return $this; + } + + if ($this->value === '0' && $that->value[0] !== '-') { + return $that; + } + + $value = Calculator::get()->gcd($this->value, $that->value); + + return new BigInteger($value); + } + + /** + * Returns the integer square root number of this number, rounded down. + * + * The result is the largest x such that x² ≤ n. + * + * @return BigInteger + * + * @throws NegativeNumberException If this number is negative. + */ + public function sqrt() : BigInteger + { + if ($this->value[0] === '-') { + throw new NegativeNumberException('Cannot calculate the square root of a negative number.'); + } + + $value = Calculator::get()->sqrt($this->value); + + return new BigInteger($value); + } + + /** + * Returns the absolute value of this number. + * + * @return BigInteger + */ + public function abs() : BigInteger + { + return $this->isNegative() ? $this->negated() : $this; + } + + /** + * Returns the inverse of this number. + * + * @return BigInteger + */ + public function negated() : BigInteger + { + return new BigInteger(Calculator::get()->neg($this->value)); + } + + /** + * Returns the integer bitwise-and combined with another integer. + * + * This method returns a negative BigInteger if and only if both operands are negative. + * + * @param BigNumber|int|float|string $that The operand. Must be convertible to an integer number. + * + * @return BigInteger + */ + public function and($that) : BigInteger + { + $that = BigInteger::of($that); + + return new BigInteger(Calculator::get()->and($this->value, $that->value)); + } + + /** + * Returns the integer bitwise-or combined with another integer. + * + * This method returns a negative BigInteger if and only if either of the operands is negative. + * + * @param BigNumber|int|float|string $that The operand. Must be convertible to an integer number. + * + * @return BigInteger + */ + public function or($that) : BigInteger + { + $that = BigInteger::of($that); + + return new BigInteger(Calculator::get()->or($this->value, $that->value)); + } + + /** + * Returns the integer bitwise-xor combined with another integer. + * + * This method returns a negative BigInteger if and only if exactly one of the operands is negative. + * + * @param BigNumber|int|float|string $that The operand. Must be convertible to an integer number. + * + * @return BigInteger + */ + public function xor($that) : BigInteger + { + $that = BigInteger::of($that); + + return new BigInteger(Calculator::get()->xor($this->value, $that->value)); + } + + /** + * Returns the bitwise-not of this BigInteger. + * + * @return BigInteger + */ + public function not() : BigInteger + { + return $this->negated()->minus(1); + } + + /** + * Returns the integer left shifted by a given number of bits. + * + * @param int $distance The distance to shift. + * + * @return BigInteger + */ + public function shiftedLeft(int $distance) : BigInteger + { + if ($distance === 0) { + return $this; + } + + if ($distance < 0) { + return $this->shiftedRight(- $distance); + } + + return $this->multipliedBy(BigInteger::of(2)->power($distance)); + } + + /** + * Returns the integer right shifted by a given number of bits. + * + * @param int $distance The distance to shift. + * + * @return BigInteger + */ + public function shiftedRight(int $distance) : BigInteger + { + if ($distance === 0) { + return $this; + } + + if ($distance < 0) { + return $this->shiftedLeft(- $distance); + } + + $operand = BigInteger::of(2)->power($distance); + + if ($this->isPositiveOrZero()) { + return $this->quotient($operand); + } + + return $this->dividedBy($operand, RoundingMode::UP); + } + + /** + * Returns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit. + * + * For positive BigIntegers, this is equivalent to the number of bits in the ordinary binary representation. + * Computes (ceil(log2(this < 0 ? -this : this+1))). + * + * @return int + */ + public function getBitLength() : int + { + if ($this->value === '0') { + return 0; + } + + if ($this->isNegative()) { + return $this->abs()->minus(1)->getBitLength(); + } + + return \strlen($this->toBase(2)); + } + + /** + * Returns the index of the rightmost (lowest-order) one bit in this BigInteger. + * + * Returns -1 if this BigInteger contains no one bits. + * + * @return int + */ + public function getLowestSetBit() : int + { + $n = $this; + $bitLength = $this->getBitLength(); + + for ($i = 0; $i <= $bitLength; $i++) { + if ($n->isOdd()) { + return $i; + } + + $n = $n->shiftedRight(1); + } + + return -1; + } + + /** + * Returns whether this number is even. + * + * @return bool + */ + public function isEven() : bool + { + return \in_array($this->value[-1], ['0', '2', '4', '6', '8'], true); + } + + /** + * Returns whether this number is odd. + * + * @return bool + */ + public function isOdd() : bool + { + return \in_array($this->value[-1], ['1', '3', '5', '7', '9'], true); + } + + /** + * Returns true if and only if the designated bit is set. + * + * Computes ((this & (1<shiftedRight($n)->isOdd(); + } + + /** + * {@inheritdoc} + */ + public function compareTo($that) : int + { + $that = BigNumber::of($that); + + if ($that instanceof BigInteger) { + return Calculator::get()->cmp($this->value, $that->value); + } + + return - $that->compareTo($this); + } + + /** + * {@inheritdoc} + */ + public function getSign() : int + { + return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1); + } + + /** + * {@inheritdoc} + */ + public function toBigInteger() : BigInteger + { + return $this; + } + + /** + * {@inheritdoc} + */ + public function toBigDecimal() : BigDecimal + { + return BigDecimal::create($this->value); + } + + /** + * {@inheritdoc} + */ + public function toBigRational() : BigRational + { + return BigRational::create($this, BigInteger::one(), false); + } + + /** + * {@inheritdoc} + */ + public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal + { + return $this->toBigDecimal()->toScale($scale, $roundingMode); + } + + /** + * {@inheritdoc} + */ + public function toInt() : int + { + $intValue = (int) $this->value; + + if ($this->value !== (string) $intValue) { + throw IntegerOverflowException::toIntOverflow($this); + } + + return $intValue; + } + + /** + * {@inheritdoc} + */ + public function toFloat() : float + { + return (float) $this->value; + } + + /** + * Returns a string representation of this number in the given base. + * + * The output will always be lowercase for bases greater than 10. + * + * @param int $base + * + * @return string + * + * @throws \InvalidArgumentException If the base is out of range. + */ + public function toBase(int $base) : string + { + if ($base === 10) { + return $this->value; + } + + if ($base < 2 || $base > 36) { + throw new \InvalidArgumentException(\sprintf('Base %d is out of range [2, 36]', $base)); + } + + return Calculator::get()->toBase($this->value, $base); + } + + /** + * Returns a string representation of this number in an arbitrary base with a custom alphabet. + * + * Because this method accepts an alphabet with any character, including dash, it does not handle negative numbers; + * a NegativeNumberException will be thrown when attempting to call this method on a negative number. + * + * @param string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8. + * + * @return string + * + * @throws NegativeNumberException If this number is negative. + * @throws \InvalidArgumentException If the given alphabet does not contain at least 2 chars. + */ + public function toArbitraryBase(string $alphabet) : string + { + $base = \strlen($alphabet); + + if ($base < 2) { + throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.'); + } + + if ($this->value[0] === '-') { + throw new NegativeNumberException(__FUNCTION__ . '() does not support negative numbers.'); + } + + return Calculator::get()->toArbitraryBase($this->value, $alphabet, $base); + } + + /** + * Returns a string of bytes containing the binary representation of this BigInteger. + * + * The string is in big-endian byte-order: the most significant byte is in the zeroth element. + * + * If `$signed` is true, the output will be in two's-complement representation, and a sign bit will be prepended to + * the output. If `$signed` is false, no sign bit will be prepended, and this method will throw an exception if the + * number is negative. + * + * The string will contain the minimum number of bytes required to represent this BigInteger, including a sign bit + * if `$signed` is true. + * + * This representation is compatible with the `fromBytes()` factory method, as long as the `$signed` flags match. + * + * @param bool $signed Whether to output a signed number in two's-complement representation with a leading sign bit. + * + * @return string + * + * @throws NegativeNumberException If $signed is false, and the number is negative. + */ + public function toBytes(bool $signed = true) : string + { + if (! $signed && $this->isNegative()) { + throw new NegativeNumberException('Cannot convert a negative number to a byte string when $signed is false.'); + } + + $hex = $this->abs()->toBase(16); + + if (\strlen($hex) % 2 !== 0) { + $hex = '0' . $hex; + } + + $baseHexLength = \strlen($hex); + + if ($signed) { + if ($this->isNegative()) { + $bin = \hex2bin($hex); + assert($bin !== false); + + $hex = \bin2hex(~$bin); + $hex = self::fromBase($hex, 16)->plus(1)->toBase(16); + + $hexLength = \strlen($hex); + + if ($hexLength < $baseHexLength) { + $hex = \str_repeat('0', $baseHexLength - $hexLength) . $hex; + } + + if ($hex[0] < '8') { + $hex = 'FF' . $hex; + } + } else { + if ($hex[0] >= '8') { + $hex = '00' . $hex; + } + } + } + + return \hex2bin($hex); + } + + /** + * {@inheritdoc} + */ + public function __toString() : string + { + return $this->value; + } + + /** + * This method is required for serializing the object and SHOULD NOT be accessed directly. + * + * @internal + * + * @return array{value: string} + */ + public function __serialize(): array + { + return ['value' => $this->value]; + } + + /** + * This method is only here to allow unserializing the object and cannot be accessed directly. + * + * @internal + * @psalm-suppress RedundantPropertyInitializationCheck + * + * @param array{value: string} $data + * + * @return void + * + * @throws \LogicException + */ + public function __unserialize(array $data): void + { + if (isset($this->value)) { + throw new \LogicException('__unserialize() is an internal function, it must not be called directly.'); + } + + $this->value = $data['value']; + } + + /** + * This method is required by interface Serializable and SHOULD NOT be accessed directly. + * + * @internal + * + * @return string + */ + public function serialize() : string + { + return $this->value; + } + + /** + * This method is only here to implement interface Serializable and cannot be accessed directly. + * + * @internal + * @psalm-suppress RedundantPropertyInitializationCheck + * + * @param string $value + * + * @return void + * + * @throws \LogicException + */ + public function unserialize($value) : void + { + if (isset($this->value)) { + throw new \LogicException('unserialize() is an internal function, it must not be called directly.'); + } + + $this->value = $value; + } +} diff --git a/vendor/brick/math/src/BigNumber.php b/vendor/brick/math/src/BigNumber.php new file mode 100644 index 0000000..38c8c55 --- /dev/null +++ b/vendor/brick/math/src/BigNumber.php @@ -0,0 +1,572 @@ +[\-\+])?' . + '(?:' . + '(?:' . + '(?[0-9]+)?' . + '(?\.)?' . + '(?[0-9]+)?' . + '(?:[eE](?[\-\+]?[0-9]+))?' . + ')|(?:' . + '(?[0-9]+)' . + '\/?' . + '(?[0-9]+)' . + ')' . + ')' . + '$/'; + + /** + * Creates a BigNumber of the given value. + * + * The concrete return type is dependent on the given value, with the following rules: + * + * - BigNumber instances are returned as is + * - integer numbers are returned as BigInteger + * - floating point numbers are converted to a string then parsed as such + * - strings containing a `/` character are returned as BigRational + * - strings containing a `.` character or using an exponential notation are returned as BigDecimal + * - strings containing only digits with an optional leading `+` or `-` sign are returned as BigInteger + * + * @param BigNumber|int|float|string $value + * + * @return BigNumber + * + * @throws NumberFormatException If the format of the number is not valid. + * @throws DivisionByZeroException If the value represents a rational number with a denominator of zero. + * + * @psalm-pure + */ + public static function of($value) : BigNumber + { + if ($value instanceof BigNumber) { + return $value; + } + + if (\is_int($value)) { + return new BigInteger((string) $value); + } + + /** @psalm-suppress RedundantCastGivenDocblockType We cannot trust the untyped $value here! */ + $value = \is_float($value) ? self::floatToString($value) : (string) $value; + + $throw = static function() use ($value) : void { + throw new NumberFormatException(\sprintf( + 'The given value "%s" does not represent a valid number.', + $value + )); + }; + + if (\preg_match(self::PARSE_REGEXP, $value, $matches) !== 1) { + $throw(); + } + + $getMatch = static function(string $value) use ($matches) : ?string { + return isset($matches[$value]) && $matches[$value] !== '' ? $matches[$value] : null; + }; + + $sign = $getMatch('sign'); + $numerator = $getMatch('numerator'); + $denominator = $getMatch('denominator'); + + if ($numerator !== null) { + assert($denominator !== null); + + if ($sign !== null) { + $numerator = $sign . $numerator; + } + + $numerator = self::cleanUp($numerator); + $denominator = self::cleanUp($denominator); + + if ($denominator === '0') { + throw DivisionByZeroException::denominatorMustNotBeZero(); + } + + return new BigRational( + new BigInteger($numerator), + new BigInteger($denominator), + false + ); + } + + $point = $getMatch('point'); + $integral = $getMatch('integral'); + $fractional = $getMatch('fractional'); + $exponent = $getMatch('exponent'); + + if ($integral === null && $fractional === null) { + $throw(); + } + + if ($integral === null) { + $integral = '0'; + } + + if ($point !== null || $exponent !== null) { + $fractional = ($fractional ?? ''); + $exponent = ($exponent !== null) ? (int) $exponent : 0; + + if ($exponent === PHP_INT_MIN || $exponent === PHP_INT_MAX) { + throw new NumberFormatException('Exponent too large.'); + } + + $unscaledValue = self::cleanUp(($sign ?? ''). $integral . $fractional); + + $scale = \strlen($fractional) - $exponent; + + if ($scale < 0) { + if ($unscaledValue !== '0') { + $unscaledValue .= \str_repeat('0', - $scale); + } + $scale = 0; + } + + return new BigDecimal($unscaledValue, $scale); + } + + $integral = self::cleanUp(($sign ?? '') . $integral); + + return new BigInteger($integral); + } + + /** + * Safely converts float to string, avoiding locale-dependent issues. + * + * @see https://github.com/brick/math/pull/20 + * + * @param float $float + * + * @return string + * + * @psalm-pure + * @psalm-suppress ImpureFunctionCall + */ + private static function floatToString(float $float) : string + { + $currentLocale = \setlocale(LC_NUMERIC, '0'); + \setlocale(LC_NUMERIC, 'C'); + + $result = (string) $float; + + \setlocale(LC_NUMERIC, $currentLocale); + + return $result; + } + + /** + * Proxy method to access protected constructors from sibling classes. + * + * @internal + * + * @param mixed ...$args The arguments to the constructor. + * + * @return static + * + * @psalm-pure + * @psalm-suppress TooManyArguments + * @psalm-suppress UnsafeInstantiation + */ + protected static function create(... $args) : BigNumber + { + return new static(... $args); + } + + /** + * Returns the minimum of the given values. + * + * @param BigNumber|int|float|string ...$values The numbers to compare. All the numbers need to be convertible + * to an instance of the class this method is called on. + * + * @return static The minimum value. + * + * @throws \InvalidArgumentException If no values are given. + * @throws MathException If an argument is not valid. + * + * @psalm-suppress LessSpecificReturnStatement + * @psalm-suppress MoreSpecificReturnType + * @psalm-pure + */ + public static function min(...$values) : BigNumber + { + $min = null; + + foreach ($values as $value) { + $value = static::of($value); + + if ($min === null || $value->isLessThan($min)) { + $min = $value; + } + } + + if ($min === null) { + throw new \InvalidArgumentException(__METHOD__ . '() expects at least one value.'); + } + + return $min; + } + + /** + * Returns the maximum of the given values. + * + * @param BigNumber|int|float|string ...$values The numbers to compare. All the numbers need to be convertible + * to an instance of the class this method is called on. + * + * @return static The maximum value. + * + * @throws \InvalidArgumentException If no values are given. + * @throws MathException If an argument is not valid. + * + * @psalm-suppress LessSpecificReturnStatement + * @psalm-suppress MoreSpecificReturnType + * @psalm-pure + */ + public static function max(...$values) : BigNumber + { + $max = null; + + foreach ($values as $value) { + $value = static::of($value); + + if ($max === null || $value->isGreaterThan($max)) { + $max = $value; + } + } + + if ($max === null) { + throw new \InvalidArgumentException(__METHOD__ . '() expects at least one value.'); + } + + return $max; + } + + /** + * Returns the sum of the given values. + * + * @param BigNumber|int|float|string ...$values The numbers to add. All the numbers need to be convertible + * to an instance of the class this method is called on. + * + * @return static The sum. + * + * @throws \InvalidArgumentException If no values are given. + * @throws MathException If an argument is not valid. + * + * @psalm-suppress LessSpecificReturnStatement + * @psalm-suppress MoreSpecificReturnType + * @psalm-pure + */ + public static function sum(...$values) : BigNumber + { + /** @var BigNumber|null $sum */ + $sum = null; + + foreach ($values as $value) { + $value = static::of($value); + + $sum = $sum === null ? $value : self::add($sum, $value); + } + + if ($sum === null) { + throw new \InvalidArgumentException(__METHOD__ . '() expects at least one value.'); + } + + return $sum; + } + + /** + * Adds two BigNumber instances in the correct order to avoid a RoundingNecessaryException. + * + * @todo This could be better resolved by creating an abstract protected method in BigNumber, and leaving to + * concrete classes the responsibility to perform the addition themselves or delegate it to the given number, + * depending on their ability to perform the operation. This will also require a version bump because we're + * potentially breaking custom BigNumber implementations (if any...) + * + * @param BigNumber $a + * @param BigNumber $b + * + * @return BigNumber + * + * @psalm-pure + */ + private static function add(BigNumber $a, BigNumber $b) : BigNumber + { + if ($a instanceof BigRational) { + return $a->plus($b); + } + + if ($b instanceof BigRational) { + return $b->plus($a); + } + + if ($a instanceof BigDecimal) { + return $a->plus($b); + } + + if ($b instanceof BigDecimal) { + return $b->plus($a); + } + + /** @var BigInteger $a */ + + return $a->plus($b); + } + + /** + * Removes optional leading zeros and + sign from the given number. + * + * @param string $number The number, validated as a non-empty string of digits with optional leading sign. + * + * @return string + * + * @psalm-pure + */ + private static function cleanUp(string $number) : string + { + $firstChar = $number[0]; + + if ($firstChar === '+' || $firstChar === '-') { + $number = \substr($number, 1); + } + + $number = \ltrim($number, '0'); + + if ($number === '') { + return '0'; + } + + if ($firstChar === '-') { + return '-' . $number; + } + + return $number; + } + + /** + * Checks if this number is equal to the given one. + * + * @param BigNumber|int|float|string $that + * + * @return bool + */ + public function isEqualTo($that) : bool + { + return $this->compareTo($that) === 0; + } + + /** + * Checks if this number is strictly lower than the given one. + * + * @param BigNumber|int|float|string $that + * + * @return bool + */ + public function isLessThan($that) : bool + { + return $this->compareTo($that) < 0; + } + + /** + * Checks if this number is lower than or equal to the given one. + * + * @param BigNumber|int|float|string $that + * + * @return bool + */ + public function isLessThanOrEqualTo($that) : bool + { + return $this->compareTo($that) <= 0; + } + + /** + * Checks if this number is strictly greater than the given one. + * + * @param BigNumber|int|float|string $that + * + * @return bool + */ + public function isGreaterThan($that) : bool + { + return $this->compareTo($that) > 0; + } + + /** + * Checks if this number is greater than or equal to the given one. + * + * @param BigNumber|int|float|string $that + * + * @return bool + */ + public function isGreaterThanOrEqualTo($that) : bool + { + return $this->compareTo($that) >= 0; + } + + /** + * Checks if this number equals zero. + * + * @return bool + */ + public function isZero() : bool + { + return $this->getSign() === 0; + } + + /** + * Checks if this number is strictly negative. + * + * @return bool + */ + public function isNegative() : bool + { + return $this->getSign() < 0; + } + + /** + * Checks if this number is negative or zero. + * + * @return bool + */ + public function isNegativeOrZero() : bool + { + return $this->getSign() <= 0; + } + + /** + * Checks if this number is strictly positive. + * + * @return bool + */ + public function isPositive() : bool + { + return $this->getSign() > 0; + } + + /** + * Checks if this number is positive or zero. + * + * @return bool + */ + public function isPositiveOrZero() : bool + { + return $this->getSign() >= 0; + } + + /** + * Returns the sign of this number. + * + * @return int -1 if the number is negative, 0 if zero, 1 if positive. + */ + abstract public function getSign() : int; + + /** + * Compares this number to the given one. + * + * @param BigNumber|int|float|string $that + * + * @return int [-1,0,1] If `$this` is lower than, equal to, or greater than `$that`. + * + * @throws MathException If the number is not valid. + */ + abstract public function compareTo($that) : int; + + /** + * Converts this number to a BigInteger. + * + * @return BigInteger The converted number. + * + * @throws RoundingNecessaryException If this number cannot be converted to a BigInteger without rounding. + */ + abstract public function toBigInteger() : BigInteger; + + /** + * Converts this number to a BigDecimal. + * + * @return BigDecimal The converted number. + * + * @throws RoundingNecessaryException If this number cannot be converted to a BigDecimal without rounding. + */ + abstract public function toBigDecimal() : BigDecimal; + + /** + * Converts this number to a BigRational. + * + * @return BigRational The converted number. + */ + abstract public function toBigRational() : BigRational; + + /** + * Converts this number to a BigDecimal with the given scale, using rounding if necessary. + * + * @param int $scale The scale of the resulting `BigDecimal`. + * @param int $roundingMode A `RoundingMode` constant. + * + * @return BigDecimal + * + * @throws RoundingNecessaryException If this number cannot be converted to the given scale without rounding. + * This only applies when RoundingMode::UNNECESSARY is used. + */ + abstract public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal; + + /** + * Returns the exact value of this number as a native integer. + * + * If this number cannot be converted to a native integer without losing precision, an exception is thrown. + * Note that the acceptable range for an integer depends on the platform and differs for 32-bit and 64-bit. + * + * @return int The converted value. + * + * @throws MathException If this number cannot be exactly converted to a native integer. + */ + abstract public function toInt() : int; + + /** + * Returns an approximation of this number as a floating-point value. + * + * Note that this method can discard information as the precision of a floating-point value + * is inherently limited. + * + * If the number is greater than the largest representable floating point number, positive infinity is returned. + * If the number is less than the smallest representable floating point number, negative infinity is returned. + * + * @return float The converted value. + */ + abstract public function toFloat() : float; + + /** + * Returns a string representation of this number. + * + * The output of this method can be parsed by the `of()` factory method; + * this will yield an object equal to this one, without any information loss. + * + * @return string + */ + abstract public function __toString() : string; + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : string + { + return $this->__toString(); + } +} diff --git a/vendor/brick/math/src/BigRational.php b/vendor/brick/math/src/BigRational.php new file mode 100644 index 0000000..bee094f --- /dev/null +++ b/vendor/brick/math/src/BigRational.php @@ -0,0 +1,523 @@ +isZero()) { + throw DivisionByZeroException::denominatorMustNotBeZero(); + } + + if ($denominator->isNegative()) { + $numerator = $numerator->negated(); + $denominator = $denominator->negated(); + } + } + + $this->numerator = $numerator; + $this->denominator = $denominator; + } + + /** + * Creates a BigRational of the given value. + * + * @param BigNumber|int|float|string $value + * + * @return BigRational + * + * @throws MathException If the value cannot be converted to a BigRational. + * + * @psalm-pure + */ + public static function of($value) : BigNumber + { + return parent::of($value)->toBigRational(); + } + + /** + * Creates a BigRational out of a numerator and a denominator. + * + * If the denominator is negative, the signs of both the numerator and the denominator + * will be inverted to ensure that the denominator is always positive. + * + * @param BigNumber|int|float|string $numerator The numerator. Must be convertible to a BigInteger. + * @param BigNumber|int|float|string $denominator The denominator. Must be convertible to a BigInteger. + * + * @return BigRational + * + * @throws NumberFormatException If an argument does not represent a valid number. + * @throws RoundingNecessaryException If an argument represents a non-integer number. + * @throws DivisionByZeroException If the denominator is zero. + * + * @psalm-pure + */ + public static function nd($numerator, $denominator) : BigRational + { + $numerator = BigInteger::of($numerator); + $denominator = BigInteger::of($denominator); + + return new BigRational($numerator, $denominator, true); + } + + /** + * Returns a BigRational representing zero. + * + * @return BigRational + * + * @psalm-pure + */ + public static function zero() : BigRational + { + /** + * @psalm-suppress ImpureStaticVariable + * @var BigRational|null $zero + */ + static $zero; + + if ($zero === null) { + $zero = new BigRational(BigInteger::zero(), BigInteger::one(), false); + } + + return $zero; + } + + /** + * Returns a BigRational representing one. + * + * @return BigRational + * + * @psalm-pure + */ + public static function one() : BigRational + { + /** + * @psalm-suppress ImpureStaticVariable + * @var BigRational|null $one + */ + static $one; + + if ($one === null) { + $one = new BigRational(BigInteger::one(), BigInteger::one(), false); + } + + return $one; + } + + /** + * Returns a BigRational representing ten. + * + * @return BigRational + * + * @psalm-pure + */ + public static function ten() : BigRational + { + /** + * @psalm-suppress ImpureStaticVariable + * @var BigRational|null $ten + */ + static $ten; + + if ($ten === null) { + $ten = new BigRational(BigInteger::ten(), BigInteger::one(), false); + } + + return $ten; + } + + /** + * @return BigInteger + */ + public function getNumerator() : BigInteger + { + return $this->numerator; + } + + /** + * @return BigInteger + */ + public function getDenominator() : BigInteger + { + return $this->denominator; + } + + /** + * Returns the quotient of the division of the numerator by the denominator. + * + * @return BigInteger + */ + public function quotient() : BigInteger + { + return $this->numerator->quotient($this->denominator); + } + + /** + * Returns the remainder of the division of the numerator by the denominator. + * + * @return BigInteger + */ + public function remainder() : BigInteger + { + return $this->numerator->remainder($this->denominator); + } + + /** + * Returns the quotient and remainder of the division of the numerator by the denominator. + * + * @return BigInteger[] + */ + public function quotientAndRemainder() : array + { + return $this->numerator->quotientAndRemainder($this->denominator); + } + + /** + * Returns the sum of this number and the given one. + * + * @param BigNumber|int|float|string $that The number to add. + * + * @return BigRational The result. + * + * @throws MathException If the number is not valid. + */ + public function plus($that) : BigRational + { + $that = BigRational::of($that); + + $numerator = $this->numerator->multipliedBy($that->denominator); + $numerator = $numerator->plus($that->numerator->multipliedBy($this->denominator)); + $denominator = $this->denominator->multipliedBy($that->denominator); + + return new BigRational($numerator, $denominator, false); + } + + /** + * Returns the difference of this number and the given one. + * + * @param BigNumber|int|float|string $that The number to subtract. + * + * @return BigRational The result. + * + * @throws MathException If the number is not valid. + */ + public function minus($that) : BigRational + { + $that = BigRational::of($that); + + $numerator = $this->numerator->multipliedBy($that->denominator); + $numerator = $numerator->minus($that->numerator->multipliedBy($this->denominator)); + $denominator = $this->denominator->multipliedBy($that->denominator); + + return new BigRational($numerator, $denominator, false); + } + + /** + * Returns the product of this number and the given one. + * + * @param BigNumber|int|float|string $that The multiplier. + * + * @return BigRational The result. + * + * @throws MathException If the multiplier is not a valid number. + */ + public function multipliedBy($that) : BigRational + { + $that = BigRational::of($that); + + $numerator = $this->numerator->multipliedBy($that->numerator); + $denominator = $this->denominator->multipliedBy($that->denominator); + + return new BigRational($numerator, $denominator, false); + } + + /** + * Returns the result of the division of this number by the given one. + * + * @param BigNumber|int|float|string $that The divisor. + * + * @return BigRational The result. + * + * @throws MathException If the divisor is not a valid number, or is zero. + */ + public function dividedBy($that) : BigRational + { + $that = BigRational::of($that); + + $numerator = $this->numerator->multipliedBy($that->denominator); + $denominator = $this->denominator->multipliedBy($that->numerator); + + return new BigRational($numerator, $denominator, true); + } + + /** + * Returns this number exponentiated to the given value. + * + * @param int $exponent The exponent. + * + * @return BigRational The result. + * + * @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000. + */ + public function power(int $exponent) : BigRational + { + if ($exponent === 0) { + $one = BigInteger::one(); + + return new BigRational($one, $one, false); + } + + if ($exponent === 1) { + return $this; + } + + return new BigRational( + $this->numerator->power($exponent), + $this->denominator->power($exponent), + false + ); + } + + /** + * Returns the reciprocal of this BigRational. + * + * The reciprocal has the numerator and denominator swapped. + * + * @return BigRational + * + * @throws DivisionByZeroException If the numerator is zero. + */ + public function reciprocal() : BigRational + { + return new BigRational($this->denominator, $this->numerator, true); + } + + /** + * Returns the absolute value of this BigRational. + * + * @return BigRational + */ + public function abs() : BigRational + { + return new BigRational($this->numerator->abs(), $this->denominator, false); + } + + /** + * Returns the negated value of this BigRational. + * + * @return BigRational + */ + public function negated() : BigRational + { + return new BigRational($this->numerator->negated(), $this->denominator, false); + } + + /** + * Returns the simplified value of this BigRational. + * + * @return BigRational + */ + public function simplified() : BigRational + { + $gcd = $this->numerator->gcd($this->denominator); + + $numerator = $this->numerator->quotient($gcd); + $denominator = $this->denominator->quotient($gcd); + + return new BigRational($numerator, $denominator, false); + } + + /** + * {@inheritdoc} + */ + public function compareTo($that) : int + { + return $this->minus($that)->getSign(); + } + + /** + * {@inheritdoc} + */ + public function getSign() : int + { + return $this->numerator->getSign(); + } + + /** + * {@inheritdoc} + */ + public function toBigInteger() : BigInteger + { + $simplified = $this->simplified(); + + if (! $simplified->denominator->isEqualTo(1)) { + throw new RoundingNecessaryException('This rational number cannot be represented as an integer value without rounding.'); + } + + return $simplified->numerator; + } + + /** + * {@inheritdoc} + */ + public function toBigDecimal() : BigDecimal + { + return $this->numerator->toBigDecimal()->exactlyDividedBy($this->denominator); + } + + /** + * {@inheritdoc} + */ + public function toBigRational() : BigRational + { + return $this; + } + + /** + * {@inheritdoc} + */ + public function toScale(int $scale, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal + { + return $this->numerator->toBigDecimal()->dividedBy($this->denominator, $scale, $roundingMode); + } + + /** + * {@inheritdoc} + */ + public function toInt() : int + { + return $this->toBigInteger()->toInt(); + } + + /** + * {@inheritdoc} + */ + public function toFloat() : float + { + return $this->numerator->toFloat() / $this->denominator->toFloat(); + } + + /** + * {@inheritdoc} + */ + public function __toString() : string + { + $numerator = (string) $this->numerator; + $denominator = (string) $this->denominator; + + if ($denominator === '1') { + return $numerator; + } + + return $this->numerator . '/' . $this->denominator; + } + + /** + * This method is required for serializing the object and SHOULD NOT be accessed directly. + * + * @internal + * + * @return array{numerator: BigInteger, denominator: BigInteger} + */ + public function __serialize(): array + { + return ['numerator' => $this->numerator, 'denominator' => $this->denominator]; + } + + /** + * This method is only here to allow unserializing the object and cannot be accessed directly. + * + * @internal + * @psalm-suppress RedundantPropertyInitializationCheck + * + * @param array{numerator: BigInteger, denominator: BigInteger} $data + * + * @return void + * + * @throws \LogicException + */ + public function __unserialize(array $data): void + { + if (isset($this->numerator)) { + throw new \LogicException('__unserialize() is an internal function, it must not be called directly.'); + } + + $this->numerator = $data['numerator']; + $this->denominator = $data['denominator']; + } + + /** + * This method is required by interface Serializable and SHOULD NOT be accessed directly. + * + * @internal + * + * @return string + */ + public function serialize() : string + { + return $this->numerator . '/' . $this->denominator; + } + + /** + * This method is only here to implement interface Serializable and cannot be accessed directly. + * + * @internal + * @psalm-suppress RedundantPropertyInitializationCheck + * + * @param string $value + * + * @return void + * + * @throws \LogicException + */ + public function unserialize($value) : void + { + if (isset($this->numerator)) { + throw new \LogicException('unserialize() is an internal function, it must not be called directly.'); + } + + [$numerator, $denominator] = \explode('/', $value); + + $this->numerator = BigInteger::of($numerator); + $this->denominator = BigInteger::of($denominator); + } +} diff --git a/vendor/brick/math/src/Exception/DivisionByZeroException.php b/vendor/brick/math/src/Exception/DivisionByZeroException.php new file mode 100644 index 0000000..a4e4431 --- /dev/null +++ b/vendor/brick/math/src/Exception/DivisionByZeroException.php @@ -0,0 +1,41 @@ + 126) { + $char = \strtoupper(\dechex($ord)); + + if ($ord < 10) { + $char = '0' . $char; + } + } else { + $char = '"' . $char . '"'; + } + + return new self(sprintf('Char %s is not a valid character in the given alphabet.', $char)); + } +} diff --git a/vendor/brick/math/src/Exception/RoundingNecessaryException.php b/vendor/brick/math/src/Exception/RoundingNecessaryException.php new file mode 100644 index 0000000..1c61005 --- /dev/null +++ b/vendor/brick/math/src/Exception/RoundingNecessaryException.php @@ -0,0 +1,21 @@ +init($a, $b); + + if ($aNeg && ! $bNeg) { + return -1; + } + + if ($bNeg && ! $aNeg) { + return 1; + } + + $aLen = \strlen($aDig); + $bLen = \strlen($bDig); + + if ($aLen < $bLen) { + $result = -1; + } elseif ($aLen > $bLen) { + $result = 1; + } else { + $result = $aDig <=> $bDig; + } + + return $aNeg ? -$result : $result; + } + + /** + * Adds two numbers. + * + * @param string $a The augend. + * @param string $b The addend. + * + * @return string The sum. + */ + abstract public function add(string $a, string $b) : string; + + /** + * Subtracts two numbers. + * + * @param string $a The minuend. + * @param string $b The subtrahend. + * + * @return string The difference. + */ + abstract public function sub(string $a, string $b) : string; + + /** + * Multiplies two numbers. + * + * @param string $a The multiplicand. + * @param string $b The multiplier. + * + * @return string The product. + */ + abstract public function mul(string $a, string $b) : string; + + /** + * Returns the quotient of the division of two numbers. + * + * @param string $a The dividend. + * @param string $b The divisor, must not be zero. + * + * @return string The quotient. + */ + abstract public function divQ(string $a, string $b) : string; + + /** + * Returns the remainder of the division of two numbers. + * + * @param string $a The dividend. + * @param string $b The divisor, must not be zero. + * + * @return string The remainder. + */ + abstract public function divR(string $a, string $b) : string; + + /** + * Returns the quotient and remainder of the division of two numbers. + * + * @param string $a The dividend. + * @param string $b The divisor, must not be zero. + * + * @return string[] An array containing the quotient and remainder. + */ + abstract public function divQR(string $a, string $b) : array; + + /** + * Exponentiates a number. + * + * @param string $a The base number. + * @param int $e The exponent, validated as an integer between 0 and MAX_POWER. + * + * @return string The power. + */ + abstract public function pow(string $a, int $e) : string; + + /** + * @param string $a + * @param string $b The modulus; must not be zero. + * + * @return string + */ + public function mod(string $a, string $b) : string + { + return $this->divR($this->add($this->divR($a, $b), $b), $b); + } + + /** + * Returns the modular multiplicative inverse of $x modulo $m. + * + * If $x has no multiplicative inverse mod m, this method must return null. + * + * This method can be overridden by the concrete implementation if the underlying library has built-in support. + * + * @param string $x + * @param string $m The modulus; must not be negative or zero. + * + * @return string|null + */ + public function modInverse(string $x, string $m) : ?string + { + if ($m === '1') { + return '0'; + } + + $modVal = $x; + + if ($x[0] === '-' || ($this->cmp($this->abs($x), $m) >= 0)) { + $modVal = $this->mod($x, $m); + } + + $x = '0'; + $y = '0'; + $g = $this->gcdExtended($modVal, $m, $x, $y); + + if ($g !== '1') { + return null; + } + + return $this->mod($this->add($this->mod($x, $m), $m), $m); + } + + /** + * Raises a number into power with modulo. + * + * @param string $base The base number; must be positive or zero. + * @param string $exp The exponent; must be positive or zero. + * @param string $mod The modulus; must be strictly positive. + * + * @return string The power. + */ + abstract public function modPow(string $base, string $exp, string $mod) : string; + + /** + * Returns the greatest common divisor of the two numbers. + * + * This method can be overridden by the concrete implementation if the underlying library + * has built-in support for GCD calculations. + * + * @param string $a The first number. + * @param string $b The second number. + * + * @return string The GCD, always positive, or zero if both arguments are zero. + */ + public function gcd(string $a, string $b) : string + { + if ($a === '0') { + return $this->abs($b); + } + + if ($b === '0') { + return $this->abs($a); + } + + return $this->gcd($b, $this->divR($a, $b)); + } + + private function gcdExtended(string $a, string $b, string &$x, string &$y) : string + { + if ($a === '0') { + $x = '0'; + $y = '1'; + + return $b; + } + + $x1 = '0'; + $y1 = '0'; + + $gcd = $this->gcdExtended($this->mod($b, $a), $a, $x1, $y1); + + $x = $this->sub($y1, $this->mul($this->divQ($b, $a), $x1)); + $y = $x1; + + return $gcd; + } + + /** + * Returns the square root of the given number, rounded down. + * + * The result is the largest x such that x² ≤ n. + * The input MUST NOT be negative. + * + * @param string $n The number. + * + * @return string The square root. + */ + abstract public function sqrt(string $n) : string; + + /** + * Converts a number from an arbitrary base. + * + * This method can be overridden by the concrete implementation if the underlying library + * has built-in support for base conversion. + * + * @param string $number The number, positive or zero, non-empty, case-insensitively validated for the given base. + * @param int $base The base of the number, validated from 2 to 36. + * + * @return string The converted number, following the Calculator conventions. + */ + public function fromBase(string $number, int $base) : string + { + return $this->fromArbitraryBase(\strtolower($number), self::ALPHABET, $base); + } + + /** + * Converts a number to an arbitrary base. + * + * This method can be overridden by the concrete implementation if the underlying library + * has built-in support for base conversion. + * + * @param string $number The number to convert, following the Calculator conventions. + * @param int $base The base to convert to, validated from 2 to 36. + * + * @return string The converted number, lowercase. + */ + public function toBase(string $number, int $base) : string + { + $negative = ($number[0] === '-'); + + if ($negative) { + $number = \substr($number, 1); + } + + $number = $this->toArbitraryBase($number, self::ALPHABET, $base); + + if ($negative) { + return '-' . $number; + } + + return $number; + } + + /** + * Converts a non-negative number in an arbitrary base using a custom alphabet, to base 10. + * + * @param string $number The number to convert, validated as a non-empty string, + * containing only chars in the given alphabet/base. + * @param string $alphabet The alphabet that contains every digit, validated as 2 chars minimum. + * @param int $base The base of the number, validated from 2 to alphabet length. + * + * @return string The number in base 10, following the Calculator conventions. + */ + final public function fromArbitraryBase(string $number, string $alphabet, int $base) : string + { + // remove leading "zeros" + $number = \ltrim($number, $alphabet[0]); + + if ($number === '') { + return '0'; + } + + // optimize for "one" + if ($number === $alphabet[1]) { + return '1'; + } + + $result = '0'; + $power = '1'; + + $base = (string) $base; + + for ($i = \strlen($number) - 1; $i >= 0; $i--) { + $index = \strpos($alphabet, $number[$i]); + + if ($index !== 0) { + $result = $this->add($result, ($index === 1) + ? $power + : $this->mul($power, (string) $index) + ); + } + + if ($i !== 0) { + $power = $this->mul($power, $base); + } + } + + return $result; + } + + /** + * Converts a non-negative number to an arbitrary base using a custom alphabet. + * + * @param string $number The number to convert, positive or zero, following the Calculator conventions. + * @param string $alphabet The alphabet that contains every digit, validated as 2 chars minimum. + * @param int $base The base to convert to, validated from 2 to alphabet length. + * + * @return string The converted number in the given alphabet. + */ + final public function toArbitraryBase(string $number, string $alphabet, int $base) : string + { + if ($number === '0') { + return $alphabet[0]; + } + + $base = (string) $base; + $result = ''; + + while ($number !== '0') { + [$number, $remainder] = $this->divQR($number, $base); + $remainder = (int) $remainder; + + $result .= $alphabet[$remainder]; + } + + return \strrev($result); + } + + /** + * Performs a rounded division. + * + * Rounding is performed when the remainder of the division is not zero. + * + * @param string $a The dividend. + * @param string $b The divisor, must not be zero. + * @param int $roundingMode The rounding mode. + * + * @return string + * + * @throws \InvalidArgumentException If the rounding mode is invalid. + * @throws RoundingNecessaryException If RoundingMode::UNNECESSARY is provided but rounding is necessary. + */ + final public function divRound(string $a, string $b, int $roundingMode) : string + { + [$quotient, $remainder] = $this->divQR($a, $b); + + $hasDiscardedFraction = ($remainder !== '0'); + $isPositiveOrZero = ($a[0] === '-') === ($b[0] === '-'); + + $discardedFractionSign = function() use ($remainder, $b) : int { + $r = $this->abs($this->mul($remainder, '2')); + $b = $this->abs($b); + + return $this->cmp($r, $b); + }; + + $increment = false; + + switch ($roundingMode) { + case RoundingMode::UNNECESSARY: + if ($hasDiscardedFraction) { + throw RoundingNecessaryException::roundingNecessary(); + } + break; + + case RoundingMode::UP: + $increment = $hasDiscardedFraction; + break; + + case RoundingMode::DOWN: + break; + + case RoundingMode::CEILING: + $increment = $hasDiscardedFraction && $isPositiveOrZero; + break; + + case RoundingMode::FLOOR: + $increment = $hasDiscardedFraction && ! $isPositiveOrZero; + break; + + case RoundingMode::HALF_UP: + $increment = $discardedFractionSign() >= 0; + break; + + case RoundingMode::HALF_DOWN: + $increment = $discardedFractionSign() > 0; + break; + + case RoundingMode::HALF_CEILING: + $increment = $isPositiveOrZero ? $discardedFractionSign() >= 0 : $discardedFractionSign() > 0; + break; + + case RoundingMode::HALF_FLOOR: + $increment = $isPositiveOrZero ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0; + break; + + case RoundingMode::HALF_EVEN: + $lastDigit = (int) $quotient[-1]; + $lastDigitIsEven = ($lastDigit % 2 === 0); + $increment = $lastDigitIsEven ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0; + break; + + default: + throw new \InvalidArgumentException('Invalid rounding mode.'); + } + + if ($increment) { + return $this->add($quotient, $isPositiveOrZero ? '1' : '-1'); + } + + return $quotient; + } + + /** + * Calculates bitwise AND of two numbers. + * + * This method can be overridden by the concrete implementation if the underlying library + * has built-in support for bitwise operations. + * + * @param string $a + * @param string $b + * + * @return string + */ + public function and(string $a, string $b) : string + { + return $this->bitwise('and', $a, $b); + } + + /** + * Calculates bitwise OR of two numbers. + * + * This method can be overridden by the concrete implementation if the underlying library + * has built-in support for bitwise operations. + * + * @param string $a + * @param string $b + * + * @return string + */ + public function or(string $a, string $b) : string + { + return $this->bitwise('or', $a, $b); + } + + /** + * Calculates bitwise XOR of two numbers. + * + * This method can be overridden by the concrete implementation if the underlying library + * has built-in support for bitwise operations. + * + * @param string $a + * @param string $b + * + * @return string + */ + public function xor(string $a, string $b) : string + { + return $this->bitwise('xor', $a, $b); + } + + /** + * Performs a bitwise operation on a decimal number. + * + * @param string $operator The operator to use, must be "and", "or" or "xor". + * @param string $a The left operand. + * @param string $b The right operand. + * + * @return string + */ + private function bitwise(string $operator, string $a, string $b) : string + { + [$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b); + + $aBin = $this->toBinary($aDig); + $bBin = $this->toBinary($bDig); + + $aLen = \strlen($aBin); + $bLen = \strlen($bBin); + + if ($aLen > $bLen) { + $bBin = \str_repeat("\x00", $aLen - $bLen) . $bBin; + } elseif ($bLen > $aLen) { + $aBin = \str_repeat("\x00", $bLen - $aLen) . $aBin; + } + + if ($aNeg) { + $aBin = $this->twosComplement($aBin); + } + if ($bNeg) { + $bBin = $this->twosComplement($bBin); + } + + switch ($operator) { + case 'and': + $value = $aBin & $bBin; + $negative = ($aNeg and $bNeg); + break; + + case 'or': + $value = $aBin | $bBin; + $negative = ($aNeg or $bNeg); + break; + + case 'xor': + $value = $aBin ^ $bBin; + $negative = ($aNeg xor $bNeg); + break; + + // @codeCoverageIgnoreStart + default: + throw new \InvalidArgumentException('Invalid bitwise operator.'); + // @codeCoverageIgnoreEnd + } + + if ($negative) { + $value = $this->twosComplement($value); + } + + $result = $this->toDecimal($value); + + return $negative ? $this->neg($result) : $result; + } + + /** + * @param string $number A positive, binary number. + * + * @return string + */ + private function twosComplement(string $number) : string + { + $xor = \str_repeat("\xff", \strlen($number)); + + $number ^= $xor; + + for ($i = \strlen($number) - 1; $i >= 0; $i--) { + $byte = \ord($number[$i]); + + if (++$byte !== 256) { + $number[$i] = \chr($byte); + break; + } + + $number[$i] = "\x00"; + + if ($i === 0) { + $number = "\x01" . $number; + } + } + + return $number; + } + + /** + * Converts a decimal number to a binary string. + * + * @param string $number The number to convert, positive or zero, only digits. + * + * @return string + */ + private function toBinary(string $number) : string + { + $result = ''; + + while ($number !== '0') { + [$number, $remainder] = $this->divQR($number, '256'); + $result .= \chr((int) $remainder); + } + + return \strrev($result); + } + + /** + * Returns the positive decimal representation of a binary number. + * + * @param string $bytes The bytes representing the number. + * + * @return string + */ + private function toDecimal(string $bytes) : string + { + $result = '0'; + $power = '1'; + + for ($i = \strlen($bytes) - 1; $i >= 0; $i--) { + $index = \ord($bytes[$i]); + + if ($index !== 0) { + $result = $this->add($result, ($index === 1) + ? $power + : $this->mul($power, (string) $index) + ); + } + + if ($i !== 0) { + $power = $this->mul($power, '256'); + } + } + + return $result; + } +} diff --git a/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php b/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php new file mode 100644 index 0000000..6632b37 --- /dev/null +++ b/vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php @@ -0,0 +1,116 @@ += 0) { + return \bcmod($a, $b, 0); + } + + return \bcmod($a, $b); + } + + /** + * {@inheritdoc} + */ + public function divQR(string $a, string $b) : array + { + $q = \bcdiv($a, $b, 0); + + if (version_compare(PHP_VERSION, '7.2') >= 0) { + $r = \bcmod($a, $b, 0); + } else { + $r = \bcmod($a, $b); + } + + assert($q !== null); + assert($r !== null); + + return [$q, $r]; + } + + /** + * {@inheritdoc} + */ + public function pow(string $a, int $e) : string + { + return \bcpow($a, (string) $e, 0); + } + + /** + * {@inheritdoc} + * + * @psalm-suppress InvalidNullableReturnType + * @psalm-suppress NullableReturnStatement + */ + public function modPow(string $base, string $exp, string $mod) : string + { + return \bcpowmod($base, $exp, $mod, 0); + } + + /** + * {@inheritDoc} + * + * @psalm-suppress NullableReturnStatement + * @psalm-suppress InvalidNullableReturnType + */ + public function sqrt(string $n) : string + { + return \bcsqrt($n, 0); + } +} diff --git a/vendor/brick/math/src/Internal/Calculator/GmpCalculator.php b/vendor/brick/math/src/Internal/Calculator/GmpCalculator.php new file mode 100644 index 0000000..52d1880 --- /dev/null +++ b/vendor/brick/math/src/Internal/Calculator/GmpCalculator.php @@ -0,0 +1,156 @@ +maxDigits = 9; + break; + + case 8: + $this->maxDigits = 18; + break; + + default: + throw new \RuntimeException('The platform is not 32-bit or 64-bit as expected.'); + } + } + + /** + * {@inheritdoc} + */ + public function add(string $a, string $b) : string + { + /** + * @psalm-var numeric-string $a + * @psalm-var numeric-string $b + */ + $result = $a + $b; + + if (is_int($result)) { + return (string) $result; + } + + if ($a === '0') { + return $b; + } + + if ($b === '0') { + return $a; + } + + [$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b); + + $result = $aNeg === $bNeg ? $this->doAdd($aDig, $bDig) : $this->doSub($aDig, $bDig); + + if ($aNeg) { + $result = $this->neg($result); + } + + return $result; + } + + /** + * {@inheritdoc} + */ + public function sub(string $a, string $b) : string + { + return $this->add($a, $this->neg($b)); + } + + /** + * {@inheritdoc} + */ + public function mul(string $a, string $b) : string + { + /** + * @psalm-var numeric-string $a + * @psalm-var numeric-string $b + */ + $result = $a * $b; + + if (is_int($result)) { + return (string) $result; + } + + if ($a === '0' || $b === '0') { + return '0'; + } + + if ($a === '1') { + return $b; + } + + if ($b === '1') { + return $a; + } + + if ($a === '-1') { + return $this->neg($b); + } + + if ($b === '-1') { + return $this->neg($a); + } + + [$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b); + + $result = $this->doMul($aDig, $bDig); + + if ($aNeg !== $bNeg) { + $result = $this->neg($result); + } + + return $result; + } + + /** + * {@inheritdoc} + */ + public function divQ(string $a, string $b) : string + { + return $this->divQR($a, $b)[0]; + } + + /** + * {@inheritdoc} + */ + public function divR(string $a, string $b): string + { + return $this->divQR($a, $b)[1]; + } + + /** + * {@inheritdoc} + */ + public function divQR(string $a, string $b) : array + { + if ($a === '0') { + return ['0', '0']; + } + + if ($a === $b) { + return ['1', '0']; + } + + if ($b === '1') { + return [$a, '0']; + } + + if ($b === '-1') { + return [$this->neg($a), '0']; + } + + /** @psalm-var numeric-string $a */ + $na = $a * 1; // cast to number + + if (is_int($na)) { + /** @psalm-var numeric-string $b */ + $nb = $b * 1; + + if (is_int($nb)) { + // the only division that may overflow is PHP_INT_MIN / -1, + // which cannot happen here as we've already handled a divisor of -1 above. + $r = $na % $nb; + $q = ($na - $r) / $nb; + + assert(is_int($q)); + + return [ + (string) $q, + (string) $r + ]; + } + } + + [$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b); + + [$q, $r] = $this->doDiv($aDig, $bDig); + + if ($aNeg !== $bNeg) { + $q = $this->neg($q); + } + + if ($aNeg) { + $r = $this->neg($r); + } + + return [$q, $r]; + } + + /** + * {@inheritdoc} + */ + public function pow(string $a, int $e) : string + { + if ($e === 0) { + return '1'; + } + + if ($e === 1) { + return $a; + } + + $odd = $e % 2; + $e -= $odd; + + $aa = $this->mul($a, $a); + + /** @psalm-suppress PossiblyInvalidArgument We're sure that $e / 2 is an int now */ + $result = $this->pow($aa, $e / 2); + + if ($odd === 1) { + $result = $this->mul($result, $a); + } + + return $result; + } + + /** + * Algorithm from: https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/ + * + * {@inheritdoc} + */ + public function modPow(string $base, string $exp, string $mod) : string + { + // special case: the algorithm below fails with 0 power 0 mod 1 (returns 1 instead of 0) + if ($base === '0' && $exp === '0' && $mod === '1') { + return '0'; + } + + // special case: the algorithm below fails with power 0 mod 1 (returns 1 instead of 0) + if ($exp === '0' && $mod === '1') { + return '0'; + } + + $x = $base; + + $res = '1'; + + // numbers are positive, so we can use remainder instead of modulo + $x = $this->divR($x, $mod); + + while ($exp !== '0') { + if (in_array($exp[-1], ['1', '3', '5', '7', '9'])) { // odd + $res = $this->divR($this->mul($res, $x), $mod); + } + + $exp = $this->divQ($exp, '2'); + $x = $this->divR($this->mul($x, $x), $mod); + } + + return $res; + } + + /** + * Adapted from https://cp-algorithms.com/num_methods/roots_newton.html + * + * {@inheritDoc} + */ + public function sqrt(string $n) : string + { + if ($n === '0') { + return '0'; + } + + // initial approximation + $x = \str_repeat('9', \intdiv(\strlen($n), 2) ?: 1); + + $decreased = false; + + for (;;) { + $nx = $this->divQ($this->add($x, $this->divQ($n, $x)), '2'); + + if ($x === $nx || $this->cmp($nx, $x) > 0 && $decreased) { + break; + } + + $decreased = $this->cmp($nx, $x) < 0; + $x = $nx; + } + + return $x; + } + + /** + * Performs the addition of two non-signed large integers. + * + * @param string $a The first operand. + * @param string $b The second operand. + * + * @return string + */ + private function doAdd(string $a, string $b) : string + { + [$a, $b, $length] = $this->pad($a, $b); + + $carry = 0; + $result = ''; + + for ($i = $length - $this->maxDigits;; $i -= $this->maxDigits) { + $blockLength = $this->maxDigits; + + if ($i < 0) { + $blockLength += $i; + /** @psalm-suppress LoopInvalidation */ + $i = 0; + } + + /** @psalm-var numeric-string $blockA */ + $blockA = \substr($a, $i, $blockLength); + + /** @psalm-var numeric-string $blockB */ + $blockB = \substr($b, $i, $blockLength); + + $sum = (string) ($blockA + $blockB + $carry); + $sumLength = \strlen($sum); + + if ($sumLength > $blockLength) { + $sum = \substr($sum, 1); + $carry = 1; + } else { + if ($sumLength < $blockLength) { + $sum = \str_repeat('0', $blockLength - $sumLength) . $sum; + } + $carry = 0; + } + + $result = $sum . $result; + + if ($i === 0) { + break; + } + } + + if ($carry === 1) { + $result = '1' . $result; + } + + return $result; + } + + /** + * Performs the subtraction of two non-signed large integers. + * + * @param string $a The first operand. + * @param string $b The second operand. + * + * @return string + */ + private function doSub(string $a, string $b) : string + { + if ($a === $b) { + return '0'; + } + + // Ensure that we always subtract to a positive result: biggest minus smallest. + $cmp = $this->doCmp($a, $b); + + $invert = ($cmp === -1); + + if ($invert) { + $c = $a; + $a = $b; + $b = $c; + } + + [$a, $b, $length] = $this->pad($a, $b); + + $carry = 0; + $result = ''; + + $complement = 10 ** $this->maxDigits; + + for ($i = $length - $this->maxDigits;; $i -= $this->maxDigits) { + $blockLength = $this->maxDigits; + + if ($i < 0) { + $blockLength += $i; + /** @psalm-suppress LoopInvalidation */ + $i = 0; + } + + /** @psalm-var numeric-string $blockA */ + $blockA = \substr($a, $i, $blockLength); + + /** @psalm-var numeric-string $blockB */ + $blockB = \substr($b, $i, $blockLength); + + $sum = $blockA - $blockB - $carry; + + if ($sum < 0) { + $sum += $complement; + $carry = 1; + } else { + $carry = 0; + } + + $sum = (string) $sum; + $sumLength = \strlen($sum); + + if ($sumLength < $blockLength) { + $sum = \str_repeat('0', $blockLength - $sumLength) . $sum; + } + + $result = $sum . $result; + + if ($i === 0) { + break; + } + } + + // Carry cannot be 1 when the loop ends, as a > b + assert($carry === 0); + + $result = \ltrim($result, '0'); + + if ($invert) { + $result = $this->neg($result); + } + + return $result; + } + + /** + * Performs the multiplication of two non-signed large integers. + * + * @param string $a The first operand. + * @param string $b The second operand. + * + * @return string + */ + private function doMul(string $a, string $b) : string + { + $x = \strlen($a); + $y = \strlen($b); + + $maxDigits = \intdiv($this->maxDigits, 2); + $complement = 10 ** $maxDigits; + + $result = '0'; + + for ($i = $x - $maxDigits;; $i -= $maxDigits) { + $blockALength = $maxDigits; + + if ($i < 0) { + $blockALength += $i; + /** @psalm-suppress LoopInvalidation */ + $i = 0; + } + + $blockA = (int) \substr($a, $i, $blockALength); + + $line = ''; + $carry = 0; + + for ($j = $y - $maxDigits;; $j -= $maxDigits) { + $blockBLength = $maxDigits; + + if ($j < 0) { + $blockBLength += $j; + /** @psalm-suppress LoopInvalidation */ + $j = 0; + } + + $blockB = (int) \substr($b, $j, $blockBLength); + + $mul = $blockA * $blockB + $carry; + $value = $mul % $complement; + $carry = ($mul - $value) / $complement; + + $value = (string) $value; + $value = \str_pad($value, $maxDigits, '0', STR_PAD_LEFT); + + $line = $value . $line; + + if ($j === 0) { + break; + } + } + + if ($carry !== 0) { + $line = $carry . $line; + } + + $line = \ltrim($line, '0'); + + if ($line !== '') { + $line .= \str_repeat('0', $x - $blockALength - $i); + $result = $this->add($result, $line); + } + + if ($i === 0) { + break; + } + } + + return $result; + } + + /** + * Performs the division of two non-signed large integers. + * + * @param string $a The first operand. + * @param string $b The second operand. + * + * @return string[] The quotient and remainder. + */ + private function doDiv(string $a, string $b) : array + { + $cmp = $this->doCmp($a, $b); + + if ($cmp === -1) { + return ['0', $a]; + } + + $x = \strlen($a); + $y = \strlen($b); + + // we now know that a >= b && x >= y + + $q = '0'; // quotient + $r = $a; // remainder + $z = $y; // focus length, always $y or $y+1 + + for (;;) { + $focus = \substr($a, 0, $z); + + $cmp = $this->doCmp($focus, $b); + + if ($cmp === -1) { + if ($z === $x) { // remainder < dividend + break; + } + + $z++; + } + + $zeros = \str_repeat('0', $x - $z); + + $q = $this->add($q, '1' . $zeros); + $a = $this->sub($a, $b . $zeros); + + $r = $a; + + if ($r === '0') { // remainder == 0 + break; + } + + $x = \strlen($a); + + if ($x < $y) { // remainder < dividend + break; + } + + $z = $y; + } + + return [$q, $r]; + } + + /** + * Compares two non-signed large numbers. + * + * @param string $a The first operand. + * @param string $b The second operand. + * + * @return int [-1, 0, 1] + */ + private function doCmp(string $a, string $b) : int + { + $x = \strlen($a); + $y = \strlen($b); + + $cmp = $x <=> $y; + + if ($cmp !== 0) { + return $cmp; + } + + return \strcmp($a, $b) <=> 0; // enforce [-1, 0, 1] + } + + /** + * Pads the left of one of the given numbers with zeros if necessary to make both numbers the same length. + * + * The numbers must only consist of digits, without leading minus sign. + * + * @param string $a The first operand. + * @param string $b The second operand. + * + * @return array{string, string, int} + */ + private function pad(string $a, string $b) : array + { + $x = \strlen($a); + $y = \strlen($b); + + if ($x > $y) { + $b = \str_repeat('0', $x - $y) . $b; + + return [$a, $b, $x]; + } + + if ($x < $y) { + $a = \str_repeat('0', $y - $x) . $a; + + return [$a, $b, $y]; + } + + return [$a, $b, $x]; + } +} diff --git a/vendor/brick/math/src/RoundingMode.php b/vendor/brick/math/src/RoundingMode.php new file mode 100644 index 0000000..06936d8 --- /dev/null +++ b/vendor/brick/math/src/RoundingMode.php @@ -0,0 +1,107 @@ += 0.5; otherwise, behaves as for DOWN. + * Note that this is the rounding mode commonly taught at school. + */ + public const HALF_UP = 5; + + /** + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. + * + * Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves as for DOWN. + */ + public const HALF_DOWN = 6; + + /** + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards positive infinity. + * + * If the result is positive, behaves as for HALF_UP; if negative, behaves as for HALF_DOWN. + */ + public const HALF_CEILING = 7; + + /** + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards negative infinity. + * + * If the result is positive, behaves as for HALF_DOWN; if negative, behaves as for HALF_UP. + */ + public const HALF_FLOOR = 8; + + /** + * Rounds towards the "nearest neighbor" unless both neighbors are equidistant, in which case rounds towards the even neighbor. + * + * Behaves as for HALF_UP if the digit to the left of the discarded fraction is odd; + * behaves as for HALF_DOWN if it's even. + * + * Note that this is the rounding mode that statistically minimizes + * cumulative error when applied repeatedly over a sequence of calculations. + * It is sometimes known as "Banker's rounding", and is chiefly used in the USA. + */ + public const HALF_EVEN = 9; +} diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php index 0eac61d..59fe535 100644 --- a/vendor/composer/InstalledVersions.php +++ b/vendor/composer/InstalledVersions.php @@ -29,11 +29,20 @@ class InstalledVersions 'aliases' => array ( ), - 'reference' => '87de34fb8b0447cfce613bc057dfc18114756556', + 'reference' => '4487e6e4ab48a41306082315d421692d6034fbfc', 'name' => 'optimisthub/moka-woocommerce', ), 'versions' => array ( + 'brick/math' => + array ( + 'pretty_version' => '0.9.3', + 'version' => '0.9.3.0', + 'aliases' => + array ( + ), + 'reference' => 'ca57d18f028f84f777b2168cd1911b0dee2343ae', + ), 'optimisthub/moka-woocommerce' => array ( 'pretty_version' => 'dev-master', @@ -41,7 +50,34 @@ class InstalledVersions 'aliases' => array ( ), - 'reference' => '87de34fb8b0447cfce613bc057dfc18114756556', + 'reference' => '4487e6e4ab48a41306082315d421692d6034fbfc', + ), + 'psr/container' => + array ( + 'pretty_version' => '1.1.2', + 'version' => '1.1.2.0', + 'aliases' => + array ( + ), + 'reference' => '513e0666f7216c7459170d56df27dfcefe1689ea', + ), + 'ramsey/collection' => + array ( + 'pretty_version' => '1.2.2', + 'version' => '1.2.2.0', + 'aliases' => + array ( + ), + 'reference' => 'cccc74ee5e328031b15640b51056ee8d3bb66c0a', + ), + 'ramsey/uuid' => + array ( + 'pretty_version' => '4.2.3', + 'version' => '4.2.3.0', + 'aliases' => + array ( + ), + 'reference' => 'fc9bb7fb5388691fd7373cd44dcb4d63bbcf24df', ), 'rappasoft/laravel-helpers' => array ( @@ -52,41 +88,120 @@ class InstalledVersions ), 'reference' => '39fc647c27db358c535919cda2040e89b51344af', ), + 'rhumsaa/uuid' => + array ( + 'replaced' => + array ( + 0 => '4.2.3', + ), + ), + 'spatie/backtrace' => + array ( + 'pretty_version' => '1.2.1', + 'version' => '1.2.1.0', + 'aliases' => + array ( + ), + 'reference' => '4ee7d41aa5268107906ea8a4d9ceccde136dbd5b', + ), + 'spatie/macroable' => + array ( + 'pretty_version' => '1.0.1', + 'version' => '1.0.1.0', + 'aliases' => + array ( + ), + 'reference' => '7a99549fc001c925714b329220dea680c04bfa48', + ), + 'spatie/ray' => + array ( + 'pretty_version' => '1.33.2', + 'version' => '1.33.2.0', + 'aliases' => + array ( + ), + 'reference' => '28f6bd88e2db0fada88a7999c8ee0aad69f56192', + ), + 'symfony/deprecation-contracts' => + array ( + 'pretty_version' => 'v2.5.0', + 'version' => '2.5.0.0', + 'aliases' => + array ( + ), + 'reference' => '6f981ee24cf69ee7ce9736146d1c57c2780598a8', + ), + 'symfony/polyfill-ctype' => + array ( + 'pretty_version' => 'v1.24.0', + 'version' => '1.24.0.0', + 'aliases' => + array ( + ), + 'reference' => '30885182c981ab175d4d034db0f6f469898070ab', + ), 'symfony/polyfill-mbstring' => array ( - 'pretty_version' => 'v1.23.1', - 'version' => '1.23.1.0', + 'pretty_version' => 'v1.24.0', + 'version' => '1.24.0.0', 'aliases' => array ( ), - 'reference' => '9174a3d80210dca8daa7f31fec659150bbeabfc6', + 'reference' => '0abb51d2f102e00a4eefcf46ba7fec406d245825', ), 'symfony/polyfill-php80' => array ( - 'pretty_version' => 'v1.23.1', - 'version' => '1.23.1.0', + 'pretty_version' => 'v1.24.0', + 'version' => '1.24.0.0', + 'aliases' => + array ( + ), + 'reference' => '57b712b08eddb97c762a8caa32c84e037892d2e9', + ), + 'symfony/polyfill-php81' => + array ( + 'pretty_version' => 'v1.24.0', + 'version' => '1.24.0.0', + 'aliases' => + array ( + ), + 'reference' => '5de4ba2d41b15f9bd0e19b2ab9674135813ec98f', + ), + 'symfony/service-contracts' => + array ( + 'pretty_version' => 'v2.5.0', + 'version' => '2.5.0.0', + 'aliases' => + array ( + ), + 'reference' => '1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc', + ), + 'symfony/stopwatch' => + array ( + 'pretty_version' => 'v5.4.3', + 'version' => '5.4.3.0', 'aliases' => array ( ), - 'reference' => '1100343ed1a92e3a38f9ae122fc0eb21602547be', + 'reference' => '395220730edceb6bd745236ccb5c9125c748f779', ), 'symfony/var-dumper' => array ( - 'pretty_version' => 'v5.4.1', - 'version' => '5.4.1.0', + 'pretty_version' => 'v5.4.3', + 'version' => '5.4.3.0', 'aliases' => array ( ), - 'reference' => '2366ac8d8abe0c077844613c1a4f0c0a9f522dcc', + 'reference' => '970a01f208bf895c5f327ba40b72288da43adec4', ), 'tightenco/collect' => array ( - 'pretty_version' => 'v8.76.1', - 'version' => '8.76.1.0', + 'pretty_version' => 'v8.83.0', + 'version' => '8.83.0.0', 'aliases' => array ( ), - 'reference' => 'c7e8131653480146d4c32c2523d53e0e59a7af19', + 'reference' => 'f8053a9e26ffe0db24db02ef346c40bca920f8f8', ), ), ); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 4ebd53f..f3393d5 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -8,6 +8,7 @@ return array( 'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php', 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', + 'ReturnTypeWillChange' => $vendorDir . '/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php', 'Stringable' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Stringable.php', 'UnhandledMatchError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php', 'ValueError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/ValueError.php', diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php index b90ba02..7515674 100644 --- a/vendor/composer/autoload_files.php +++ b/vendor/composer/autoload_files.php @@ -6,13 +6,18 @@ $baseDir = dirname($vendorDir); return array( - '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', 'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', '667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php', + '23c18046f52bef3eea034657bafda50f' => $vendorDir . '/symfony/polyfill-php81/bootstrap.php', + '6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php', + '320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', + 'e39a8b23c42d4e1452234d762b03835a' => $vendorDir . '/ramsey/uuid/src/functions.php', '460404fa6d3686d7820838788517c1f9' => $vendorDir . '/rappasoft/laravel-helpers/src/arrays.php', 'c0908dd0408c67235210b4bf031d1290' => $vendorDir . '/rappasoft/laravel-helpers/src/classes.php', '728cd66d334b33c0fb1ed0fe1060a82b' => $vendorDir . '/rappasoft/laravel-helpers/src/helpers.php', 'daf45b1134c9868f305965e4c0e0f06c' => $vendorDir . '/rappasoft/laravel-helpers/src/strings.php', + '3074abeef0bacf5811f59e9dee6311d1' => $vendorDir . '/spatie/ray/src/helpers.php', 'fe62ba7e10580d903cc46d808b5961a4' => $vendorDir . '/tightenco/collect/src/Collect/Support/helpers.php', 'caf31cc6ec7cf2241cb6f12c226c3846' => $vendorDir . '/tightenco/collect/src/Collect/Support/alias.php', '87a441cc0a9becb56112f465a238f99e' => $baseDir . '/core/library/Moka_Init.php', diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index 2f76c90..35a699b 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -7,7 +7,18 @@ return array( 'Tightenco\\Collect\\' => array($vendorDir . '/tightenco/collect/src/Collect'), + 'Symfony\\Polyfill\\Php81\\' => array($vendorDir . '/symfony/polyfill-php81'), 'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), + 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), + 'Symfony\\Contracts\\Service\\' => array($vendorDir . '/symfony/service-contracts'), 'Symfony\\Component\\VarDumper\\' => array($vendorDir . '/symfony/var-dumper'), + 'Symfony\\Component\\Stopwatch\\' => array($vendorDir . '/symfony/stopwatch'), + 'Spatie\\Ray\\' => array($vendorDir . '/spatie/ray/src'), + 'Spatie\\Macroable\\' => array($vendorDir . '/spatie/macroable/src'), + 'Spatie\\Backtrace\\' => array($vendorDir . '/spatie/backtrace/src'), + 'Ramsey\\Uuid\\' => array($vendorDir . '/ramsey/uuid/src'), + 'Ramsey\\Collection\\' => array($vendorDir . '/ramsey/collection/src'), + 'Psr\\Container\\' => array($vendorDir . '/psr/container/src'), + 'Brick\\Math\\' => array($vendorDir . '/brick/math/src'), ); diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 951031a..c1c8ebe 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -7,13 +7,18 @@ class ComposerStaticInitfd623bf18bd862ee63a9bbe9992e886d { public static $files = array ( - '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', 'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', '667aeda72477189d0494fecd327c3641' => __DIR__ . '/..' . '/symfony/var-dumper/Resources/functions/dump.php', + '23c18046f52bef3eea034657bafda50f' => __DIR__ . '/..' . '/symfony/polyfill-php81/bootstrap.php', + '6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php', + '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', + 'e39a8b23c42d4e1452234d762b03835a' => __DIR__ . '/..' . '/ramsey/uuid/src/functions.php', '460404fa6d3686d7820838788517c1f9' => __DIR__ . '/..' . '/rappasoft/laravel-helpers/src/arrays.php', 'c0908dd0408c67235210b4bf031d1290' => __DIR__ . '/..' . '/rappasoft/laravel-helpers/src/classes.php', '728cd66d334b33c0fb1ed0fe1060a82b' => __DIR__ . '/..' . '/rappasoft/laravel-helpers/src/helpers.php', 'daf45b1134c9868f305965e4c0e0f06c' => __DIR__ . '/..' . '/rappasoft/laravel-helpers/src/strings.php', + '3074abeef0bacf5811f59e9dee6311d1' => __DIR__ . '/..' . '/spatie/ray/src/helpers.php', 'fe62ba7e10580d903cc46d808b5961a4' => __DIR__ . '/..' . '/tightenco/collect/src/Collect/Support/helpers.php', 'caf31cc6ec7cf2241cb6f12c226c3846' => __DIR__ . '/..' . '/tightenco/collect/src/Collect/Support/alias.php', '87a441cc0a9becb56112f465a238f99e' => __DIR__ . '/../..' . '/core/library/Moka_Init.php', @@ -31,9 +36,29 @@ class ComposerStaticInitfd623bf18bd862ee63a9bbe9992e886d ), 'S' => array ( + 'Symfony\\Polyfill\\Php81\\' => 23, 'Symfony\\Polyfill\\Php80\\' => 23, 'Symfony\\Polyfill\\Mbstring\\' => 26, + 'Symfony\\Polyfill\\Ctype\\' => 23, + 'Symfony\\Contracts\\Service\\' => 26, 'Symfony\\Component\\VarDumper\\' => 28, + 'Symfony\\Component\\Stopwatch\\' => 28, + 'Spatie\\Ray\\' => 11, + 'Spatie\\Macroable\\' => 17, + 'Spatie\\Backtrace\\' => 17, + ), + 'R' => + array ( + 'Ramsey\\Uuid\\' => 12, + 'Ramsey\\Collection\\' => 18, + ), + 'P' => + array ( + 'Psr\\Container\\' => 14, + ), + 'B' => + array ( + 'Brick\\Math\\' => 11, ), ); @@ -42,6 +67,10 @@ class ComposerStaticInitfd623bf18bd862ee63a9bbe9992e886d array ( 0 => __DIR__ . '/..' . '/tightenco/collect/src/Collect', ), + 'Symfony\\Polyfill\\Php81\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-php81', + ), 'Symfony\\Polyfill\\Php80\\' => array ( 0 => __DIR__ . '/..' . '/symfony/polyfill-php80', @@ -50,15 +79,56 @@ class ComposerStaticInitfd623bf18bd862ee63a9bbe9992e886d array ( 0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring', ), + 'Symfony\\Polyfill\\Ctype\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-ctype', + ), + 'Symfony\\Contracts\\Service\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/service-contracts', + ), 'Symfony\\Component\\VarDumper\\' => array ( 0 => __DIR__ . '/..' . '/symfony/var-dumper', ), + 'Symfony\\Component\\Stopwatch\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/stopwatch', + ), + 'Spatie\\Ray\\' => + array ( + 0 => __DIR__ . '/..' . '/spatie/ray/src', + ), + 'Spatie\\Macroable\\' => + array ( + 0 => __DIR__ . '/..' . '/spatie/macroable/src', + ), + 'Spatie\\Backtrace\\' => + array ( + 0 => __DIR__ . '/..' . '/spatie/backtrace/src', + ), + 'Ramsey\\Uuid\\' => + array ( + 0 => __DIR__ . '/..' . '/ramsey/uuid/src', + ), + 'Ramsey\\Collection\\' => + array ( + 0 => __DIR__ . '/..' . '/ramsey/collection/src', + ), + 'Psr\\Container\\' => + array ( + 0 => __DIR__ . '/..' . '/psr/container/src', + ), + 'Brick\\Math\\' => + array ( + 0 => __DIR__ . '/..' . '/brick/math/src', + ), ); public static $classMap = array ( 'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php', 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', + 'ReturnTypeWillChange' => __DIR__ . '/..' . '/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php', 'Stringable' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Stringable.php', 'UnhandledMatchError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php', 'ValueError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/ValueError.php', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index f21fc7b..77e3465 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1,32 +1,662 @@ { "packages": [ + { + "name": "brick/math", + "version": "0.9.3", + "version_normalized": "0.9.3.0", + "source": { + "type": "git", + "url": "https://github.com/brick/math.git", + "reference": "ca57d18f028f84f777b2168cd1911b0dee2343ae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/brick/math/zipball/ca57d18f028f84f777b2168cd1911b0dee2343ae", + "reference": "ca57d18f028f84f777b2168cd1911b0dee2343ae", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.2", + "phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.0", + "vimeo/psalm": "4.9.2" + }, + "time": "2021-08-15T20:50:18+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Brick\\Math\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Arbitrary-precision arithmetic library", + "keywords": [ + "Arbitrary-precision", + "BigInteger", + "BigRational", + "arithmetic", + "bigdecimal", + "bignum", + "brick", + "math" + ], + "support": { + "issues": "https://github.com/brick/math/issues", + "source": "https://github.com/brick/math/tree/0.9.3" + }, + "funding": [ + { + "url": "https://github.com/BenMorel", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/brick/math", + "type": "tidelift" + } + ], + "install-path": "../brick/math" + }, + { + "name": "psr/container", + "version": "1.1.2", + "version_normalized": "1.1.2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "time": "2021-11-05T16:50:12+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/1.1.2" + }, + "install-path": "../psr/container" + }, + { + "name": "ramsey/collection", + "version": "1.2.2", + "version_normalized": "1.2.2.0", + "source": { + "type": "git", + "url": "https://github.com/ramsey/collection.git", + "reference": "cccc74ee5e328031b15640b51056ee8d3bb66c0a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ramsey/collection/zipball/cccc74ee5e328031b15640b51056ee8d3bb66c0a", + "reference": "cccc74ee5e328031b15640b51056ee8d3bb66c0a", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8", + "symfony/polyfill-php81": "^1.23" + }, + "require-dev": { + "captainhook/captainhook": "^5.3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", + "ergebnis/composer-normalize": "^2.6", + "fakerphp/faker": "^1.5", + "hamcrest/hamcrest-php": "^2", + "jangregor/phpstan-prophecy": "^0.8", + "mockery/mockery": "^1.3", + "phpspec/prophecy-phpunit": "^2.0", + "phpstan/extension-installer": "^1", + "phpstan/phpstan": "^0.12.32", + "phpstan/phpstan-mockery": "^0.12.5", + "phpstan/phpstan-phpunit": "^0.12.11", + "phpunit/phpunit": "^8.5 || ^9", + "psy/psysh": "^0.10.4", + "slevomat/coding-standard": "^6.3", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.4" + }, + "time": "2021-10-10T03:01:02+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Ramsey\\Collection\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ben Ramsey", + "email": "ben@benramsey.com", + "homepage": "https://benramsey.com" + } + ], + "description": "A PHP library for representing and manipulating collections.", + "keywords": [ + "array", + "collection", + "hash", + "map", + "queue", + "set" + ], + "support": { + "issues": "https://github.com/ramsey/collection/issues", + "source": "https://github.com/ramsey/collection/tree/1.2.2" + }, + "funding": [ + { + "url": "https://github.com/ramsey", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/ramsey/collection", + "type": "tidelift" + } + ], + "install-path": "../ramsey/collection" + }, + { + "name": "ramsey/uuid", + "version": "4.2.3", + "version_normalized": "4.2.3.0", + "source": { + "type": "git", + "url": "https://github.com/ramsey/uuid.git", + "reference": "fc9bb7fb5388691fd7373cd44dcb4d63bbcf24df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/fc9bb7fb5388691fd7373cd44dcb4d63bbcf24df", + "reference": "fc9bb7fb5388691fd7373cd44dcb4d63bbcf24df", + "shasum": "" + }, + "require": { + "brick/math": "^0.8 || ^0.9", + "ext-json": "*", + "php": "^7.2 || ^8.0", + "ramsey/collection": "^1.0", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-php80": "^1.14" + }, + "replace": { + "rhumsaa/uuid": "self.version" + }, + "require-dev": { + "captainhook/captainhook": "^5.10", + "captainhook/plugin-composer": "^5.3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", + "doctrine/annotations": "^1.8", + "ergebnis/composer-normalize": "^2.15", + "mockery/mockery": "^1.3", + "moontoast/math": "^1.1", + "paragonie/random-lib": "^2", + "php-mock/php-mock": "^2.2", + "php-mock/php-mock-mockery": "^1.3", + "php-parallel-lint/php-parallel-lint": "^1.1", + "phpbench/phpbench": "^1.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-mockery": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^8.5 || ^9", + "slevomat/coding-standard": "^7.0", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.9" + }, + "suggest": { + "ext-bcmath": "Enables faster math with arbitrary-precision integers using BCMath.", + "ext-ctype": "Enables faster processing of character classification using ctype functions.", + "ext-gmp": "Enables faster math with arbitrary-precision integers using GMP.", + "ext-uuid": "Enables the use of PeclUuidTimeGenerator and PeclUuidRandomGenerator.", + "paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter", + "ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type." + }, + "time": "2021-09-25T23:10:38+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.x-dev" + }, + "captainhook": { + "force-install": true + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Ramsey\\Uuid\\": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A PHP library for generating and working with universally unique identifiers (UUIDs).", + "keywords": [ + "guid", + "identifier", + "uuid" + ], + "support": { + "issues": "https://github.com/ramsey/uuid/issues", + "source": "https://github.com/ramsey/uuid/tree/4.2.3" + }, + "funding": [ + { + "url": "https://github.com/ramsey", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/ramsey/uuid", + "type": "tidelift" + } + ], + "install-path": "../ramsey/uuid" + }, { "name": "rappasoft/laravel-helpers", "version": "v2.0.0", "version_normalized": "2.0.0.0", "source": { "type": "git", - "url": "https://github.com/rappasoft/laravel-helpers.git", - "reference": "39fc647c27db358c535919cda2040e89b51344af" + "url": "https://github.com/rappasoft/laravel-helpers.git", + "reference": "39fc647c27db358c535919cda2040e89b51344af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rappasoft/laravel-helpers/zipball/39fc647c27db358c535919cda2040e89b51344af", + "reference": "39fc647c27db358c535919cda2040e89b51344af", + "shasum": "" + }, + "require": { + "php": "^7.3|^8.0" + }, + "time": "2021-10-01T18:00:53+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "files": [ + "src/arrays.php", + "src/classes.php", + "src/helpers.php", + "src/strings.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anthony Rappa", + "email": "rappa819@gmail.com" + } + ], + "description": "Laravel Helpers for Non-Laravel Projects", + "keywords": [ + "String helpers", + "array helpers", + "helpers", + "laravel" + ], + "support": { + "issues": "https://github.com/rappasoft/laravel-helpers/issues", + "source": "https://github.com/rappasoft/laravel-helpers/tree/v2.0.0" + }, + "install-path": "../rappasoft/laravel-helpers" + }, + { + "name": "spatie/backtrace", + "version": "1.2.1", + "version_normalized": "1.2.1.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/backtrace.git", + "reference": "4ee7d41aa5268107906ea8a4d9ceccde136dbd5b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/backtrace/zipball/4ee7d41aa5268107906ea8a4d9ceccde136dbd5b", + "reference": "4ee7d41aa5268107906ea8a4d9ceccde136dbd5b", + "shasum": "" + }, + "require": { + "php": "^7.3|^8.0" + }, + "require-dev": { + "ext-json": "*", + "phpunit/phpunit": "^9.3", + "symfony/var-dumper": "^5.1" + }, + "time": "2021-11-09T10:57:15+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Spatie\\Backtrace\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van de Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "A better backtrace", + "homepage": "https://github.com/spatie/backtrace", + "keywords": [ + "Backtrace", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/backtrace/issues", + "source": "https://github.com/spatie/backtrace/tree/1.2.1" + }, + "funding": [ + { + "url": "https://github.com/sponsors/spatie", + "type": "github" + }, + { + "url": "https://spatie.be/open-source/support-us", + "type": "other" + } + ], + "install-path": "../spatie/backtrace" + }, + { + "name": "spatie/macroable", + "version": "1.0.1", + "version_normalized": "1.0.1.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/macroable.git", + "reference": "7a99549fc001c925714b329220dea680c04bfa48" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/macroable/zipball/7a99549fc001c925714b329220dea680c04bfa48", + "reference": "7a99549fc001c925714b329220dea680c04bfa48", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.0|^9.3" + }, + "time": "2020-11-03T10:15:05+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Spatie\\Macroable\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "A trait to dynamically add methods to a class", + "homepage": "https://github.com/spatie/macroable", + "keywords": [ + "macroable", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/macroable/issues", + "source": "https://github.com/spatie/macroable/tree/1.0.1" + }, + "install-path": "../spatie/macroable" + }, + { + "name": "spatie/ray", + "version": "1.33.2", + "version_normalized": "1.33.2.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/ray.git", + "reference": "28f6bd88e2db0fada88a7999c8ee0aad69f56192" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/ray/zipball/28f6bd88e2db0fada88a7999c8ee0aad69f56192", + "reference": "28f6bd88e2db0fada88a7999c8ee0aad69f56192", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "php": "^7.3|^8.0", + "ramsey/uuid": "^3.0|^4.1", + "spatie/backtrace": "^1.1", + "spatie/macroable": "^1.0|^2.0", + "symfony/stopwatch": "^4.0|^5.1|^6.0", + "symfony/var-dumper": "^4.2|^5.1|^6.0" + }, + "require-dev": { + "illuminate/support": "6.x|^8.18|^9.0", + "nesbot/carbon": "^2.43", + "phpstan/phpstan": "^0.12.92", + "phpunit/phpunit": "^9.5", + "spatie/phpunit-snapshot-assertions": "^4.2", + "spatie/test-time": "^1.2" + }, + "time": "2022-02-02T15:16:13+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Spatie\\Ray\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Debug with Ray to fix problems faster", + "homepage": "https://github.com/spatie/ray", + "keywords": [ + "ray", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/ray/issues", + "source": "https://github.com/spatie/ray/tree/1.33.2" + }, + "funding": [ + { + "url": "https://github.com/sponsors/spatie", + "type": "github" + }, + { + "url": "https://spatie.be/open-source/support-us", + "type": "other" + } + ], + "install-path": "../spatie/ray" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v2.5.0", + "version_normalized": "2.5.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/6f981ee24cf69ee7ce9736146d1c57c2780598a8", + "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "time": "2021-07-12T14:48:14+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "installation-source": "dist", + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "install-path": "../symfony/deprecation-contracts" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.24.0", + "version_normalized": "1.24.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "30885182c981ab175d4d034db0f6f469898070ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rappasoft/laravel-helpers/zipball/39fc647c27db358c535919cda2040e89b51344af", - "reference": "39fc647c27db358c535919cda2040e89b51344af", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab", + "reference": "30885182c981ab175d4d034db0f6f469898070ab", "shasum": "" }, "require": { - "php": "^7.3|^8.0" + "php": ">=7.1" }, - "time": "2021-10-01T18:00:53+00:00", + "provide": { + "ext-ctype": "*" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "time": "2021-10-20T20:35:02+00:00", "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, "installation-source": "dist", "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, "files": [ - "src/arrays.php", - "src/classes.php", - "src/helpers.php", - "src/strings.php" + "bootstrap.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -35,45 +665,66 @@ ], "authors": [ { - "name": "Anthony Rappa", - "email": "rappa819@gmail.com" + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "Laravel Helpers for Non-Laravel Projects", + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", "keywords": [ - "String helpers", - "array helpers", - "helpers", - "laravel" + "compatibility", + "ctype", + "polyfill", + "portable" ], "support": { - "issues": "https://github.com/rappasoft/laravel-helpers/issues", - "source": "https://github.com/rappasoft/laravel-helpers/tree/v2.0.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.24.0" }, - "install-path": "../rappasoft/laravel-helpers" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "install-path": "../symfony/polyfill-ctype" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.23.1", - "version_normalized": "1.23.1.0", + "version": "v1.24.0", + "version_normalized": "1.24.0.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6" + "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6", - "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825", + "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825", "shasum": "" }, "require": { "php": ">=7.1" }, + "provide": { + "ext-mbstring": "*" + }, "suggest": { "ext-mbstring": "For best performance" }, - "time": "2021-05-27T12:26:48+00:00", + "time": "2021-11-30T18:21:41+00:00", "type": "library", "extra": { "branch-alias": { @@ -86,12 +737,12 @@ }, "installation-source": "dist", "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -117,7 +768,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.24.0" }, "funding": [ { @@ -137,23 +788,23 @@ }, { "name": "symfony/polyfill-php80", - "version": "v1.23.1", - "version_normalized": "1.23.1.0", + "version": "v1.24.0", + "version_normalized": "1.24.0.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be" + "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be", - "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/57b712b08eddb97c762a8caa32c84e037892d2e9", + "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9", "shasum": "" }, "require": { "php": ">=7.1" }, - "time": "2021-07-28T13:41:28+00:00", + "time": "2021-09-13T13:58:33+00:00", "type": "library", "extra": { "branch-alias": { @@ -166,12 +817,12 @@ }, "installation-source": "dist", "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, "files": [ "bootstrap.php" ], + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, "classmap": [ "Resources/stubs" ] @@ -203,7 +854,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.24.0" }, "funding": [ { @@ -221,19 +872,252 @@ ], "install-path": "../symfony/polyfill-php80" }, + { + "name": "symfony/polyfill-php81", + "version": "v1.24.0", + "version_normalized": "1.24.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php81.git", + "reference": "5de4ba2d41b15f9bd0e19b2ab9674135813ec98f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/5de4ba2d41b15f9bd0e19b2ab9674135813ec98f", + "reference": "5de4ba2d41b15f9bd0e19b2ab9674135813ec98f", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "time": "2021-09-13T13:58:11+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "installation-source": "dist", + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php81\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php81/tree/v1.24.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "install-path": "../symfony/polyfill-php81" + }, + { + "name": "symfony/service-contracts", + "version": "v2.5.0", + "version_normalized": "2.5.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/service-contracts.git", + "reference": "1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc", + "reference": "1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "psr/container": "^1.1", + "symfony/deprecation-contracts": "^2.1" + }, + "conflict": { + "ext-psr": "<1.1|>=2" + }, + "suggest": { + "symfony/service-implementation": "" + }, + "time": "2021-11-04T16:48:04+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Service\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to writing services", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/service-contracts/tree/v2.5.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "install-path": "../symfony/service-contracts" + }, + { + "name": "symfony/stopwatch", + "version": "v5.4.3", + "version_normalized": "5.4.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/stopwatch.git", + "reference": "395220730edceb6bd745236ccb5c9125c748f779" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/395220730edceb6bd745236ccb5c9125c748f779", + "reference": "395220730edceb6bd745236ccb5c9125c748f779", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/service-contracts": "^1|^2|^3" + }, + "time": "2022-01-02T09:53:40+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Component\\Stopwatch\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides a way to profile code", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/stopwatch/tree/v5.4.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "install-path": "../symfony/stopwatch" + }, { "name": "symfony/var-dumper", - "version": "v5.4.1", - "version_normalized": "5.4.1.0", + "version": "v5.4.3", + "version_normalized": "5.4.3.0", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "2366ac8d8abe0c077844613c1a4f0c0a9f522dcc" + "reference": "970a01f208bf895c5f327ba40b72288da43adec4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/2366ac8d8abe0c077844613c1a4f0c0a9f522dcc", - "reference": "2366ac8d8abe0c077844613c1a4f0c0a9f522dcc", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/970a01f208bf895c5f327ba40b72288da43adec4", + "reference": "970a01f208bf895c5f327ba40b72288da43adec4", "shasum": "" }, "require": { @@ -257,7 +1141,7 @@ "ext-intl": "To show region name in time zone dump", "symfony/console": "To use the ServerDumpCommand and/or the bin/var-dump-server script" }, - "time": "2021-12-01T15:04:08+00:00", + "time": "2022-01-17T16:30:37+00:00", "bin": [ "Resources/bin/var-dump-server" ], @@ -295,7 +1179,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v5.4.1" + "source": "https://github.com/symfony/var-dumper/tree/v5.4.3" }, "funding": [ { @@ -315,21 +1199,21 @@ }, { "name": "tightenco/collect", - "version": "v8.76.1", - "version_normalized": "8.76.1.0", + "version": "v8.83.0", + "version_normalized": "8.83.0.0", "source": { "type": "git", "url": "https://github.com/tighten/collect.git", - "reference": "c7e8131653480146d4c32c2523d53e0e59a7af19" + "reference": "f8053a9e26ffe0db24db02ef346c40bca920f8f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tighten/collect/zipball/c7e8131653480146d4c32c2523d53e0e59a7af19", - "reference": "c7e8131653480146d4c32c2523d53e0e59a7af19", + "url": "https://api.github.com/repos/tighten/collect/zipball/f8053a9e26ffe0db24db02ef346c40bca920f8f8", + "reference": "f8053a9e26ffe0db24db02ef346c40bca920f8f8", "shasum": "" }, "require": { - "php": "^7.2|^8.0", + "php": "^7.3|^8.0", "symfony/var-dumper": "^3.4 || ^4.0 || ^5.0 || ^6.0" }, "require-dev": { @@ -337,7 +1221,7 @@ "nesbot/carbon": "^2.23.0", "phpunit/phpunit": "^8.3" }, - "time": "2021-12-14T22:01:32+00:00", + "time": "2022-02-10T23:00:41+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -366,7 +1250,7 @@ ], "support": { "issues": "https://github.com/tighten/collect/issues", - "source": "https://github.com/tighten/collect/tree/v8.76.1" + "source": "https://github.com/tighten/collect/tree/v8.83.0" }, "install-path": "../tightenco/collect" } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 18c92e7..713e20f 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -6,11 +6,20 @@ 'aliases' => array ( ), - 'reference' => '87de34fb8b0447cfce613bc057dfc18114756556', + 'reference' => '4487e6e4ab48a41306082315d421692d6034fbfc', 'name' => 'optimisthub/moka-woocommerce', ), 'versions' => array ( + 'brick/math' => + array ( + 'pretty_version' => '0.9.3', + 'version' => '0.9.3.0', + 'aliases' => + array ( + ), + 'reference' => 'ca57d18f028f84f777b2168cd1911b0dee2343ae', + ), 'optimisthub/moka-woocommerce' => array ( 'pretty_version' => 'dev-master', @@ -18,7 +27,34 @@ 'aliases' => array ( ), - 'reference' => '87de34fb8b0447cfce613bc057dfc18114756556', + 'reference' => '4487e6e4ab48a41306082315d421692d6034fbfc', + ), + 'psr/container' => + array ( + 'pretty_version' => '1.1.2', + 'version' => '1.1.2.0', + 'aliases' => + array ( + ), + 'reference' => '513e0666f7216c7459170d56df27dfcefe1689ea', + ), + 'ramsey/collection' => + array ( + 'pretty_version' => '1.2.2', + 'version' => '1.2.2.0', + 'aliases' => + array ( + ), + 'reference' => 'cccc74ee5e328031b15640b51056ee8d3bb66c0a', + ), + 'ramsey/uuid' => + array ( + 'pretty_version' => '4.2.3', + 'version' => '4.2.3.0', + 'aliases' => + array ( + ), + 'reference' => 'fc9bb7fb5388691fd7373cd44dcb4d63bbcf24df', ), 'rappasoft/laravel-helpers' => array ( @@ -29,41 +65,120 @@ ), 'reference' => '39fc647c27db358c535919cda2040e89b51344af', ), + 'rhumsaa/uuid' => + array ( + 'replaced' => + array ( + 0 => '4.2.3', + ), + ), + 'spatie/backtrace' => + array ( + 'pretty_version' => '1.2.1', + 'version' => '1.2.1.0', + 'aliases' => + array ( + ), + 'reference' => '4ee7d41aa5268107906ea8a4d9ceccde136dbd5b', + ), + 'spatie/macroable' => + array ( + 'pretty_version' => '1.0.1', + 'version' => '1.0.1.0', + 'aliases' => + array ( + ), + 'reference' => '7a99549fc001c925714b329220dea680c04bfa48', + ), + 'spatie/ray' => + array ( + 'pretty_version' => '1.33.2', + 'version' => '1.33.2.0', + 'aliases' => + array ( + ), + 'reference' => '28f6bd88e2db0fada88a7999c8ee0aad69f56192', + ), + 'symfony/deprecation-contracts' => + array ( + 'pretty_version' => 'v2.5.0', + 'version' => '2.5.0.0', + 'aliases' => + array ( + ), + 'reference' => '6f981ee24cf69ee7ce9736146d1c57c2780598a8', + ), + 'symfony/polyfill-ctype' => + array ( + 'pretty_version' => 'v1.24.0', + 'version' => '1.24.0.0', + 'aliases' => + array ( + ), + 'reference' => '30885182c981ab175d4d034db0f6f469898070ab', + ), 'symfony/polyfill-mbstring' => array ( - 'pretty_version' => 'v1.23.1', - 'version' => '1.23.1.0', + 'pretty_version' => 'v1.24.0', + 'version' => '1.24.0.0', 'aliases' => array ( ), - 'reference' => '9174a3d80210dca8daa7f31fec659150bbeabfc6', + 'reference' => '0abb51d2f102e00a4eefcf46ba7fec406d245825', ), 'symfony/polyfill-php80' => array ( - 'pretty_version' => 'v1.23.1', - 'version' => '1.23.1.0', + 'pretty_version' => 'v1.24.0', + 'version' => '1.24.0.0', + 'aliases' => + array ( + ), + 'reference' => '57b712b08eddb97c762a8caa32c84e037892d2e9', + ), + 'symfony/polyfill-php81' => + array ( + 'pretty_version' => 'v1.24.0', + 'version' => '1.24.0.0', + 'aliases' => + array ( + ), + 'reference' => '5de4ba2d41b15f9bd0e19b2ab9674135813ec98f', + ), + 'symfony/service-contracts' => + array ( + 'pretty_version' => 'v2.5.0', + 'version' => '2.5.0.0', + 'aliases' => + array ( + ), + 'reference' => '1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc', + ), + 'symfony/stopwatch' => + array ( + 'pretty_version' => 'v5.4.3', + 'version' => '5.4.3.0', 'aliases' => array ( ), - 'reference' => '1100343ed1a92e3a38f9ae122fc0eb21602547be', + 'reference' => '395220730edceb6bd745236ccb5c9125c748f779', ), 'symfony/var-dumper' => array ( - 'pretty_version' => 'v5.4.1', - 'version' => '5.4.1.0', + 'pretty_version' => 'v5.4.3', + 'version' => '5.4.3.0', 'aliases' => array ( ), - 'reference' => '2366ac8d8abe0c077844613c1a4f0c0a9f522dcc', + 'reference' => '970a01f208bf895c5f327ba40b72288da43adec4', ), 'tightenco/collect' => array ( - 'pretty_version' => 'v8.76.1', - 'version' => '8.76.1.0', + 'pretty_version' => 'v8.83.0', + 'version' => '8.83.0.0', 'aliases' => array ( ), - 'reference' => 'c7e8131653480146d4c32c2523d53e0e59a7af19', + 'reference' => 'f8053a9e26ffe0db24db02ef346c40bca920f8f8', ), ), ); diff --git a/vendor/composer/platform_check.php b/vendor/composer/platform_check.php index 92370c5..580fa96 100644 --- a/vendor/composer/platform_check.php +++ b/vendor/composer/platform_check.php @@ -4,8 +4,8 @@ $issues = array(); -if (!(PHP_VERSION_ID >= 70300)) { - $issues[] = 'Your Composer dependencies require a PHP version ">= 7.3.0". You are running ' . PHP_VERSION . '.'; +if (!(PHP_VERSION_ID >= 70400)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0". You are running ' . PHP_VERSION . '.'; } if ($issues) { diff --git a/vendor/psr/container/.gitignore b/vendor/psr/container/.gitignore new file mode 100644 index 0000000..b2395aa --- /dev/null +++ b/vendor/psr/container/.gitignore @@ -0,0 +1,3 @@ +composer.lock +composer.phar +/vendor/ diff --git a/vendor/psr/container/LICENSE b/vendor/psr/container/LICENSE new file mode 100644 index 0000000..2877a48 --- /dev/null +++ b/vendor/psr/container/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013-2016 container-interop +Copyright (c) 2016 PHP Framework Interoperability Group + +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/psr/container/README.md b/vendor/psr/container/README.md new file mode 100644 index 0000000..1b9d9e5 --- /dev/null +++ b/vendor/psr/container/README.md @@ -0,0 +1,13 @@ +Container interface +============== + +This repository holds all interfaces related to [PSR-11 (Container Interface)][psr-url]. + +Note that this is not a Container implementation of its own. It is merely abstractions that describe the components of a Dependency Injection Container. + +The installable [package][package-url] and [implementations][implementation-url] are listed on Packagist. + +[psr-url]: https://www.php-fig.org/psr/psr-11/ +[package-url]: https://packagist.org/packages/psr/container +[implementation-url]: https://packagist.org/providers/psr/container-implementation + diff --git a/vendor/psr/container/composer.json b/vendor/psr/container/composer.json new file mode 100644 index 0000000..017f41e --- /dev/null +++ b/vendor/psr/container/composer.json @@ -0,0 +1,22 @@ +{ + "name": "psr/container", + "type": "library", + "description": "Common Container Interface (PHP FIG PSR-11)", + "keywords": ["psr", "psr-11", "container", "container-interop", "container-interface"], + "homepage": "https://github.com/php-fig/container", + "license": "MIT", + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "require": { + "php": ">=7.4.0" + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + } +} diff --git a/vendor/psr/container/src/ContainerExceptionInterface.php b/vendor/psr/container/src/ContainerExceptionInterface.php new file mode 100644 index 0000000..0f213f2 --- /dev/null +++ b/vendor/psr/container/src/ContainerExceptionInterface.php @@ -0,0 +1,12 @@ + + +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/collection/README.md b/vendor/ramsey/collection/README.md new file mode 100644 index 0000000..9124dd7 --- /dev/null +++ b/vendor/ramsey/collection/README.md @@ -0,0 +1,82 @@ +

ramsey/collection

+ +

+ A PHP library for representing and manipulating collections. +

+ +

+ Source Code + Download Package + PHP Programming Language + Read License + Build Status + Codecov Code Coverage + Psalm Type Coverage +

+ +## About + +ramsey/collection is a PHP library for representing and manipulating collections. + +Much inspiration for this library came from the [Java Collections Framework][java]. + +This project adheres to a [code of conduct](CODE_OF_CONDUCT.md). +By participating in this project and its community, you are expected to +uphold this code. + +## Installation + +Install this package as a dependency using [Composer](https://getcomposer.org). + +``` bash +composer require ramsey/collection +``` + +## Usage + +Examples of how to use this framework can be found in the +[Wiki pages](https://github.com/ramsey/collection/wiki/Examples). + +## Contributing + +Contributions are welcome! Before contributing to this project, familiarize +yourself with [CONTRIBUTING.md](CONTRIBUTING.md). + +To develop this project, you will need [PHP](https://www.php.net) 7.3 or greater +and [Composer](https://getcomposer.org). + +After cloning this repository locally, execute the following commands: + +``` bash +cd /path/to/repository +composer install +``` + +Now, you are ready to develop! + +## Coordinated Disclosure + +Keeping user information safe and secure is a top priority, and we welcome the +contribution of external security researchers. If you believe you've found a +security issue in software that is maintained in this repository, please read +[SECURITY.md][] for instructions on submitting a vulnerability report. + +## ramsey/collection for Enterprise + +Available as part of the Tidelift Subscription. + +The maintainers of ramsey/collection and thousands of other packages are working +with Tidelift to deliver commercial support and maintenance for the open source +packages you use to build your applications. Save time, reduce risk, and improve +code health, while paying the maintainers of the exact packages you use. +[Learn more.](https://tidelift.com/subscription/pkg/packagist-ramsey-collection?utm_source=undefined&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) + +## Copyright and License + +The ramsey/collection library is copyright © [Ben Ramsey](https://benramsey.com) +and licensed for use under the terms of the +MIT License (MIT). Please see [LICENSE](LICENSE) for more information. + + +[java]: http://docs.oracle.com/javase/8/docs/technotes/guides/collections/index.html +[security.md]: https://github.com/ramsey/collection/blob/master/SECURITY.md diff --git a/vendor/ramsey/collection/SECURITY.md b/vendor/ramsey/collection/SECURITY.md new file mode 100644 index 0000000..b052f3b --- /dev/null +++ b/vendor/ramsey/collection/SECURITY.md @@ -0,0 +1,113 @@ + + +# Vulnerability Disclosure Policy + +Keeping user information safe and secure is a top priority, and we welcome the +contribution of external security researchers. + +## Scope + +If you believe you've found a security issue in software that is maintained in +this repository, we encourage you to notify us. + +| Version | In scope | Source code | +| :-----: | :------: | :---------- | +| latest | ✅ | https://github.com/ramsey/collection | + +## How to Submit a Report + +To submit a vulnerability report, please contact us at . +Your submission will be reviewed and validated by a member of our team. + +## Safe Harbor + +We support safe harbor for security researchers who: + +* Make a good faith effort to avoid privacy violations, destruction of data, and + interruption or degradation of our services. +* Only interact with accounts you own or with explicit permission of the account + holder. If you do encounter Personally Identifiable Information (PII) contact + us immediately, do not proceed with access, and immediately purge any local + information. +* Provide us with a reasonable amount of time to resolve vulnerabilities prior + to any disclosure to the public or a third-party. + +We will consider activities conducted consistent with this policy to constitute +"authorized" conduct and will not pursue civil action or initiate a complaint to +law enforcement. We will help to the extent we can if legal action is initiated +by a third party against you. + +Please submit a report to us before engaging in conduct that may be inconsistent +with or unaddressed by this policy. + +## Preferences + +* Please provide detailed reports with reproducible steps and a clearly defined + impact. +* Include the version number of the vulnerable package in your report +* Social engineering (e.g. phishing, vishing, smishing) is prohibited. + +## Encryption Key for security@ramsey.dev + +For increased privacy when reporting sensitive issues, you may encrypt your +messages using the following key: + +``` +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBF+Z9gEBEACbT/pIx8RR0K18t8Z2rDnmEV44YdT7HNsMdq+D6SAlx8UUb6AU +jGIbV9dgBgGNtOLU1pxloaJwL9bWIRbj+X/Qb2WNIP//Vz1Y40ox1dSpfCUrizXx +kb4p58Xml0PsB8dg3b4RDUgKwGC37ne5xmDnigyJPbiB2XJ6Xc46oPCjh86XROTK +wEBB2lY67ClBlSlvC2V9KmbTboRQkLdQDhOaUosMb99zRb0EWqDLaFkZVjY5HI7i +0pTveE6dI12NfHhTwKjZ5pUiAZQGlKA6J1dMjY2unxHZkQj5MlMfrLSyJHZxccdJ +xD94T6OTcTHt/XmMpI2AObpewZDdChDQmcYDZXGfAhFoJmbvXsmLMGXKgzKoZ/ls +RmLsQhh7+/r8E+Pn5r+A6Hh4uAc14ApyEP0ckKeIXw1C6pepHM4E8TEXVr/IA6K/ +z6jlHORixIFX7iNOnfHh+qwOgZw40D6JnBfEzjFi+T2Cy+JzN2uy7I8UnecTMGo3 +5t6astPy6xcH6kZYzFTV7XERR6LIIVyLAiMFd8kF5MbJ8N5ElRFsFHPW+82N2HDX +c60iSaTB85k6R6xd8JIKDiaKE4sSuw2wHFCKq33d/GamYezp1wO+bVUQg88efljC +2JNFyD+vl30josqhw1HcmbE1TP3DlYeIL5jQOlxCMsgai6JtTfHFM/5MYwARAQAB +tBNzZWN1cml0eUByYW1zZXkuZGV2iQJUBBMBCAA+FiEE4drPD+/ofZ570fAYq0bv +vXQCywIFAl+Z9gECGwMFCQeGH4AFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQ +q0bvvXQCywIkEA//Qcwv8MtTCy01LHZd9c7VslwhNdXQDYymcTyjcYw8x7O22m4B +3hXE6vqAplFhVxxkqXB2ef0tQuzxhPHNJgkCE4Wq4i+V6qGpaSVHQT2W6DN/NIhL +vS8OdScc6zddmIbIkSrzVVAtjwehFNEIrX3DnbbbK+Iku7vsKT5EclOluIsjlYoX +goW8IeReyDBqOe2H3hoCGw6EA0D/NYV2bJnfy53rXVIyarsXXeOLp7eNEH6Td7aW +PVSrMZJe1t+knrEGnEdrXWzlg4lCJJCtemGv+pKBUomnyISXSdqyoRCCzvQjqyig +2kRebUX8BXPW33p4OXPj9sIboUOjZwormWwqqbFMO+J4TiVCUoEoheI7emPFRcNN +QtPJrjbY1++OznBc0GRpfeUkGoU1cbRl1bnepnFIZMTDLkrVW6I1Y4q8ZVwX3BkE +N81ctFrRpHBlU36EdHvjPQmGtuiL77Qq3fWmMv7yTvK1wHJAXfEb0ZJWHZCbck3w +l0CVq0Z+UUAOM8Rp1N0N8m92xtapav0qCFU9qzf2J5qX6GRmWv+d29wPgFHzDWBm +nnrYYIA4wJLx00U6SMcVBSnNe91B+RfGY5XQhbWPjQQecOGCSDsxaFAq2MeOVJyZ +bIjLYfG9GxoLKr5R7oLRJvZI4nKKBc1Kci/crZbdiSdQhSQGlDz88F1OHeCIdQQQ +EQgAHRYhBOhdAxHd+lus86YQ57Atl5icjAcbBQJfmfdIAAoJELAtl5icjAcbFVcA +/1LqB3ZjsnXDAvvAXZVjSPqofSlpMLeRQP6IM/A9Odq0AQCZrtZc1knOMGEcjppK +Rk+sy/R0Mshy8TDuaZIRgh2Ux7kCDQRfmfYBARAAmchKzzVz7IaEq7PnZDb3szQs +T/+E9F3m39yOpV4fEB1YzObonFakXNT7Gw2tZEx0eitUMqQ/13jjfu3UdzlKl2bR +qA8LrSQRhB+PTC9A1XvwxCUYhhjGiLzJ9CZL6hBQB43qHOmE9XJPme90geLsF+gK +u39Waj1SNWzwGg+Gy1Gl5f2AJoDTxznreCuFGj+Vfaczt/hlfgqpOdb9jsmdoE7t +3DSWppA9dRHWwQSgE6J28rR4QySBcqyXS6IMykqaJn7Z26yNIaITLnHCZOSY8zhP +ha7GFsN549EOCgECbrnPt9dmI2+hQE0RO0e7SOBNsIf5sz/i7urhwuj0CbOqhjc2 +X1AEVNFCVcb6HPi/AWefdFCRu0gaWQxn5g+9nkq5slEgvzCCiKYzaBIcr8qR6Hb4 +FaOPVPxO8vndRouq57Ws8XpAwbPttioFuCqF4u9K+tK/8e2/R8QgRYJsE3Cz/Fu8 ++pZFpMnqbDEbK3DL3ss+1ed1sky+mDV8qXXeI33XW5hMFnk1JWshUjHNlQmE6ftC +U0xSTMVUtwJhzH2zDp8lEdu7qi3EsNULOl68ozDr6soWAvCbHPeTdTOnFySGCleG +/3TonsoZJs/sSPPJnxFQ1DtgQL6EbhIwa0ZwU4eKYVHZ9tjxuMX3teFzRvOrJjgs ++ywGlsIURtEckT5Y6nMAEQEAAYkCPAQYAQgAJhYhBOHazw/v6H2ee9HwGKtG7710 +AssCBQJfmfYBAhsMBQkHhh+AAAoJEKtG7710AssC8NcP/iDAcy1aZFvkA0EbZ85p +i7/+ywtE/1wF4U4/9OuLcoskqGGnl1pJNPooMOSBCfreoTB8HimT0Fln0CoaOm4Q +pScNq39JXmf4VxauqUJVARByP6zUfgYarqoaZNeuFF0S4AZJ2HhGzaQPjDz1uKVM +PE6tQSgQkFzdZ9AtRA4vElTH6yRAgmepUsOihk0b0gUtVnwtRYZ8e0Qt3ie97a73 +DxLgAgedFRUbLRYiT0vNaYbainBsLWKpN/T8odwIg/smP0Khjp/ckV60cZTdBiPR +szBTPJESMUTu0VPntc4gWwGsmhZJg/Tt/qP08XYo3VxNYBegyuWwNR66zDWvwvGH +muMv5UchuDxp6Rt3JkIO4voMT1JSjWy9p8krkPEE4V6PxAagLjdZSkt92wVLiK5x +y5gNrtPhU45YdRAKHr36OvJBJQ42CDaZ6nzrzghcIp9CZ7ANHrI+QLRM/csz+AGA +szSp6S4mc1lnxxfbOhPPpebZPn0nIAXoZnnoVKdrxBVedPQHT59ZFvKTQ9Fs7gd3 +sYNuc7tJGFGC2CxBH4ANDpOQkc5q9JJ1HSGrXU3juxIiRgfA26Q22S9c71dXjElw +Ri584QH+bL6kkYmm8xpKF6TVwhwu5xx/jBPrbWqFrtbvLNrnfPoapTihBfdIhkT6 +nmgawbBHA02D5xEqB5SU3WJu +=eJNx +-----END PGP PUBLIC KEY BLOCK----- +``` diff --git a/vendor/ramsey/collection/composer.json b/vendor/ramsey/collection/composer.json new file mode 100644 index 0000000..98862ee --- /dev/null +++ b/vendor/ramsey/collection/composer.json @@ -0,0 +1,102 @@ +{ + "name": "ramsey/collection", + "type": "library", + "description": "A PHP library for representing and manipulating collections.", + "keywords": [ + "array", + "collection", + "hash", + "map", + "queue", + "set" + ], + "license": "MIT", + "authors": [ + { + "name": "Ben Ramsey", + "email": "ben@benramsey.com", + "homepage": "https://benramsey.com" + } + ], + "require": { + "php": "^7.3 || ^8", + "symfony/polyfill-php81": "^1.23" + }, + "require-dev": { + "captainhook/captainhook": "^5.3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", + "ergebnis/composer-normalize": "^2.6", + "fakerphp/faker": "^1.5", + "hamcrest/hamcrest-php": "^2", + "jangregor/phpstan-prophecy": "^0.8", + "mockery/mockery": "^1.3", + "phpspec/prophecy-phpunit": "^2.0", + "phpstan/extension-installer": "^1", + "phpstan/phpstan": "^0.12.32", + "phpstan/phpstan-mockery": "^0.12.5", + "phpstan/phpstan-phpunit": "^0.12.11", + "phpunit/phpunit": "^8.5 || ^9", + "psy/psysh": "^0.10.4", + "slevomat/coding-standard": "^6.3", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.4" + }, + "config": { + "sort-packages": true + }, + "autoload": { + "psr-4": { + "Ramsey\\Collection\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Ramsey\\Console\\": "resources/console/", + "Ramsey\\Collection\\Test\\": "tests/", + "Ramsey\\Test\\Generics\\": "tests/generics/" + }, + "files": [ + "vendor/hamcrest/hamcrest-php/hamcrest/Hamcrest.php" + ] + }, + "scripts": { + "post-autoload-dump": "captainhook install --ansi -f -s", + "dev:analyze": [ + "@dev:analyze:phpstan", + "@dev:analyze:psalm" + ], + "dev:analyze:phpstan": "phpstan --memory-limit=1G analyse", + "dev:analyze:psalm": "psalm --diff --config=psalm.xml", + "dev:build:clean": "git clean -fX build/.", + "dev:build:clear-cache": "git clean -fX build/cache/.", + "dev:lint": "phpcs --cache=build/cache/phpcs.cache", + "dev:lint:fix": "./bin/lint-fix.sh", + "dev:repl": [ + "echo ; echo 'Type ./bin/repl to start the REPL.'" + ], + "dev:test": "phpunit", + "dev:test:all": [ + "@dev:lint", + "@dev:analyze", + "@dev:test" + ], + "dev:test:coverage:ci": "phpunit --coverage-clover build/logs/clover.xml", + "dev:test:coverage:html": "phpunit --coverage-html build/coverage", + "test": "@dev:test:all" + }, + "scripts-descriptions": { + "dev:analyze": "Performs static analysis on the code base.", + "dev:analyze:phpstan": "Runs the PHPStan static analyzer.", + "dev:analyze:psalm": "Runs the Psalm static analyzer.", + "dev:build:clean": "Removes everything not under version control from the build directory.", + "dev:build:clear-cache": "Removes everything not under version control from build/cache/.", + "dev:lint": "Checks all source code for coding standards issues.", + "dev:lint:fix": "Checks source code for coding standards issues and fixes them, if possible.", + "dev:repl": "Note: Use ./bin/repl to run the REPL.", + "dev:test": "Runs the full unit test suite.", + "dev:test:all": "Runs linting, static analysis, and unit tests.", + "dev:test:coverage:ci": "Runs the unit test suite and generates a Clover coverage report.", + "dev:test:coverage:html": "Runs the unit tests suite and generates an HTML coverage report.", + "test": "Shortcut to run the full test suite." + } +} diff --git a/vendor/ramsey/collection/src/AbstractArray.php b/vendor/ramsey/collection/src/AbstractArray.php new file mode 100644 index 0000000..d72dbe6 --- /dev/null +++ b/vendor/ramsey/collection/src/AbstractArray.php @@ -0,0 +1,209 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +use ArrayIterator; +use Traversable; + +use function serialize; +use function unserialize; + +/** + * This class provides a basic implementation of `ArrayInterface`, to minimize + * the effort required to implement this interface. + * + * @template T + * @implements ArrayInterface + */ +abstract class AbstractArray implements ArrayInterface +{ + /** + * The items of this array. + * + * @var array + */ + protected $data = []; + + /** + * Constructs a new array object. + * + * @param array $data The initial items to add to this array. + */ + public function __construct(array $data = []) + { + // Invoke offsetSet() for each value added; in this way, sub-classes + // may provide additional logic about values added to the array object. + foreach ($data as $key => $value) { + $this[$key] = $value; + } + } + + /** + * Returns an iterator for this array. + * + * @link http://php.net/manual/en/iteratoraggregate.getiterator.php IteratorAggregate::getIterator() + * + * @return Traversable + */ + public function getIterator(): Traversable + { + return new ArrayIterator($this->data); + } + + /** + * Returns `true` if the given offset exists in this array. + * + * @link http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetExists() + * + * @param array-key $offset The offset to check. + */ + public function offsetExists($offset): bool + { + return isset($this->data[$offset]); + } + + /** + * Returns the value at the specified offset. + * + * @link http://php.net/manual/en/arrayaccess.offsetget.php ArrayAccess::offsetGet() + * + * @param array-key $offset The offset for which a value should be returned. + * + * @return T|null the value stored at the offset, or null if the offset + * does not exist. + * + * @psalm-suppress InvalidAttribute + */ + #[\ReturnTypeWillChange] // phpcs:ignore + public function offsetGet($offset) + { + return $this->data[$offset] ?? null; + } + + /** + * Sets the given value to the given offset in the array. + * + * @link http://php.net/manual/en/arrayaccess.offsetset.php ArrayAccess::offsetSet() + * + * @param array-key|null $offset The offset to set. If `null`, the value may be + * set at a numerically-indexed offset. + * @param T $value The value to set at the given offset. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function offsetSet($offset, $value): void + { + if ($offset === null) { + $this->data[] = $value; + } else { + $this->data[$offset] = $value; + } + } + + /** + * Removes the given offset and its value from the array. + * + * @link http://php.net/manual/en/arrayaccess.offsetunset.php ArrayAccess::offsetUnset() + * + * @param array-key $offset The offset to remove from the array. + */ + public function offsetUnset($offset): void + { + unset($this->data[$offset]); + } + + /** + * Returns a serialized string representation of this array object. + * + * @deprecated The Serializable interface will go away in PHP 9. + * + * @link http://php.net/manual/en/serializable.serialize.php Serializable::serialize() + * + * @return string a PHP serialized string. + */ + public function serialize(): string + { + return serialize($this->data); + } + + /** + * Returns data suitable for PHP serialization. + * + * @link https://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.serialize + * @link https://www.php.net/serialize + * + * @return array + */ + public function __serialize(): array + { + return $this->data; + } + + /** + * Converts a serialized string representation into an instance object. + * + * @deprecated The Serializable interface will go away in PHP 9. + * + * @link http://php.net/manual/en/serializable.unserialize.php Serializable::unserialize() + * + * @param string $serialized A PHP serialized string to unserialize. + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + */ + public function unserialize($serialized): void + { + /** @var array $data */ + $data = unserialize($serialized, ['allowed_classes' => false]); + + $this->data = $data; + } + + /** + * Adds unserialized data to the object. + * + * @param array $data + */ + public function __unserialize(array $data): void + { + $this->data = $data; + } + + /** + * Returns the number of items in this array. + * + * @link http://php.net/manual/en/countable.count.php Countable::count() + */ + public function count(): int + { + return count($this->data); + } + + public function clear(): void + { + $this->data = []; + } + + /** + * @inheritDoc + */ + public function toArray(): array + { + return $this->data; + } + + public function isEmpty(): bool + { + return count($this->data) === 0; + } +} diff --git a/vendor/ramsey/collection/src/AbstractCollection.php b/vendor/ramsey/collection/src/AbstractCollection.php new file mode 100644 index 0000000..d2cd115 --- /dev/null +++ b/vendor/ramsey/collection/src/AbstractCollection.php @@ -0,0 +1,318 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +use Closure; +use Ramsey\Collection\Exception\CollectionMismatchException; +use Ramsey\Collection\Exception\InvalidArgumentException; +use Ramsey\Collection\Exception\InvalidSortOrderException; +use Ramsey\Collection\Exception\OutOfBoundsException; +use Ramsey\Collection\Tool\TypeTrait; +use Ramsey\Collection\Tool\ValueExtractorTrait; +use Ramsey\Collection\Tool\ValueToStringTrait; + +use function array_filter; +use function array_map; +use function array_merge; +use function array_search; +use function array_udiff; +use function array_uintersect; +use function current; +use function end; +use function in_array; +use function is_int; +use function reset; +use function sprintf; +use function unserialize; +use function usort; + +/** + * This class provides a basic implementation of `CollectionInterface`, to + * minimize the effort required to implement this interface + * + * @template T + * @extends AbstractArray + * @implements CollectionInterface + */ +abstract class AbstractCollection extends AbstractArray implements CollectionInterface +{ + use TypeTrait; + use ValueToStringTrait; + use ValueExtractorTrait; + + /** + * @inheritDoc + */ + public function add($element): bool + { + $this[] = $element; + + return true; + } + + /** + * @inheritDoc + */ + public function contains($element, bool $strict = true): bool + { + return in_array($element, $this->data, $strict); + } + + /** + * @inheritDoc + */ + public function offsetSet($offset, $value): void + { + if ($this->checkType($this->getType(), $value) === false) { + throw new InvalidArgumentException( + 'Value must be of type ' . $this->getType() . '; value is ' + . $this->toolValueToString($value) + ); + } + + if ($offset === null) { + $this->data[] = $value; + } else { + $this->data[$offset] = $value; + } + } + + /** + * @inheritDoc + */ + public function remove($element): bool + { + if (($position = array_search($element, $this->data, true)) !== false) { + unset($this->data[$position]); + + return true; + } + + return false; + } + + /** + * @inheritDoc + */ + public function column(string $propertyOrMethod): array + { + $temp = []; + + foreach ($this->data as $item) { + /** @var mixed $value */ + $value = $this->extractValue($item, $propertyOrMethod); + + /** @psalm-suppress MixedAssignment */ + $temp[] = $value; + } + + return $temp; + } + + /** + * @inheritDoc + */ + public function first() + { + if ($this->isEmpty()) { + throw new OutOfBoundsException('Can\'t determine first item. Collection is empty'); + } + + reset($this->data); + + /** @var T $first */ + $first = current($this->data); + + return $first; + } + + /** + * @inheritDoc + */ + public function last() + { + if ($this->isEmpty()) { + throw new OutOfBoundsException('Can\'t determine last item. Collection is empty'); + } + + /** @var T $item */ + $item = end($this->data); + reset($this->data); + + return $item; + } + + public function sort(string $propertyOrMethod, string $order = self::SORT_ASC): CollectionInterface + { + if (!in_array($order, [self::SORT_ASC, self::SORT_DESC], true)) { + throw new InvalidSortOrderException('Invalid sort order given: ' . $order); + } + + $collection = clone $this; + + usort( + $collection->data, + /** + * @param T $a + * @param T $b + */ + function ($a, $b) use ($propertyOrMethod, $order): int { + /** @var mixed $aValue */ + $aValue = $this->extractValue($a, $propertyOrMethod); + + /** @var mixed $bValue */ + $bValue = $this->extractValue($b, $propertyOrMethod); + + return ($aValue <=> $bValue) * ($order === self::SORT_DESC ? -1 : 1); + } + ); + + return $collection; + } + + public function filter(callable $callback): CollectionInterface + { + $collection = clone $this; + $collection->data = array_merge([], array_filter($collection->data, $callback)); + + return $collection; + } + + /** + * {@inheritdoc} + */ + public function where(string $propertyOrMethod, $value): CollectionInterface + { + return $this->filter(function ($item) use ($propertyOrMethod, $value) { + /** @var mixed $accessorValue */ + $accessorValue = $this->extractValue($item, $propertyOrMethod); + + return $accessorValue === $value; + }); + } + + public function map(callable $callback): CollectionInterface + { + return new Collection('mixed', array_map($callback, $this->data)); + } + + public function diff(CollectionInterface $other): CollectionInterface + { + $this->compareCollectionTypes($other); + + $diffAtoB = array_udiff($this->data, $other->toArray(), $this->getComparator()); + $diffBtoA = array_udiff($other->toArray(), $this->data, $this->getComparator()); + + /** @var array $diff */ + $diff = array_merge($diffAtoB, $diffBtoA); + + $collection = clone $this; + $collection->data = $diff; + + return $collection; + } + + public function intersect(CollectionInterface $other): CollectionInterface + { + $this->compareCollectionTypes($other); + + /** @var array $intersect */ + $intersect = array_uintersect($this->data, $other->toArray(), $this->getComparator()); + + $collection = clone $this; + $collection->data = $intersect; + + return $collection; + } + + public function merge(CollectionInterface ...$collections): CollectionInterface + { + $mergedCollection = clone $this; + + foreach ($collections as $index => $collection) { + if (!$collection instanceof static) { + throw new CollectionMismatchException( + sprintf('Collection with index %d must be of type %s', $index, static::class) + ); + } + + // When using generics (Collection.php, Set.php, etc), + // we also need to make sure that the internal types match each other + if ($collection->getType() !== $this->getType()) { + throw new CollectionMismatchException( + sprintf('Collection items in collection with index %d must be of type %s', $index, $this->getType()) + ); + } + + foreach ($collection as $key => $value) { + if (is_int($key)) { + $mergedCollection[] = $value; + } else { + $mergedCollection[$key] = $value; + } + } + } + + return $mergedCollection; + } + + /** + * @inheritDoc + */ + public function unserialize($serialized): void + { + /** @var array $data */ + $data = unserialize($serialized, ['allowed_classes' => [$this->getType()]]); + + $this->data = $data; + } + + /** + * @param CollectionInterface $other + */ + private function compareCollectionTypes(CollectionInterface $other): void + { + if (!$other instanceof static) { + throw new CollectionMismatchException('Collection must be of type ' . static::class); + } + + // When using generics (Collection.php, Set.php, etc), + // we also need to make sure that the internal types match each other + if ($other->getType() !== $this->getType()) { + throw new CollectionMismatchException('Collection items must be of type ' . $this->getType()); + } + } + + private function getComparator(): Closure + { + return /** + * @param T $a + * @param T $b + */ + function ($a, $b): int { + // If the two values are object, we convert them to unique scalars. + // If the collection contains mixed values (unlikely) where some are objects + // and some are not, we leave them as they are. + // The comparator should still work and the result of $a < $b should + // be consistent but unpredictable since not documented. + if (is_object($a) && is_object($b)) { + $a = spl_object_id($a); + $b = spl_object_id($b); + } + + return $a === $b ? 0 : ($a < $b ? 1 : -1); + }; + } +} diff --git a/vendor/ramsey/collection/src/AbstractSet.php b/vendor/ramsey/collection/src/AbstractSet.php new file mode 100644 index 0000000..1126ccb --- /dev/null +++ b/vendor/ramsey/collection/src/AbstractSet.php @@ -0,0 +1,50 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +/** + * This class contains the basic implementation of a collection that does not + * allow duplicated values (a set), to minimize the effort required to implement + * this specific type of collection. + * + * @template T + * @extends AbstractCollection + */ +abstract class AbstractSet extends AbstractCollection +{ + /** + * @inheritDoc + */ + public function add($element): bool + { + if ($this->contains($element)) { + return false; + } + + return parent::add($element); + } + + /** + * @inheritDoc + */ + public function offsetSet($offset, $value): void + { + if ($this->contains($value)) { + return; + } + + parent::offsetSet($offset, $value); + } +} diff --git a/vendor/ramsey/collection/src/ArrayInterface.php b/vendor/ramsey/collection/src/ArrayInterface.php new file mode 100644 index 0000000..27af610 --- /dev/null +++ b/vendor/ramsey/collection/src/ArrayInterface.php @@ -0,0 +1,51 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +use ArrayAccess; +use Countable; +use IteratorAggregate; +use Serializable; + +/** + * `ArrayInterface` provides traversable array functionality to data types. + * + * @template T + * @extends ArrayAccess + * @extends IteratorAggregate + */ +interface ArrayInterface extends + ArrayAccess, + Countable, + IteratorAggregate, + Serializable +{ + /** + * Removes all items from this array. + */ + public function clear(): void; + + /** + * Returns a native PHP array representation of this array object. + * + * @return array + */ + public function toArray(): array; + + /** + * Returns `true` if this array is empty. + */ + public function isEmpty(): bool; +} diff --git a/vendor/ramsey/collection/src/Collection.php b/vendor/ramsey/collection/src/Collection.php new file mode 100644 index 0000000..1299c12 --- /dev/null +++ b/vendor/ramsey/collection/src/Collection.php @@ -0,0 +1,106 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +/** + * A collection represents a group of objects. + * + * Each object in the collection is of a specific, defined type. + * + * This is a direct implementation of `CollectionInterface`, provided for + * the sake of convenience. + * + * Example usage: + * + * ``` php + * $collection = new \Ramsey\Collection\Collection('My\\Foo'); + * $collection->add(new \My\Foo()); + * $collection->add(new \My\Foo()); + * + * foreach ($collection as $foo) { + * // Do something with $foo + * } + * ``` + * + * It is preferable to subclass `AbstractCollection` to create your own typed + * collections. For example: + * + * ``` php + * namespace My\Foo; + * + * class FooCollection extends \Ramsey\Collection\AbstractCollection + * { + * public function getType() + * { + * return 'My\\Foo'; + * } + * } + * ``` + * + * And then use it similarly to the earlier example: + * + * ``` php + * $fooCollection = new \My\Foo\FooCollection(); + * $fooCollection->add(new \My\Foo()); + * $fooCollection->add(new \My\Foo()); + * + * foreach ($fooCollection as $foo) { + * // Do something with $foo + * } + * ``` + * + * The benefit with this approach is that you may do type-checking on the + * collection object: + * + * ``` php + * if ($collection instanceof \My\Foo\FooCollection) { + * // the collection is a collection of My\Foo objects + * } + * ``` + * + * @template T + * @extends AbstractCollection + */ +class Collection extends AbstractCollection +{ + /** + * The type of elements stored in this collection. + * + * A collection's type is immutable once it is set. For this reason, this + * property is set private. + * + * @var string + */ + private $collectionType; + + /** + * Constructs a collection object of the specified type, optionally with the + * specified data. + * + * @param string $collectionType The type (FQCN) associated with this + * collection. + * @param array $data The initial items to store in the collection. + */ + public function __construct(string $collectionType, array $data = []) + { + $this->collectionType = $collectionType; + parent::__construct($data); + } + + public function getType(): string + { + return $this->collectionType; + } +} diff --git a/vendor/ramsey/collection/src/CollectionInterface.php b/vendor/ramsey/collection/src/CollectionInterface.php new file mode 100644 index 0000000..aa86feb --- /dev/null +++ b/vendor/ramsey/collection/src/CollectionInterface.php @@ -0,0 +1,205 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +/** + * A collection represents a group of objects, known as its elements. + * + * Some collections allow duplicate elements and others do not. Some are ordered + * and others unordered. + * + * @template T + * @extends ArrayInterface + */ +interface CollectionInterface extends ArrayInterface +{ + /** + * Ascending sort type. + */ + public const SORT_ASC = 'asc'; + + /** + * Descending sort type. + */ + public const SORT_DESC = 'desc'; + + /** + * Ensures that this collection contains the specified element (optional + * operation). + * + * Returns `true` if this collection changed as a result of the call. + * (Returns `false` if this collection does not permit duplicates and + * already contains the specified element.) + * + * Collections that support this operation may place limitations on what + * elements may be added to this collection. In particular, some + * collections will refuse to add `null` elements, and others will impose + * restrictions on the type of elements that may be added. Collection + * classes should clearly specify in their documentation any restrictions + * on what elements may be added. + * + * If a collection refuses to add a particular element for any reason other + * than that it already contains the element, it must throw an exception + * (rather than returning `false`). This preserves the invariant that a + * collection always contains the specified element after this call returns. + * + * @param T $element The element to add to the collection. + * + * @return bool `true` if this collection changed as a result of the call. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function add($element): bool; + + /** + * Returns `true` if this collection contains the specified element. + * + * @param T $element The element to check whether the collection contains. + * @param bool $strict Whether to perform a strict type check on the value. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function contains($element, bool $strict = true): bool; + + /** + * Returns the type associated with this collection. + */ + public function getType(): string; + + /** + * Removes a single instance of the specified element from this collection, + * if it is present. + * + * @param T $element The element to remove from the collection. + * + * @return bool `true` if an element was removed as a result of this call. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function remove($element): bool; + + /** + * Returns the values from the given property or method. + * + * @param string $propertyOrMethod The property or method name to filter by. + * + * @return list + */ + public function column(string $propertyOrMethod): array; + + /** + * Returns the first item of the collection. + * + * @return T + */ + public function first(); + + /** + * Returns the last item of the collection. + * + * @return T + */ + public function last(); + + /** + * Sort the collection by a property or method with the given sort order. + * + * This will always leave the original collection untouched and will return + * a new one. + * + * @param string $propertyOrMethod The property or method to sort by. + * @param string $order The sort order for the resulting collection (one of + * this interface's `SORT_*` constants). + * + * @return CollectionInterface + */ + public function sort(string $propertyOrMethod, string $order = self::SORT_ASC): self; + + /** + * Filter out items of the collection which don't match the criteria of + * given callback. + * + * This will always leave the original collection untouched and will return + * a new one. + * + * See the {@link http://php.net/manual/en/function.array-filter.php PHP array_filter() documentation} + * for examples of how the `$callback` parameter works. + * + * @param callable(T):bool $callback A callable to use for filtering elements. + * + * @return CollectionInterface + */ + public function filter(callable $callback): self; + + /** + * Create a new collection where items match the criteria of given callback. + * + * This will always leave the original collection untouched and will return + * a new one. + * + * @param string $propertyOrMethod The property or method to evaluate. + * @param mixed $value The value to match. + * + * @return CollectionInterface + */ + public function where(string $propertyOrMethod, $value): self; + + /** + * Apply a given callback method on each item of the collection. + * + * This will always leave the original collection untouched. The new + * collection is created by mapping the callback to each item of the + * original collection. + * + * See the {@link http://php.net/manual/en/function.array-map.php PHP array_map() documentation} + * for examples of how the `$callback` parameter works. + * + * @param callable(T):TCallbackReturn $callback A callable to apply to each + * item of the collection. + * + * @return CollectionInterface + * + * @template TCallbackReturn + */ + public function map(callable $callback): self; + + /** + * Create a new collection with divergent items between current and given + * collection. + * + * @param CollectionInterface $other The collection to check for divergent + * items. + * + * @return CollectionInterface + */ + public function diff(CollectionInterface $other): self; + + /** + * Create a new collection with intersecting item between current and given + * collection. + * + * @param CollectionInterface $other The collection to check for + * intersecting items. + * + * @return CollectionInterface + */ + public function intersect(CollectionInterface $other): self; + + /** + * Merge current items and items of given collections into a new one. + * + * @param CollectionInterface ...$collections The collections to merge. + * + * @return CollectionInterface + */ + public function merge(CollectionInterface ...$collections): self; +} diff --git a/vendor/ramsey/collection/src/DoubleEndedQueue.php b/vendor/ramsey/collection/src/DoubleEndedQueue.php new file mode 100644 index 0000000..c9c5950 --- /dev/null +++ b/vendor/ramsey/collection/src/DoubleEndedQueue.php @@ -0,0 +1,187 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +use Ramsey\Collection\Exception\InvalidArgumentException; +use Ramsey\Collection\Exception\NoSuchElementException; + +/** + * This class provides a basic implementation of `DoubleEndedQueueInterface`, to + * minimize the effort required to implement this interface. + * + * @template T + * @extends Queue + * @implements DoubleEndedQueueInterface + */ +class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface +{ + /** + * Index of the last element in the queue. + * + * @var int + */ + private $tail = -1; + + /** + * @inheritDoc + */ + public function offsetSet($offset, $value): void + { + if ($this->checkType($this->getType(), $value) === false) { + throw new InvalidArgumentException( + 'Value must be of type ' . $this->getType() . '; value is ' + . $this->toolValueToString($value) + ); + } + + $this->tail++; + + $this->data[$this->tail] = $value; + } + + /** + * @inheritDoc + */ + public function addFirst($element): bool + { + if ($this->checkType($this->getType(), $element) === false) { + throw new InvalidArgumentException( + 'Value must be of type ' . $this->getType() . '; value is ' + . $this->toolValueToString($element) + ); + } + + $this->index--; + + $this->data[$this->index] = $element; + + return true; + } + + /** + * @inheritDoc + */ + public function addLast($element): bool + { + return $this->add($element); + } + + /** + * @inheritDoc + */ + public function offerFirst($element): bool + { + try { + return $this->addFirst($element); + } catch (InvalidArgumentException $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function offerLast($element): bool + { + return $this->offer($element); + } + + /** + * @inheritDoc + */ + public function removeFirst() + { + return $this->remove(); + } + + /** + * @inheritDoc + */ + public function removeLast() + { + $tail = $this->pollLast(); + + if ($tail === null) { + throw new NoSuchElementException('Can\'t return element from Queue. Queue is empty.'); + } + + return $tail; + } + + /** + * @inheritDoc + */ + public function pollFirst() + { + return $this->poll(); + } + + /** + * @inheritDoc + */ + public function pollLast() + { + if ($this->count() === 0) { + return null; + } + + $tail = $this[$this->tail]; + + unset($this[$this->tail]); + $this->tail--; + + return $tail; + } + + /** + * @inheritDoc + */ + public function firstElement() + { + return $this->element(); + } + + /** + * @inheritDoc + */ + public function lastElement() + { + if ($this->count() === 0) { + throw new NoSuchElementException('Can\'t return element from Queue. Queue is empty.'); + } + + return $this->data[$this->tail]; + } + + /** + * @inheritDoc + */ + public function peekFirst() + { + return $this->peek(); + } + + /** + * @inheritDoc + */ + public function peekLast() + { + if ($this->count() === 0) { + return null; + } + + return $this->data[$this->tail]; + } +} diff --git a/vendor/ramsey/collection/src/DoubleEndedQueueInterface.php b/vendor/ramsey/collection/src/DoubleEndedQueueInterface.php new file mode 100644 index 0000000..d7df534 --- /dev/null +++ b/vendor/ramsey/collection/src/DoubleEndedQueueInterface.php @@ -0,0 +1,316 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +use Ramsey\Collection\Exception\NoSuchElementException; + +/** + * A linear collection that supports element insertion and removal at both ends. + * + * Most `DoubleEndedQueueInterface` implementations place no fixed limits on the + * number of elements they may contain, but this interface supports + * capacity-restricted double-ended queues as well as those with no fixed size + * limit. + * + * This interface defines methods to access the elements at both ends of the + * double-ended queue. Methods are provided to insert, remove, and examine the + * element. Each of these methods exists in two forms: one throws an exception + * if the operation fails, the other returns a special value (either `null` or + * `false`, depending on the operation). The latter form of the insert operation + * is designed specifically for use with capacity-restricted implementations; in + * most implementations, insert operations cannot fail. + * + * The twelve methods described above are summarized in the following table: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Summary of DoubleEndedQueueInterface methods
First Element (Head)Last Element (Tail)
Throws exceptionSpecial valueThrows exceptionSpecial value
InsertaddFirst()offerFirst()addLast()offerLast()
RemoveremoveFirst()pollFirst()removeLast()pollLast()
ExaminefirstElement()peekFirst()lastElement()peekLast()
+ * + * This interface extends the `QueueInterface`. When a double-ended queue is + * used as a queue, FIFO (first-in-first-out) behavior results. Elements are + * added at the end of the double-ended queue and removed from the beginning. + * The methods inherited from the `QueueInterface` are precisely equivalent to + * `DoubleEndedQueueInterface` methods as indicated in the following table: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Comparison of QueueInterface and DoubleEndedQueueInterface methods
QueueInterface MethodDoubleEndedQueueInterface Method
add()addLast()
offer()offerLast()
remove()removeFirst()
poll()pollFirst()
element()firstElement()
peek()peekFirst()
+ * + * Double-ended queues can also be used as LIFO (last-in-first-out) stacks. When + * a double-ended queue is used as a stack, elements are pushed and popped from + * the beginning of the double-ended queue. Stack concepts are precisely + * equivalent to `DoubleEndedQueueInterface` methods as indicated in the table + * below: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Comparison of stack concepts and DoubleEndedQueueInterface methods
Stack conceptDoubleEndedQueueInterface Method
pushaddFirst()
popremoveFirst()
peekpeekFirst()
+ * + * Note that the `peek()` method works equally well when a double-ended queue is + * used as a queue or a stack; in either case, elements are drawn from the + * beginning of the double-ended queue. + * + * While `DoubleEndedQueueInterface` implementations are not strictly required + * to prohibit the insertion of `null` elements, they are strongly encouraged to + * do so. Users of any `DoubleEndedQueueInterface` implementations that do allow + * `null` elements are strongly encouraged *not* to take advantage of the + * ability to insert nulls. This is so because `null` is used as a special + * return value by various methods to indicated that the double-ended queue is + * empty. + * + * @template T + * @extends QueueInterface + */ +interface DoubleEndedQueueInterface extends QueueInterface +{ + /** + * Inserts the specified element at the front of this queue if it is + * possible to do so immediately without violating capacity restrictions. + * + * When using a capacity-restricted double-ended queue, it is generally + * preferable to use the `offerFirst()` method. + * + * @param T $element The element to add to the front of this queue. + * + * @return bool `true` if this queue changed as a result of the call. + * + * @throws \RuntimeException if a queue refuses to add a particular element + * for any reason other than that it already contains the element. + * Implementations should use a more-specific exception that extends + * `\RuntimeException`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function addFirst($element): bool; + + /** + * Inserts the specified element at the end of this queue if it is possible + * to do so immediately without violating capacity restrictions. + * + * When using a capacity-restricted double-ended queue, it is generally + * preferable to use the `offerLast()` method. + * + * This method is equivalent to `add()`. + * + * @param T $element The element to add to the end of this queue. + * + * @return bool `true` if this queue changed as a result of the call. + * + * @throws \RuntimeException if a queue refuses to add a particular element + * for any reason other than that it already contains the element. + * Implementations should use a more-specific exception that extends + * `\RuntimeException`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function addLast($element): bool; + + /** + * Inserts the specified element at the front of this queue if it is + * possible to do so immediately without violating capacity restrictions. + * + * When using a capacity-restricted queue, this method is generally + * preferable to `addFirst()`, which can fail to insert an element only by + * throwing an exception. + * + * @param T $element The element to add to the front of this queue. + * + * @return bool `true` if the element was added to this queue, else `false`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function offerFirst($element): bool; + + /** + * Inserts the specified element at the end of this queue if it is possible + * to do so immediately without violating capacity restrictions. + * + * When using a capacity-restricted queue, this method is generally + * preferable to `addLast()` which can fail to insert an element only by + * throwing an exception. + * + * @param T $element The element to add to the end of this queue. + * + * @return bool `true` if the element was added to this queue, else `false`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function offerLast($element): bool; + + /** + * Retrieves and removes the head of this queue. + * + * This method differs from `pollFirst()` only in that it throws an + * exception if this queue is empty. + * + * @return T the first element in this queue. + * + * @throws NoSuchElementException if this queue is empty. + */ + public function removeFirst(); + + /** + * Retrieves and removes the tail of this queue. + * + * This method differs from `pollLast()` only in that it throws an exception + * if this queue is empty. + * + * @return T the last element in this queue. + * + * @throws NoSuchElementException if this queue is empty. + */ + public function removeLast(); + + /** + * Retrieves and removes the head of this queue, or returns `null` if this + * queue is empty. + * + * @return T|null the head of this queue, or `null` if this queue is empty. + */ + public function pollFirst(); + + /** + * Retrieves and removes the tail of this queue, or returns `null` if this + * queue is empty. + * + * @return T|null the tail of this queue, or `null` if this queue is empty. + */ + public function pollLast(); + + /** + * Retrieves, but does not remove, the head of this queue. + * + * This method differs from `peekFirst()` only in that it throws an + * exception if this queue is empty. + * + * @return T the head of this queue. + * + * @throws NoSuchElementException if this queue is empty. + */ + public function firstElement(); + + /** + * Retrieves, but does not remove, the tail of this queue. + * + * This method differs from `peekLast()` only in that it throws an exception + * if this queue is empty. + * + * @return T the tail of this queue. + * + * @throws NoSuchElementException if this queue is empty. + */ + public function lastElement(); + + /** + * Retrieves, but does not remove, the head of this queue, or returns `null` + * if this queue is empty. + * + * @return T|null the head of this queue, or `null` if this queue is empty. + */ + public function peekFirst(); + + /** + * Retrieves, but does not remove, the tail of this queue, or returns `null` + * if this queue is empty. + * + * @return T|null the tail of this queue, or `null` if this queue is empty. + */ + public function peekLast(); +} diff --git a/vendor/ramsey/collection/src/Exception/CollectionMismatchException.php b/vendor/ramsey/collection/src/Exception/CollectionMismatchException.php new file mode 100644 index 0000000..d4b335f --- /dev/null +++ b/vendor/ramsey/collection/src/Exception/CollectionMismatchException.php @@ -0,0 +1,22 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Exception; + +/** + * Thrown when attempting to operate on collections of differing types. + */ +class CollectionMismatchException extends \RuntimeException +{ +} diff --git a/vendor/ramsey/collection/src/Exception/InvalidArgumentException.php b/vendor/ramsey/collection/src/Exception/InvalidArgumentException.php new file mode 100644 index 0000000..dcc3eac --- /dev/null +++ b/vendor/ramsey/collection/src/Exception/InvalidArgumentException.php @@ -0,0 +1,22 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Exception; + +/** + * Thrown to indicate an argument is not of the expected type. + */ +class InvalidArgumentException extends \InvalidArgumentException +{ +} diff --git a/vendor/ramsey/collection/src/Exception/InvalidSortOrderException.php b/vendor/ramsey/collection/src/Exception/InvalidSortOrderException.php new file mode 100644 index 0000000..9337ccc --- /dev/null +++ b/vendor/ramsey/collection/src/Exception/InvalidSortOrderException.php @@ -0,0 +1,22 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Exception; + +/** + * Thrown when attempting to use a sort order that is not recognized. + */ +class InvalidSortOrderException extends \RuntimeException +{ +} diff --git a/vendor/ramsey/collection/src/Exception/NoSuchElementException.php b/vendor/ramsey/collection/src/Exception/NoSuchElementException.php new file mode 100644 index 0000000..9debe8f --- /dev/null +++ b/vendor/ramsey/collection/src/Exception/NoSuchElementException.php @@ -0,0 +1,22 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Exception; + +/** + * Thrown when attempting to access an element that does not exist. + */ +class NoSuchElementException extends \RuntimeException +{ +} diff --git a/vendor/ramsey/collection/src/Exception/OutOfBoundsException.php b/vendor/ramsey/collection/src/Exception/OutOfBoundsException.php new file mode 100644 index 0000000..4e9d16f --- /dev/null +++ b/vendor/ramsey/collection/src/Exception/OutOfBoundsException.php @@ -0,0 +1,22 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Exception; + +/** + * Thrown when attempting to access an element out of the range of the collection. + */ +class OutOfBoundsException extends \OutOfBoundsException +{ +} diff --git a/vendor/ramsey/collection/src/Exception/UnsupportedOperationException.php b/vendor/ramsey/collection/src/Exception/UnsupportedOperationException.php new file mode 100644 index 0000000..8f45e58 --- /dev/null +++ b/vendor/ramsey/collection/src/Exception/UnsupportedOperationException.php @@ -0,0 +1,22 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Exception; + +/** + * Thrown to indicate that the requested operation is not supported. + */ +class UnsupportedOperationException extends \RuntimeException +{ +} diff --git a/vendor/ramsey/collection/src/Exception/ValueExtractionException.php b/vendor/ramsey/collection/src/Exception/ValueExtractionException.php new file mode 100644 index 0000000..f6c6cb4 --- /dev/null +++ b/vendor/ramsey/collection/src/Exception/ValueExtractionException.php @@ -0,0 +1,22 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Exception; + +/** + * Thrown when attempting to extract a value for a method or property that does not exist. + */ +class ValueExtractionException extends \RuntimeException +{ +} diff --git a/vendor/ramsey/collection/src/GenericArray.php b/vendor/ramsey/collection/src/GenericArray.php new file mode 100644 index 0000000..2b079aa --- /dev/null +++ b/vendor/ramsey/collection/src/GenericArray.php @@ -0,0 +1,24 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +/** + * `GenericArray` represents a standard array object. + * + * @extends AbstractArray + */ +class GenericArray extends AbstractArray +{ +} diff --git a/vendor/ramsey/collection/src/Map/AbstractMap.php b/vendor/ramsey/collection/src/Map/AbstractMap.php new file mode 100644 index 0000000..ae9f2fe --- /dev/null +++ b/vendor/ramsey/collection/src/Map/AbstractMap.php @@ -0,0 +1,162 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Map; + +use Ramsey\Collection\AbstractArray; +use Ramsey\Collection\Exception\InvalidArgumentException; + +use function array_key_exists; +use function array_keys; +use function in_array; + +/** + * This class provides a basic implementation of `MapInterface`, to minimize the + * effort required to implement this interface. + * + * @template T + * @extends AbstractArray + * @implements MapInterface + */ +abstract class AbstractMap extends AbstractArray implements MapInterface +{ + /** + * @inheritDoc + */ + public function offsetSet($offset, $value): void + { + if ($offset === null) { + throw new InvalidArgumentException( + 'Map elements are key/value pairs; a key must be provided for ' + . 'value ' . var_export($value, true) + ); + } + + $this->data[$offset] = $value; + } + + /** + * @inheritDoc + */ + public function containsKey($key): bool + { + return array_key_exists($key, $this->data); + } + + /** + * @inheritDoc + */ + public function containsValue($value): bool + { + return in_array($value, $this->data, true); + } + + /** + * @inheritDoc + */ + public function keys(): array + { + return array_keys($this->data); + } + + /** + * @inheritDoc + */ + public function get($key, $defaultValue = null) + { + if (!$this->containsKey($key)) { + return $defaultValue; + } + + return $this[$key]; + } + + /** + * @inheritDoc + */ + public function put($key, $value) + { + $previousValue = $this->get($key); + $this[$key] = $value; + + return $previousValue; + } + + /** + * @inheritDoc + */ + public function putIfAbsent($key, $value) + { + $currentValue = $this->get($key); + + if ($currentValue === null) { + $this[$key] = $value; + } + + return $currentValue; + } + + /** + * @inheritDoc + */ + public function remove($key) + { + $previousValue = $this->get($key); + unset($this[$key]); + + return $previousValue; + } + + /** + * @inheritDoc + */ + public function removeIf($key, $value): bool + { + if ($this->get($key) === $value) { + unset($this[$key]); + + return true; + } + + return false; + } + + /** + * @inheritDoc + */ + public function replace($key, $value) + { + $currentValue = $this->get($key); + + if ($this->containsKey($key)) { + $this[$key] = $value; + } + + return $currentValue; + } + + /** + * @inheritDoc + */ + public function replaceIf($key, $oldValue, $newValue): bool + { + if ($this->get($key) === $oldValue) { + $this[$key] = $newValue; + + return true; + } + + return false; + } +} diff --git a/vendor/ramsey/collection/src/Map/AbstractTypedMap.php b/vendor/ramsey/collection/src/Map/AbstractTypedMap.php new file mode 100644 index 0000000..551d2e6 --- /dev/null +++ b/vendor/ramsey/collection/src/Map/AbstractTypedMap.php @@ -0,0 +1,69 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Map; + +use Ramsey\Collection\Exception\InvalidArgumentException; +use Ramsey\Collection\Tool\TypeTrait; +use Ramsey\Collection\Tool\ValueToStringTrait; + +/** + * This class provides a basic implementation of `TypedMapInterface`, to + * minimize the effort required to implement this interface. + * + * @template K + * @template T + * @extends AbstractMap + * @implements TypedMapInterface + */ +abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface +{ + use TypeTrait; + use ValueToStringTrait; + + /** + * @param K|null $offset + * @param T $value + * + * @inheritDoc + * + * @psalm-suppress MoreSpecificImplementedParamType + */ + public function offsetSet($offset, $value): void + { + if ($offset === null) { + throw new InvalidArgumentException( + 'Map elements are key/value pairs; a key must be provided for ' + . 'value ' . var_export($value, true) + ); + } + + if ($this->checkType($this->getKeyType(), $offset) === false) { + throw new InvalidArgumentException( + 'Key must be of type ' . $this->getKeyType() . '; key is ' + . $this->toolValueToString($offset) + ); + } + + if ($this->checkType($this->getValueType(), $value) === false) { + throw new InvalidArgumentException( + 'Value must be of type ' . $this->getValueType() . '; value is ' + . $this->toolValueToString($value) + ); + } + + /** @psalm-suppress MixedArgumentTypeCoercion */ + parent::offsetSet($offset, $value); + } +} diff --git a/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php b/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php new file mode 100644 index 0000000..79a314d --- /dev/null +++ b/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php @@ -0,0 +1,25 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Map; + +/** + * `AssociativeArrayMap` represents a standard associative array object. + * + * @template T + * @extends AbstractMap + */ +class AssociativeArrayMap extends AbstractMap +{ +} diff --git a/vendor/ramsey/collection/src/Map/MapInterface.php b/vendor/ramsey/collection/src/Map/MapInterface.php new file mode 100644 index 0000000..6ed0b29 --- /dev/null +++ b/vendor/ramsey/collection/src/Map/MapInterface.php @@ -0,0 +1,149 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Map; + +use Ramsey\Collection\ArrayInterface; + +/** + * An object that maps keys to values. + * + * A map cannot contain duplicate keys; each key can map to at most one value. + * + * @template T + * @extends ArrayInterface + */ +interface MapInterface extends ArrayInterface +{ + /** + * Returns `true` if this map contains a mapping for the specified key. + * + * @param array-key $key The key to check in the map. + */ + public function containsKey($key): bool; + + /** + * Returns `true` if this map maps one or more keys to the specified value. + * + * This performs a strict type check on the value. + * + * @param T $value The value to check in the map. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function containsValue($value): bool; + + /** + * Return an array of the keys contained in this map. + * + * @return list + */ + public function keys(): array; + + /** + * Returns the value to which the specified key is mapped, `null` if this + * map contains no mapping for the key, or (optionally) `$defaultValue` if + * this map contains no mapping for the key. + * + * @param array-key $key The key to return from the map. + * @param T|null $defaultValue The default value to use if `$key` is not found. + * + * @return T|null the value or `null` if the key could not be found. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function get($key, $defaultValue = null); + + /** + * Associates the specified value with the specified key in this map. + * + * If the map previously contained a mapping for the key, the old value is + * replaced by the specified value. + * + * @param array-key $key The key to put or replace in the map. + * @param T $value The value to store at `$key`. + * + * @return T|null the previous value associated with key, or `null` if + * there was no mapping for `$key`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function put($key, $value); + + /** + * Associates the specified value with the specified key in this map only if + * it is not already set. + * + * If there is already a value associated with `$key`, this returns that + * value without replacing it. + * + * @param array-key $key The key to put in the map. + * @param T $value The value to store at `$key`. + * + * @return T|null the previous value associated with key, or `null` if + * there was no mapping for `$key`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function putIfAbsent($key, $value); + + /** + * Removes the mapping for a key from this map if it is present. + * + * @param array-key $key The key to remove from the map. + * + * @return T|null the previous value associated with key, or `null` if + * there was no mapping for `$key`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function remove($key); + + /** + * Removes the entry for the specified key only if it is currently mapped to + * the specified value. + * + * This performs a strict type check on the value. + * + * @param array-key $key The key to remove from the map. + * @param T $value The value to match. + * + * @return bool true if the value was removed. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function removeIf($key, $value): bool; + + /** + * Replaces the entry for the specified key only if it is currently mapped + * to some value. + * + * @param array-key $key The key to replace. + * @param T $value The value to set at `$key`. + * + * @return T|null the previous value associated with key, or `null` if + * there was no mapping for `$key`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function replace($key, $value); + + /** + * Replaces the entry for the specified key only if currently mapped to the + * specified value. + * + * This performs a strict type check on the value. + * + * @param array-key $key The key to remove from the map. + * @param T $oldValue The value to match. + * @param T $newValue The value to use as a replacement. + * + * @return bool true if the value was replaced. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function replaceIf($key, $oldValue, $newValue): bool; +} diff --git a/vendor/ramsey/collection/src/Map/NamedParameterMap.php b/vendor/ramsey/collection/src/Map/NamedParameterMap.php new file mode 100644 index 0000000..9926ddd --- /dev/null +++ b/vendor/ramsey/collection/src/Map/NamedParameterMap.php @@ -0,0 +1,120 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Map; + +use Ramsey\Collection\Exception\InvalidArgumentException; +use Ramsey\Collection\Tool\TypeTrait; +use Ramsey\Collection\Tool\ValueToStringTrait; + +use function array_combine; +use function array_key_exists; +use function is_int; + +/** + * `NamedParameterMap` represents a mapping of values to a set of named keys + * that may optionally be typed + * + * @extends AbstractMap + */ +class NamedParameterMap extends AbstractMap +{ + use TypeTrait; + use ValueToStringTrait; + + /** + * Named parameters defined for this map. + * + * @var array + */ + protected $namedParameters; + + /** + * Constructs a new `NamedParameterMap`. + * + * @param array $namedParameters The named parameters defined for this map. + * @param array $data An initial set of data to set on this map. + */ + public function __construct(array $namedParameters, array $data = []) + { + $this->namedParameters = $this->filterNamedParameters($namedParameters); + parent::__construct($data); + } + + /** + * Returns named parameters set for this `NamedParameterMap`. + * + * @return array + */ + public function getNamedParameters(): array + { + return $this->namedParameters; + } + + /** + * @inheritDoc + */ + public function offsetSet($offset, $value): void + { + if ($offset === null) { + throw new InvalidArgumentException( + 'Map elements are key/value pairs; a key must be provided for ' + . 'value ' . var_export($value, true) + ); + } + + if (!array_key_exists($offset, $this->namedParameters)) { + throw new InvalidArgumentException( + 'Attempting to set value for unconfigured parameter \'' + . $offset . '\'' + ); + } + + if ($this->checkType($this->namedParameters[$offset], $value) === false) { + throw new InvalidArgumentException( + 'Value for \'' . $offset . '\' must be of type ' + . $this->namedParameters[$offset] . '; value is ' + . $this->toolValueToString($value) + ); + } + + $this->data[$offset] = $value; + } + + /** + * Given an array of named parameters, constructs a proper mapping of + * named parameters to types. + * + * @param array $namedParameters The named parameters to filter. + * + * @return array + */ + protected function filterNamedParameters(array $namedParameters): array + { + $names = []; + $types = []; + + foreach ($namedParameters as $key => $value) { + if (is_int($key)) { + $names[] = $value; + $types[] = 'mixed'; + } else { + $names[] = $key; + $types[] = $value; + } + } + + return array_combine($names, $types) ?: []; + } +} diff --git a/vendor/ramsey/collection/src/Map/TypedMap.php b/vendor/ramsey/collection/src/Map/TypedMap.php new file mode 100644 index 0000000..2e79637 --- /dev/null +++ b/vendor/ramsey/collection/src/Map/TypedMap.php @@ -0,0 +1,137 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Map; + +use Ramsey\Collection\Tool\TypeTrait; + +/** + * A `TypedMap` represents a map of elements where key and value are typed. + * + * Each element is identified by a key with defined type and a value of defined + * type. The keys of the map must be unique. The values on the map can be= + * repeated but each with its own different key. + * + * The most common case is to use a string type key, but it's not limited to + * this type of keys. + * + * This is a direct implementation of `TypedMapInterface`, provided for the sake + * of convenience. + * + * Example usage: + * + * ```php + * $map = new TypedMap('string', Foo::class); + * $map['x'] = new Foo(); + * foreach ($map as $key => $value) { + * // do something with $key, it will be a Foo::class + * } + * + * // this will throw an exception since key must be string + * $map[10] = new Foo(); + * + * // this will throw an exception since value must be a Foo + * $map['bar'] = 'bar'; + * + * // initialize map with contents + * $map = new TypedMap('string', Foo::class, [ + * new Foo(), new Foo(), new Foo() + * ]); + * ``` + * + * It is preferable to subclass `AbstractTypedMap` to create your own typed map + * implementation: + * + * ```php + * class FooTypedMap extends AbstractTypedMap + * { + * public function getKeyType() + * { + * return 'int'; + * } + * + * public function getValueType() + * { + * return Foo::class; + * } + * } + * ``` + * + * … but you also may use the `TypedMap` class: + * + * ```php + * class FooTypedMap extends TypedMap + * { + * public function __constructor(array $data = []) + * { + * parent::__construct('int', Foo::class, $data); + * } + * } + * ``` + * + * @template K + * @template T + * @extends AbstractTypedMap + */ +class TypedMap extends AbstractTypedMap +{ + use TypeTrait; + + /** + * The data type of keys stored in this collection. + * + * A map key's type is immutable once it is set. For this reason, this + * property is set private. + * + * @var string data type of the map key. + */ + private $keyType; + + /** + * The data type of values stored in this collection. + * + * A map value's type is immutable once it is set. For this reason, this + * property is set private. + * + * @var string data type of the map value. + */ + private $valueType; + + /** + * Constructs a map object of the specified key and value types, + * optionally with the specified data. + * + * @param string $keyType The data type of the map's keys. + * @param string $valueType The data type of the map's values. + * @param array $data The initial data to set for this map. + */ + public function __construct(string $keyType, string $valueType, array $data = []) + { + $this->keyType = $keyType; + $this->valueType = $valueType; + + /** @psalm-suppress MixedArgumentTypeCoercion */ + parent::__construct($data); + } + + public function getKeyType(): string + { + return $this->keyType; + } + + public function getValueType(): string + { + return $this->valueType; + } +} diff --git a/vendor/ramsey/collection/src/Map/TypedMapInterface.php b/vendor/ramsey/collection/src/Map/TypedMapInterface.php new file mode 100644 index 0000000..0308109 --- /dev/null +++ b/vendor/ramsey/collection/src/Map/TypedMapInterface.php @@ -0,0 +1,35 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Map; + +/** + * A `TypedMapInterface` represents a map of elements where key and value are + * typed. + * + * @template T + * @extends MapInterface + */ +interface TypedMapInterface extends MapInterface +{ + /** + * Return the type used on the key. + */ + public function getKeyType(): string; + + /** + * Return the type forced on the values. + */ + public function getValueType(): string; +} diff --git a/vendor/ramsey/collection/src/Queue.php b/vendor/ramsey/collection/src/Queue.php new file mode 100644 index 0000000..93e032b --- /dev/null +++ b/vendor/ramsey/collection/src/Queue.php @@ -0,0 +1,169 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +use Ramsey\Collection\Exception\InvalidArgumentException; +use Ramsey\Collection\Exception\NoSuchElementException; +use Ramsey\Collection\Tool\TypeTrait; +use Ramsey\Collection\Tool\ValueToStringTrait; + +/** + * This class provides a basic implementation of `QueueInterface`, to minimize + * the effort required to implement this interface. + * + * @template T + * @extends AbstractArray + * @implements QueueInterface + */ +class Queue extends AbstractArray implements QueueInterface +{ + use TypeTrait; + use ValueToStringTrait; + + /** + * The type of elements stored in this queue. + * + * A queue's type is immutable once it is set. For this reason, this + * property is set private. + * + * @var string + */ + private $queueType; + + /** + * The index of the head of the queue. + * + * @var int + */ + protected $index = 0; + + /** + * Constructs a queue object of the specified type, optionally with the + * specified data. + * + * @param string $queueType The type (FQCN) associated with this queue. + * @param array $data The initial items to store in the collection. + */ + public function __construct(string $queueType, array $data = []) + { + $this->queueType = $queueType; + parent::__construct($data); + } + + /** + * {@inheritDoc} + * + * Since arbitrary offsets may not be manipulated in a queue, this method + * serves only to fulfill the `ArrayAccess` interface requirements. It is + * invoked by other operations when adding values to the queue. + */ + public function offsetSet($offset, $value): void + { + if ($this->checkType($this->getType(), $value) === false) { + throw new InvalidArgumentException( + 'Value must be of type ' . $this->getType() . '; value is ' + . $this->toolValueToString($value) + ); + } + + $this->data[] = $value; + } + + /** + * @inheritDoc + */ + public function add($element): bool + { + $this[] = $element; + + return true; + } + + /** + * @inheritDoc + */ + public function element() + { + $element = $this->peek(); + + if ($element === null) { + throw new NoSuchElementException( + 'Can\'t return element from Queue. Queue is empty.' + ); + } + + return $element; + } + + /** + * @inheritDoc + */ + public function offer($element): bool + { + try { + return $this->add($element); + } catch (InvalidArgumentException $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function peek() + { + if ($this->count() === 0) { + return null; + } + + return $this[$this->index]; + } + + /** + * @inheritDoc + */ + public function poll() + { + if ($this->count() === 0) { + return null; + } + + $head = $this[$this->index]; + + unset($this[$this->index]); + $this->index++; + + return $head; + } + + /** + * @inheritDoc + */ + public function remove() + { + $head = $this->poll(); + + if ($head === null) { + throw new NoSuchElementException('Can\'t return element from Queue. Queue is empty.'); + } + + return $head; + } + + public function getType(): string + { + return $this->queueType; + } +} diff --git a/vendor/ramsey/collection/src/QueueInterface.php b/vendor/ramsey/collection/src/QueueInterface.php new file mode 100644 index 0000000..8c7383d --- /dev/null +++ b/vendor/ramsey/collection/src/QueueInterface.php @@ -0,0 +1,203 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +use Ramsey\Collection\Exception\NoSuchElementException; + +/** + * A queue is a collection in which the entities in the collection are kept in + * order. + * + * The principal operations on the queue are the addition of entities to the end + * (tail), also known as *enqueue*, and removal of entities from the front + * (head), also known as *dequeue*. This makes the queue a first-in-first-out + * (FIFO) data structure. + * + * Besides basic array operations, queues provide additional insertion, + * extraction, and inspection operations. Each of these methods exists in two + * forms: one throws an exception if the operation fails, the other returns a + * special value (either `null` or `false`, depending on the operation). The + * latter form of the insert operation is designed specifically for use with + * capacity-restricted `QueueInterface` implementations; in most + * implementations, insert operations cannot fail. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Summary of QueueInterface methods
Throws exceptionReturns special value
Insertadd()offer()
Removeremove()poll()
Examineelement()peek()
+ * + * Queues typically, but do not necessarily, order elements in a FIFO + * (first-in-first-out) manner. Among the exceptions are priority queues, which + * order elements according to a supplied comparator, or the elements' natural + * ordering, and LIFO queues (or stacks) which order the elements LIFO + * (last-in-first-out). Whatever the ordering used, the head of the queue is + * that element which would be removed by a call to remove() or poll(). In a + * FIFO queue, all new elements are inserted at the tail of the queue. Other + * kinds of queues may use different placement rules. Every `QueueInterface` + * implementation must specify its ordering properties. + * + * The `offer()` method inserts an element if possible, otherwise returning + * `false`. This differs from the `add()` method, which can fail to add an + * element only by throwing an unchecked exception. The `offer()` method is + * designed for use when failure is a normal, rather than exceptional + * occurrence, for example, in fixed-capacity (or "bounded") queues. + * + * The `remove()` and `poll()` methods remove and return the head of the queue. + * Exactly which element is removed from the queue is a function of the queue's + * ordering policy, which differs from implementation to implementation. The + * `remove()` and `poll()` methods differ only in their behavior when the queue + * is empty: the `remove()` method throws an exception, while the `poll()` + * method returns `null`. + * + * The `element()` and `peek()` methods return, but do not remove, the head of + * the queue. + * + * `QueueInterface` implementations generally do not allow insertion of `null` + * elements, although some implementations do not prohibit insertion of `null`. + * Even in the implementations that permit it, `null` should not be inserted + * into a queue, as `null` is also used as a special return value by the + * `poll()` method to indicate that the queue contains no elements. + * + * @template T + * @extends ArrayInterface + */ +interface QueueInterface extends ArrayInterface +{ + /** + * Ensures that this queue contains the specified element (optional + * operation). + * + * Returns `true` if this queue changed as a result of the call. (Returns + * `false` if this queue does not permit duplicates and already contains the + * specified element.) + * + * Queues that support this operation may place limitations on what elements + * may be added to this queue. In particular, some queues will refuse to add + * `null` elements, and others will impose restrictions on the type of + * elements that may be added. Queue classes should clearly specify in their + * documentation any restrictions on what elements may be added. + * + * If a queue refuses to add a particular element for any reason other than + * that it already contains the element, it must throw an exception (rather + * than returning `false`). This preserves the invariant that a queue always + * contains the specified element after this call returns. + * + * @see self::offer() + * + * @param T $element The element to add to this queue. + * + * @return bool `true` if this queue changed as a result of the call. + * + * @throws \RuntimeException if a queue refuses to add a particular element + * for any reason other than that it already contains the element. + * Implementations should use a more-specific exception that extends + * `\RuntimeException`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function add($element): bool; + + /** + * Retrieves, but does not remove, the head of this queue. + * + * This method differs from `peek()` only in that it throws an exception if + * this queue is empty. + * + * @see self::peek() + * + * @return T the head of this queue. + * + * @throws NoSuchElementException if this queue is empty. + */ + public function element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. + * + * When using a capacity-restricted queue, this method is generally + * preferable to `add()`, which can fail to insert an element only by + * throwing an exception. + * + * @see self::add() + * + * @param T $element The element to add to this queue. + * + * @return bool `true` if the element was added to this queue, else `false`. + */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function offer($element): bool; + + /** + * Retrieves, but does not remove, the head of this queue, or returns `null` + * if this queue is empty. + * + * @see self::element() + * + * @return T|null the head of this queue, or `null` if this queue is empty. + */ + public function peek(); + + /** + * Retrieves and removes the head of this queue, or returns `null` + * if this queue is empty. + * + * @see self::remove() + * + * @return T|null the head of this queue, or `null` if this queue is empty. + */ + public function poll(); + + /** + * Retrieves and removes the head of this queue. + * + * This method differs from `poll()` only in that it throws an exception if + * this queue is empty. + * + * @see self::poll() + * + * @return T the head of this queue. + * + * @throws NoSuchElementException if this queue is empty. + */ + public function remove(); + + /** + * Returns the type associated with this queue. + */ + public function getType(): string; +} diff --git a/vendor/ramsey/collection/src/Set.php b/vendor/ramsey/collection/src/Set.php new file mode 100644 index 0000000..6932f24 --- /dev/null +++ b/vendor/ramsey/collection/src/Set.php @@ -0,0 +1,69 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection; + +/** + * A set is a collection that contains no duplicate elements. + * + * Great care must be exercised if mutable objects are used as set elements. + * The behavior of a set is not specified if the value of an object is changed + * in a manner that affects equals comparisons while the object is an element in + * the set. + * + * Example usage: + * + * ``` php + * $foo = new \My\Foo(); + * $set = new Set(\My\Foo::class); + * + * $set->add($foo); // returns TRUE, the element don't exists + * $set->add($foo); // returns FALSE, the element already exists + * + * $bar = new \My\Foo(); + * $set->add($bar); // returns TRUE, $bar !== $foo + * ``` + * + * @template T + * @extends AbstractSet + */ +class Set extends AbstractSet +{ + /** + * The type of elements stored in this set + * + * A set's type is immutable. For this reason, this property is private. + * + * @var string + */ + private $setType; + + /** + * Constructs a set object of the specified type, optionally with the + * specified data. + * + * @param string $setType The type (FQCN) associated with this set. + * @param array $data The initial items to store in the set. + */ + public function __construct(string $setType, array $data = []) + { + $this->setType = $setType; + parent::__construct($data); + } + + public function getType(): string + { + return $this->setType; + } +} diff --git a/vendor/ramsey/collection/src/Tool/TypeTrait.php b/vendor/ramsey/collection/src/Tool/TypeTrait.php new file mode 100644 index 0000000..8214e96 --- /dev/null +++ b/vendor/ramsey/collection/src/Tool/TypeTrait.php @@ -0,0 +1,73 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Tool; + +use function is_array; +use function is_bool; +use function is_callable; +use function is_float; +use function is_int; +use function is_numeric; +use function is_object; +use function is_resource; +use function is_scalar; +use function is_string; + +/** + * Provides functionality to check values for specific types. + */ +trait TypeTrait +{ + /** + * Returns `true` if value is of the specified type. + * + * @param string $type The type to check the value against. + * @param mixed $value The value to check. + */ + protected function checkType(string $type, $value): bool + { + switch ($type) { + case 'array': + return is_array($value); + case 'bool': + case 'boolean': + return is_bool($value); + case 'callable': + return is_callable($value); + case 'float': + case 'double': + return is_float($value); + case 'int': + case 'integer': + return is_int($value); + case 'null': + return $value === null; + case 'numeric': + return is_numeric($value); + case 'object': + return is_object($value); + case 'resource': + return is_resource($value); + case 'scalar': + return is_scalar($value); + case 'string': + return is_string($value); + case 'mixed': + return true; + default: + return $value instanceof $type; + } + } +} diff --git a/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php b/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php new file mode 100644 index 0000000..f9be1be --- /dev/null +++ b/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php @@ -0,0 +1,58 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Tool; + +use Ramsey\Collection\Exception\ValueExtractionException; + +use function get_class; +use function method_exists; +use function property_exists; +use function sprintf; + +/** + * Provides functionality to extract the value of a property or method from an object. + */ +trait ValueExtractorTrait +{ + /** + * Extracts the value of the given property or method from the object. + * + * @param mixed $object The object to extract the value from. + * @param string $propertyOrMethod The property or method for which the + * value should be extracted. + * + * @return mixed the value extracted from the specified property or method. + * + * @throws ValueExtractionException if the method or property is not defined. + */ + protected function extractValue($object, string $propertyOrMethod) + { + if (!is_object($object)) { + throw new ValueExtractionException('Unable to extract a value from a non-object'); + } + + if (property_exists($object, $propertyOrMethod)) { + return $object->$propertyOrMethod; + } + + if (method_exists($object, $propertyOrMethod)) { + return $object->{$propertyOrMethod}(); + } + + throw new ValueExtractionException( + sprintf('Method or property "%s" not defined in %s', $propertyOrMethod, get_class($object)) + ); + } +} diff --git a/vendor/ramsey/collection/src/Tool/ValueToStringTrait.php b/vendor/ramsey/collection/src/Tool/ValueToStringTrait.php new file mode 100644 index 0000000..721ade0 --- /dev/null +++ b/vendor/ramsey/collection/src/Tool/ValueToStringTrait.php @@ -0,0 +1,94 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Collection\Tool; + +use DateTimeInterface; + +use function get_class; +use function get_resource_type; +use function is_array; +use function is_bool; +use function is_callable; +use function is_resource; +use function is_scalar; + +/** + * Provides functionality to express a value as string + */ +trait ValueToStringTrait +{ + /** + * Returns a string representation of the value. + * + * - null value: `'NULL'` + * - boolean: `'TRUE'`, `'FALSE'` + * - array: `'Array'` + * - scalar: converted-value + * - resource: `'(type resource #number)'` + * - object with `__toString()`: result of `__toString()` + * - object DateTime: ISO 8601 date + * - object: `'(className Object)'` + * - anonymous function: same as object + * + * @param mixed $value the value to return as a string. + */ + protected function toolValueToString($value): string + { + // null + if ($value === null) { + return 'NULL'; + } + + // boolean constants + if (is_bool($value)) { + return $value ? 'TRUE' : 'FALSE'; + } + + // array + if (is_array($value)) { + return 'Array'; + } + + // scalar types (integer, float, string) + if (is_scalar($value)) { + return (string) $value; + } + + // resource + if (is_resource($value)) { + return '(' . get_resource_type($value) . ' resource #' . (int) $value . ')'; + } + + // If we don't know what it is, use var_export(). + if (!is_object($value)) { + return '(' . var_export($value, true) . ')'; + } + + // From here, $value should be an object. + + // __toString() is implemented + if (is_callable([$value, '__toString'])) { + return (string) $value->__toString(); + } + + // object of type \DateTime + if ($value instanceof DateTimeInterface) { + return $value->format('c'); + } + + // unknown type + return '(' . get_class($value) . ' Object)'; + } +} diff --git a/vendor/ramsey/uuid/LICENSE b/vendor/ramsey/uuid/LICENSE new file mode 100644 index 0000000..5e06cf4 --- /dev/null +++ b/vendor/ramsey/uuid/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012-2021 Ben Ramsey + +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 0000000..97e81a5 --- /dev/null +++ b/vendor/ramsey/uuid/README.md @@ -0,0 +1,83 @@ +

ramsey/uuid

+ +

+ A PHP library for generating and working with UUIDs. +

+ +

+ Source Code + Download Package + PHP Programming Language + Read License + Build Status + Codecov Code Coverage + Psalm Type Coverage +

+ +ramsey/uuid is a PHP library for generating and working with universally unique +identifiers (UUIDs). + +This project adheres to a [code of conduct](CODE_OF_CONDUCT.md). +By participating in this project and its community, you are expected to +uphold this code. + +Much inspiration for this library came from the [Java][javauuid] and +[Python][pyuuid] UUID libraries. + +## Installation + +The preferred method of installation is via [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 to Version 4 + +See the documentation for a thorough upgrade guide: + +* [Upgrading ramsey/uuid Version 3 to 4](https://uuid.ramsey.dev/en/latest/upgrading/3-to-4.html) + +## Documentation + +Please see for documentation, tips, examples, and +frequently asked questions. + +## Contributing + +Contributions are welcome! To contribute, please familiarize yourself with +[CONTRIBUTING.md](CONTRIBUTING.md). + +## Coordinated Disclosure + +Keeping user information safe and secure is a top priority, and we welcome the +contribution of external security researchers. If you believe you've found a +security issue in software that is maintained in this repository, please read +[SECURITY.md][] for instructions on submitting a vulnerability report. + +## ramsey/uuid for Enterprise + +Available as part of the Tidelift Subscription. + +The maintainers of ramsey/uuid and thousands of other packages are working with +Tidelift to deliver commercial support and maintenance for the open source +packages you use to build your applications. Save time, reduce risk, and improve +code health, while paying the maintainers of the exact packages you use. +[Learn more.](https://tidelift.com/subscription/pkg/packagist-ramsey-uuid?utm_source=undefined&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) + +## 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/main/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 +[composer]: http://getcomposer.org/ +[contributing.md]: https://github.com/ramsey/uuid/blob/main/CONTRIBUTING.md +[security.md]: https://github.com/ramsey/uuid/blob/main/SECURITY.md +[license]: https://github.com/ramsey/uuid/blob/main/LICENSE diff --git a/vendor/ramsey/uuid/composer.json b/vendor/ramsey/uuid/composer.json new file mode 100644 index 0000000..3f3b5ac --- /dev/null +++ b/vendor/ramsey/uuid/composer.json @@ -0,0 +1,107 @@ +{ + "name": "ramsey/uuid", + "type": "library", + "description": "A PHP library for generating and working with universally unique identifiers (UUIDs).", + "keywords": [ + "uuid", + "identifier", + "guid" + ], + "license": "MIT", + "require": { + "php": "^7.2 || ^8.0", + "ext-json": "*", + "brick/math": "^0.8 || ^0.9", + "ramsey/collection": "^1.0", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-php80": "^1.14" + }, + "replace": { + "rhumsaa/uuid": "self.version" + }, + "require-dev": { + "captainhook/captainhook": "^5.10", + "captainhook/plugin-composer": "^5.3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", + "doctrine/annotations": "^1.8", + "ergebnis/composer-normalize": "^2.15", + "mockery/mockery": "^1.3", + "moontoast/math": "^1.1", + "paragonie/random-lib": "^2", + "php-mock/php-mock": "^2.2", + "php-mock/php-mock-mockery": "^1.3", + "php-parallel-lint/php-parallel-lint": "^1.1", + "phpbench/phpbench": "^1.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-mockery": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^8.5 || ^9", + "slevomat/coding-standard": "^7.0", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.9" + }, + "suggest": { + "ext-bcmath": "Enables faster math with arbitrary-precision integers using BCMath.", + "ext-ctype": "Enables faster processing of character classification using ctype functions.", + "ext-gmp": "Enables faster math with arbitrary-precision integers using GMP.", + "ext-uuid": "Enables the use of PeclUuidTimeGenerator and PeclUuidRandomGenerator.", + "paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter", + "ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type." + }, + "config": { + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-main": "4.x-dev" + }, + "captainhook": { + "force-install": true + } + }, + "autoload": { + "psr-4": { + "Ramsey\\Uuid\\": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Ramsey\\Uuid\\Benchmark\\": "tests/benchmark/", + "Ramsey\\Uuid\\StaticAnalysis\\": "tests/static-analysis/", + "Ramsey\\Uuid\\Test\\": "tests/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "analyze": [ + "@phpstan", + "@psalm" + ], + "build:clean": "git clean -fX build/", + "lint": "parallel-lint src tests", + "lint:paths": "parallel-lint", + "phpbench": "phpbench run", + "phpcbf": "phpcbf -vpw --cache=build/cache/phpcs.cache", + "phpcs": "phpcs --cache=build/cache/phpcs.cache", + "phpstan": [ + "phpstan analyse --no-progress", + "phpstan analyse -c phpstan-tests.neon --no-progress" + ], + "phpunit": "phpunit --verbose --colors=always", + "phpunit-coverage": "phpunit --verbose --colors=always --coverage-html build/coverage", + "psalm": "psalm --show-info=false --config=psalm.xml", + "test": [ + "@lint", + "@phpbench", + "@phpcs", + "@phpstan", + "@psalm", + "@phpunit" + ] + } +} diff --git a/vendor/ramsey/uuid/src/BinaryUtils.php b/vendor/ramsey/uuid/src/BinaryUtils.php new file mode 100644 index 0000000..fb8ba9a --- /dev/null +++ b/vendor/ramsey/uuid/src/BinaryUtils.php @@ -0,0 +1,63 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +/** + * Provides binary math utilities + */ +class BinaryUtils +{ + /** + * Applies the RFC 4122 variant field to the 16-bit clock sequence + * + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 RFC 4122, § 4.1.1: Variant + * + * @param int $clockSeq The 16-bit clock sequence value before the RFC 4122 + * variant is applied + * + * @return int The 16-bit clock sequence multiplexed with the UUID variant + * + * @psalm-pure + */ + public static function applyVariant(int $clockSeq): int + { + $clockSeq = $clockSeq & 0x3fff; + $clockSeq |= 0x8000; + + return $clockSeq; + } + + /** + * Applies the RFC 4122 version number to the 16-bit `time_hi_and_version` field + * + * @link http://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, § 4.1.3: Version + * + * @param int $timeHi The value of the 16-bit `time_hi_and_version` field + * before the RFC 4122 version is applied + * @param int $version The RFC 4122 version to apply to the `time_hi` field + * + * @return int The 16-bit time_hi field of the timestamp multiplexed with + * the UUID version number + * + * @psalm-pure + */ + public static function applyVersion(int $timeHi, int $version): int + { + $timeHi = $timeHi & 0x0fff; + $timeHi |= $version << 12; + + return $timeHi; + } +} diff --git a/vendor/ramsey/uuid/src/Builder/BuilderCollection.php b/vendor/ramsey/uuid/src/Builder/BuilderCollection.php new file mode 100644 index 0000000..89fa1e3 --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/BuilderCollection.php @@ -0,0 +1,80 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Builder; + +use Ramsey\Collection\AbstractCollection; +use Ramsey\Uuid\Converter\Number\GenericNumberConverter; +use Ramsey\Uuid\Converter\Time\GenericTimeConverter; +use Ramsey\Uuid\Converter\Time\PhpTimeConverter; +use Ramsey\Uuid\Guid\GuidBuilder; +use Ramsey\Uuid\Math\BrickMathCalculator; +use Ramsey\Uuid\Nonstandard\UuidBuilder as NonstandardUuidBuilder; +use Ramsey\Uuid\Rfc4122\UuidBuilder as Rfc4122UuidBuilder; +use Traversable; + +/** + * A collection of UuidBuilderInterface objects + * + * @extends AbstractCollection + */ +class BuilderCollection extends AbstractCollection +{ + public function getType(): string + { + return UuidBuilderInterface::class; + } + + /** + * @psalm-mutation-free + * @psalm-suppress ImpureMethodCall + * @psalm-suppress InvalidTemplateParam + */ + public function getIterator(): Traversable + { + return parent::getIterator(); + } + + /** + * Re-constructs the object from its serialized form + * + * @param string $serialized The serialized PHP string to unserialize into + * a UuidInterface instance + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + * @psalm-suppress RedundantConditionGivenDocblockType + */ + public function unserialize($serialized): void + { + /** @var array $data */ + $data = unserialize($serialized, [ + 'allowed_classes' => [ + BrickMathCalculator::class, + GenericNumberConverter::class, + GenericTimeConverter::class, + GuidBuilder::class, + NonstandardUuidBuilder::class, + PhpTimeConverter::class, + Rfc4122UuidBuilder::class, + ], + ]); + + $this->data = array_filter( + $data, + function ($unserialized): bool { + return $unserialized instanceof UuidBuilderInterface; + } + ); + } +} diff --git a/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php b/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php new file mode 100644 index 0000000..7c4a6f8 --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php @@ -0,0 +1,26 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Builder; + +use Ramsey\Uuid\Rfc4122\UuidBuilder as Rfc4122UuidBuilder; + +/** + * @deprecated Transition to {@see Rfc4122UuidBuilder}. + * + * @psalm-immutable + */ +class DefaultUuidBuilder extends Rfc4122UuidBuilder +{ +} diff --git a/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php new file mode 100644 index 0000000..23931e4 --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php @@ -0,0 +1,76 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Builder; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\Time\DegradedTimeConverter; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\DegradedUuid; +use Ramsey\Uuid\Rfc4122\Fields as Rfc4122Fields; +use Ramsey\Uuid\UuidInterface; + +/** + * @deprecated DegradedUuid instances are no longer necessary to support 32-bit + * systems. Transition to {@see DefaultUuidBuilder}. + * + * @psalm-immutable + */ +class DegradedUuidBuilder implements UuidBuilderInterface +{ + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * @param NumberConverterInterface $numberConverter The number converter to + * use when constructing the DegradedUuid + * @param TimeConverterInterface|null $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to Unix timestamps + */ + public function __construct( + NumberConverterInterface $numberConverter, + ?TimeConverterInterface $timeConverter = null + ) { + $this->numberConverter = $numberConverter; + $this->timeConverter = $timeConverter ?: new DegradedTimeConverter(); + } + + /** + * Builds and returns a DegradedUuid + * + * @param CodecInterface $codec The codec to use for building this DegradedUuid instance + * @param string $bytes The byte string from which to construct a UUID + * + * @return DegradedUuid The DegradedUuidBuild returns an instance of Ramsey\Uuid\DegradedUuid + * + * @psalm-pure + */ + public function build(CodecInterface $codec, string $bytes): UuidInterface + { + return new DegradedUuid( + new Rfc4122Fields($bytes), + $this->numberConverter, + $codec, + $this->timeConverter + ); + } +} diff --git a/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php b/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php new file mode 100644 index 0000000..470d2f7 --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php @@ -0,0 +1,74 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Builder; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Exception\BuilderNotFoundException; +use Ramsey\Uuid\Exception\UnableToBuildUuidException; +use Ramsey\Uuid\UuidInterface; + +/** + * FallbackBuilder builds a UUID by stepping through a list of UUID builders + * until a UUID can be constructed without exceptions + * + * @psalm-immutable + */ +class FallbackBuilder implements UuidBuilderInterface +{ + /** + * @var BuilderCollection + */ + private $builders; + + /** + * @param BuilderCollection $builders An array of UUID builders + */ + public function __construct(BuilderCollection $builders) + { + $this->builders = $builders; + } + + /** + * Builds and returns a UuidInterface instance using the first builder that + * succeeds + * + * @param CodecInterface $codec The codec to use for building this instance + * @param string $bytes The byte string from which to construct a UUID + * + * @return UuidInterface an instance of a UUID object + * + * @psalm-pure + */ + public function build(CodecInterface $codec, string $bytes): UuidInterface + { + $lastBuilderException = null; + + foreach ($this->builders as $builder) { + try { + return $builder->build($codec, $bytes); + } catch (UnableToBuildUuidException $exception) { + $lastBuilderException = $exception; + + continue; + } + } + + throw new BuilderNotFoundException( + 'Could not find a suitable builder for the provided codec and fields', + 0, + $lastBuilderException + ); + } +} diff --git a/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php b/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php new file mode 100644 index 0000000..8e58b2b --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php @@ -0,0 +1,39 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Builder; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\UuidInterface; + +/** + * A UUID builder builds instances of UuidInterface + * + * @psalm-immutable + */ +interface UuidBuilderInterface +{ + /** + * Builds and returns a UuidInterface + * + * @param CodecInterface $codec The codec to use for building this UuidInterface instance + * @param string $bytes The byte string from which to construct a UUID + * + * @return UuidInterface Implementations may choose to return more specific + * instances of UUIDs that implement UuidInterface + * + * @psalm-pure + */ + public function build(CodecInterface $codec, string $bytes): UuidInterface; +} diff --git a/vendor/ramsey/uuid/src/Codec/CodecInterface.php b/vendor/ramsey/uuid/src/Codec/CodecInterface.php new file mode 100644 index 0000000..85f8a7e --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/CodecInterface.php @@ -0,0 +1,71 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Codec; + +use Ramsey\Uuid\UuidInterface; + +/** + * A codec encodes and decodes a UUID according to defined rules + * + * @psalm-immutable + */ +interface CodecInterface +{ + /** + * Returns a hexadecimal string representation of a UuidInterface + * + * @param UuidInterface $uuid The UUID for which to create a hexadecimal + * string representation + * + * @return string Hexadecimal string representation of a UUID + * + * @psalm-return non-empty-string + */ + public function encode(UuidInterface $uuid): string; + + /** + * Returns a binary string representation of a UuidInterface + * + * @param UuidInterface $uuid The UUID for which to create a binary string + * representation + * + * @return string Binary string representation of a UUID + * + * @psalm-return non-empty-string + */ + public function encodeBinary(UuidInterface $uuid): string; + + /** + * Returns a UuidInterface derived from a hexadecimal string representation + * + * @param string $encodedUuid The hexadecimal string representation to + * convert into a UuidInterface instance + * + * @return UuidInterface An instance of a UUID decoded from a hexadecimal + * string representation + */ + public function decode(string $encodedUuid): UuidInterface; + + /** + * Returns a UuidInterface derived from a binary string representation + * + * @param string $bytes The binary string representation to convert into a + * UuidInterface instance + * + * @return UuidInterface An instance of a UUID decoded from a binary string + * representation + */ + public function decodeBytes(string $bytes): UuidInterface; +} diff --git a/vendor/ramsey/uuid/src/Codec/GuidStringCodec.php b/vendor/ramsey/uuid/src/Codec/GuidStringCodec.php new file mode 100644 index 0000000..f11e9d5 --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/GuidStringCodec.php @@ -0,0 +1,55 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Codec; + +use Ramsey\Uuid\Guid\Guid; +use Ramsey\Uuid\UuidInterface; + +use function bin2hex; +use function substr; + +/** + * GuidStringCodec encodes and decodes globally unique identifiers (GUID) + * + * @see Guid + * + * @psalm-immutable + */ +class GuidStringCodec extends StringCodec +{ + public function decode(string $encodedUuid): UuidInterface + { + $bytes = $this->getBytes($encodedUuid); + + return $this->getBuilder()->build($this, $this->swapBytes($bytes)); + } + + public function decodeBytes(string $bytes): UuidInterface + { + // Specifically call parent::decode to preserve correct byte order + return parent::decode(bin2hex($bytes)); + } + + /** + * Swaps bytes according to the GUID rules + */ + private function swapBytes(string $bytes): string + { + return $bytes[3] . $bytes[2] . $bytes[1] . $bytes[0] + . $bytes[5] . $bytes[4] + . $bytes[7] . $bytes[6] + . substr($bytes, 8); + } +} diff --git a/vendor/ramsey/uuid/src/Codec/OrderedTimeCodec.php b/vendor/ramsey/uuid/src/Codec/OrderedTimeCodec.php new file mode 100644 index 0000000..0798ebc --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/OrderedTimeCodec.php @@ -0,0 +1,113 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Codec; + +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Exception\UnsupportedOperationException; +use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\UuidInterface; + +use function strlen; +use function substr; + +/** + * OrderedTimeCodec encodes and decodes a UUID, optimizing the byte order for + * more efficient storage + * + * For binary representations of version 1 UUID, this codec may be used to + * reorganize the time fields, making the UUID closer to sequential when storing + * the bytes. According to Percona, this optimization can improve database + * INSERTs and SELECTs using the UUID column as a key. + * + * The string representation of the UUID will remain unchanged. Only the binary + * representation is reordered. + * + * **PLEASE NOTE:** Binary representations of UUIDs encoded with this codec must + * be decoded with this codec. Decoding using another codec can result in + * malformed UUIDs. + * + * @link https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/ Storing UUID Values in MySQL + * + * @psalm-immutable + */ +class OrderedTimeCodec extends StringCodec +{ + /** + * Returns a binary string representation of a UUID, with the timestamp + * fields rearranged for optimized storage + * + * @inheritDoc + * @psalm-return non-empty-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function encodeBinary(UuidInterface $uuid): string + { + if ( + !($uuid->getFields() instanceof Rfc4122FieldsInterface) + || $uuid->getFields()->getVersion() !== Uuid::UUID_TYPE_TIME + ) { + throw new InvalidArgumentException( + 'Expected RFC 4122 version 1 (time-based) UUID' + ); + } + + $bytes = $uuid->getFields()->getBytes(); + + /** @phpstan-ignore-next-line PHPStan complains that this is not a non-empty-string. */ + return $bytes[6] . $bytes[7] + . $bytes[4] . $bytes[5] + . $bytes[0] . $bytes[1] . $bytes[2] . $bytes[3] + . substr($bytes, 8); + } + + /** + * Returns a UuidInterface derived from an ordered-time binary string + * representation + * + * @throws InvalidArgumentException if $bytes is an invalid length + * + * @inheritDoc + */ + public function decodeBytes(string $bytes): UuidInterface + { + if (strlen($bytes) !== 16) { + throw new InvalidArgumentException( + '$bytes string should contain 16 characters.' + ); + } + + // Rearrange the bytes to their original order. + $rearrangedBytes = $bytes[4] . $bytes[5] . $bytes[6] . $bytes[7] + . $bytes[2] . $bytes[3] + . $bytes[0] . $bytes[1] + . substr($bytes, 8); + + $uuid = parent::decodeBytes($rearrangedBytes); + + if ( + !($uuid->getFields() instanceof Rfc4122FieldsInterface) + || $uuid->getFields()->getVersion() !== Uuid::UUID_TYPE_TIME + ) { + throw new UnsupportedOperationException( + 'Attempting to decode a non-time-based UUID using ' + . 'OrderedTimeCodec' + ); + } + + return $uuid; + } +} diff --git a/vendor/ramsey/uuid/src/Codec/StringCodec.php b/vendor/ramsey/uuid/src/Codec/StringCodec.php new file mode 100644 index 0000000..58c9f58 --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/StringCodec.php @@ -0,0 +1,138 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Codec; + +use Ramsey\Uuid\Builder\UuidBuilderInterface; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Exception\InvalidUuidStringException; +use Ramsey\Uuid\Rfc4122\FieldsInterface; +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\UuidInterface; + +use function hex2bin; +use function implode; +use function str_replace; +use function strlen; +use function substr; + +/** + * StringCodec encodes and decodes RFC 4122 UUIDs + * + * @link http://tools.ietf.org/html/rfc4122 + * + * @psalm-immutable + */ +class StringCodec implements CodecInterface +{ + /** + * @var UuidBuilderInterface + */ + private $builder; + + /** + * Constructs a StringCodec + * + * @param UuidBuilderInterface $builder The builder to use when encoding UUIDs + */ + public function __construct(UuidBuilderInterface $builder) + { + $this->builder = $builder; + } + + public function encode(UuidInterface $uuid): string + { + /** @var FieldsInterface $fields */ + $fields = $uuid->getFields(); + + return $fields->getTimeLow()->toString() + . '-' + . $fields->getTimeMid()->toString() + . '-' + . $fields->getTimeHiAndVersion()->toString() + . '-' + . $fields->getClockSeqHiAndReserved()->toString() + . $fields->getClockSeqLow()->toString() + . '-' + . $fields->getNode()->toString(); + } + + /** + * @psalm-return non-empty-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function encodeBinary(UuidInterface $uuid): string + { + /** @phpstan-ignore-next-line PHPStan complains that this is not a non-empty-string. */ + return $uuid->getFields()->getBytes(); + } + + /** + * @throws InvalidUuidStringException + * + * @inheritDoc + */ + public function decode(string $encodedUuid): UuidInterface + { + return $this->builder->build($this, $this->getBytes($encodedUuid)); + } + + public function decodeBytes(string $bytes): UuidInterface + { + if (strlen($bytes) !== 16) { + throw new InvalidArgumentException( + '$bytes string should contain 16 characters.' + ); + } + + return $this->builder->build($this, $bytes); + } + + /** + * Returns the UUID builder + */ + protected function getBuilder(): UuidBuilderInterface + { + return $this->builder; + } + + /** + * Returns a byte string of the UUID + */ + protected function getBytes(string $encodedUuid): string + { + $parsedUuid = str_replace( + ['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}', '-'], + '', + $encodedUuid + ); + + $components = [ + substr($parsedUuid, 0, 8), + substr($parsedUuid, 8, 4), + substr($parsedUuid, 12, 4), + substr($parsedUuid, 16, 4), + substr($parsedUuid, 20), + ]; + + if (!Uuid::isValid(implode('-', $components))) { + throw new InvalidUuidStringException( + 'Invalid UUID string: ' . $encodedUuid + ); + } + + return (string) hex2bin($parsedUuid); + } +} diff --git a/vendor/ramsey/uuid/src/Codec/TimestampFirstCombCodec.php b/vendor/ramsey/uuid/src/Codec/TimestampFirstCombCodec.php new file mode 100644 index 0000000..0e0042d --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/TimestampFirstCombCodec.php @@ -0,0 +1,113 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Codec; + +use Ramsey\Uuid\Exception\InvalidUuidStringException; +use Ramsey\Uuid\UuidInterface; + +use function bin2hex; +use function sprintf; +use function substr; +use function substr_replace; + +/** + * TimestampFirstCombCodec encodes and decodes COMBs, with the timestamp as the + * first 48 bits + * + * In contrast with the TimestampLastCombCodec, the TimestampFirstCombCodec + * adds the timestamp to the first 48 bits of the COMB. To generate a + * timestamp-first COMB, set the TimestampFirstCombCodec as the codec, along + * with the CombGenerator as the random generator. + * + * ``` php + * $factory = new UuidFactory(); + * + * $factory->setCodec(new TimestampFirstCombCodec($factory->getUuidBuilder())); + * + * $factory->setRandomGenerator(new CombGenerator( + * $factory->getRandomGenerator(), + * $factory->getNumberConverter() + * )); + * + * $timestampFirstComb = $factory->uuid4(); + * ``` + * + * @link https://www.informit.com/articles/printerfriendly/25862 The Cost of GUIDs as Primary Keys + * + * @psalm-immutable + */ +class TimestampFirstCombCodec extends StringCodec +{ + /** + * @psalm-return non-empty-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function encode(UuidInterface $uuid): string + { + $bytes = $this->swapBytes($uuid->getFields()->getBytes()); + + return sprintf( + '%08s-%04s-%04s-%04s-%012s', + bin2hex(substr($bytes, 0, 4)), + bin2hex(substr($bytes, 4, 2)), + bin2hex(substr($bytes, 6, 2)), + bin2hex(substr($bytes, 8, 2)), + bin2hex(substr($bytes, 10)) + ); + } + + /** + * @psalm-return non-empty-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function encodeBinary(UuidInterface $uuid): string + { + /** @phpstan-ignore-next-line PHPStan complains that this is not a non-empty-string. */ + return $this->swapBytes($uuid->getFields()->getBytes()); + } + + /** + * @throws InvalidUuidStringException + * + * @inheritDoc + */ + public function decode(string $encodedUuid): UuidInterface + { + $bytes = $this->getBytes($encodedUuid); + + return $this->getBuilder()->build($this, $this->swapBytes($bytes)); + } + + public function decodeBytes(string $bytes): UuidInterface + { + return $this->getBuilder()->build($this, $this->swapBytes($bytes)); + } + + /** + * Swaps bytes according to the timestamp-first COMB rules + */ + private function swapBytes(string $bytes): string + { + $first48Bits = substr($bytes, 0, 6); + $last48Bits = substr($bytes, -6); + + $bytes = substr_replace($bytes, $last48Bits, 0, 6); + $bytes = substr_replace($bytes, $first48Bits, -6); + + return $bytes; + } +} diff --git a/vendor/ramsey/uuid/src/Codec/TimestampLastCombCodec.php b/vendor/ramsey/uuid/src/Codec/TimestampLastCombCodec.php new file mode 100644 index 0000000..4856dea --- /dev/null +++ b/vendor/ramsey/uuid/src/Codec/TimestampLastCombCodec.php @@ -0,0 +1,51 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Codec; + +/** + * TimestampLastCombCodec encodes and decodes COMBs, with the timestamp as the + * last 48 bits + * + * The CombGenerator when used with the StringCodec (and, by proxy, the + * TimestampLastCombCodec) adds the timestamp to the last 48 bits of the COMB. + * The TimestampLastCombCodec is provided for the sake of consistency. In + * practice, it is identical to the standard StringCodec but, it may be used + * with the CombGenerator for additional context when reading code. + * + * Consider the following code. By default, the codec used by UuidFactory is the + * StringCodec, but here, we explicitly set the TimestampLastCombCodec. It is + * redundant, but it is clear that we intend this COMB to be generated with the + * timestamp appearing at the end. + * + * ``` php + * $factory = new UuidFactory(); + * + * $factory->setCodec(new TimestampLastCombCodec($factory->getUuidBuilder())); + * + * $factory->setRandomGenerator(new CombGenerator( + * $factory->getRandomGenerator(), + * $factory->getNumberConverter() + * )); + * + * $timestampLastComb = $factory->uuid4(); + * ``` + * + * @link https://www.informit.com/articles/printerfriendly/25862 The Cost of GUIDs as Primary Keys + * + * @psalm-immutable + */ +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 0000000..fef63fd --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php @@ -0,0 +1,57 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Converter\Number; + +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Math\BrickMathCalculator; + +/** + * Previously used to integrate moontoast/math as a bignum arithmetic library, + * BigNumberConverter is deprecated in favor of GenericNumberConverter + * + * @deprecated Transition to {@see GenericNumberConverter}. + * + * @psalm-immutable + */ +class BigNumberConverter implements NumberConverterInterface +{ + /** + * @var NumberConverterInterface + */ + private $converter; + + public function __construct() + { + $this->converter = new GenericNumberConverter(new BrickMathCalculator()); + } + + /** + * @inheritDoc + * @psalm-pure + */ + public function fromHex(string $hex): string + { + return $this->converter->fromHex($hex); + } + + /** + * @inheritDoc + * @psalm-pure + */ + public function toHex(string $number): string + { + return $this->converter->toHex($number); + } +} 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 0000000..c9cfa68 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php @@ -0,0 +1,25 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Converter\Number; + +/** + * @deprecated DegradedNumberConverter is no longer necessary for converting + * numbers on 32-bit systems. Transition to {@see GenericNumberConverter}. + * + * @psalm-immutable + */ +class DegradedNumberConverter extends BigNumberConverter +{ +} diff --git a/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php new file mode 100644 index 0000000..501eac0 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php @@ -0,0 +1,63 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Converter\Number; + +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Math\CalculatorInterface; +use Ramsey\Uuid\Type\Integer as IntegerObject; + +/** + * GenericNumberConverter uses the provided calculator to convert decimal + * numbers to and from hexadecimal values + * + * @psalm-immutable + */ +class GenericNumberConverter implements NumberConverterInterface +{ + /** + * @var CalculatorInterface + */ + private $calculator; + + public function __construct(CalculatorInterface $calculator) + { + $this->calculator = $calculator; + } + + /** + * @inheritDoc + * @psalm-pure + * @psalm-return numeric-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function fromHex(string $hex): string + { + return $this->calculator->fromBase($hex, 16)->toString(); + } + + /** + * @inheritDoc + * @psalm-pure + * @psalm-return non-empty-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function toHex(string $number): string + { + /** @phpstan-ignore-next-line PHPStan complains that this is not a non-empty-string. */ + return $this->calculator->toBase(new IntegerObject($number), 16); + } +} diff --git a/vendor/ramsey/uuid/src/Converter/NumberConverterInterface.php b/vendor/ramsey/uuid/src/Converter/NumberConverterInterface.php new file mode 100644 index 0000000..b33ec31 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/NumberConverterInterface.php @@ -0,0 +1,57 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Converter; + +/** + * A number converter converts UUIDs from hexadecimal characters into + * representations of integers and vice versa + * + * @psalm-immutable + */ +interface NumberConverterInterface +{ + /** + * Converts a hexadecimal number into an string integer representation of + * the number + * + * The integer representation returned is a string representation of the + * integer, to accommodate unsigned integers greater than PHP_INT_MAX. + * + * @param string $hex The hexadecimal string representation to convert + * + * @return string String representation of an integer + * + * @psalm-return numeric-string + * + * @psalm-pure + */ + public function fromHex(string $hex): string; + + /** + * Converts a string integer representation into a hexadecimal string + * representation of the number + * + * @param string $number A string integer representation to convert; this + * must be a numeric string to accommodate unsigned integers greater + * than PHP_INT_MAX. + * + * @return string Hexadecimal string + * + * @psalm-return non-empty-string + * + * @psalm-pure + */ + public function toHex(string $number): string; +} 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 0000000..7390dad --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Time/BigNumberTimeConverter.php @@ -0,0 +1,51 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Converter\Time; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Math\BrickMathCalculator; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Time; + +/** + * Previously used to integrate moontoast/math as a bignum arithmetic library, + * BigNumberTimeConverter is deprecated in favor of GenericTimeConverter + * + * @deprecated Transition to {@see GenericTimeConverter}. + * + * @psalm-immutable + */ +class BigNumberTimeConverter implements TimeConverterInterface +{ + /** + * @var TimeConverterInterface + */ + private $converter; + + public function __construct() + { + $this->converter = new GenericTimeConverter(new BrickMathCalculator()); + } + + public function calculateTime(string $seconds, string $microseconds): Hexadecimal + { + return $this->converter->calculateTime($seconds, $microseconds); + } + + public function convertTime(Hexadecimal $uuidTimestamp): Time + { + return $this->converter->convertTime($uuidTimestamp); + } +} 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 0000000..cdc2875 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Time/DegradedTimeConverter.php @@ -0,0 +1,25 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Converter\Time; + +/** + * @deprecated DegradedTimeConverter is no longer necessary for converting + * time on 32-bit systems. Transition to {@see GenericTimeConverter}. + * + * @psalm-immutable + */ +class DegradedTimeConverter extends BigNumberTimeConverter +{ +} diff --git a/vendor/ramsey/uuid/src/Converter/Time/GenericTimeConverter.php b/vendor/ramsey/uuid/src/Converter/Time/GenericTimeConverter.php new file mode 100644 index 0000000..a8aa64b --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Time/GenericTimeConverter.php @@ -0,0 +1,124 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Converter\Time; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Math\CalculatorInterface; +use Ramsey\Uuid\Math\RoundingMode; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Type\Time; + +use function explode; +use function str_pad; + +use const STR_PAD_LEFT; + +/** + * GenericTimeConverter uses the provided calculator to calculate and convert + * time values + * + * @psalm-immutable + */ +class GenericTimeConverter implements TimeConverterInterface +{ + /** + * The number of 100-nanosecond intervals from the Gregorian calendar epoch + * to the Unix epoch. + */ + private const GREGORIAN_TO_UNIX_INTERVALS = '122192928000000000'; + + /** + * The number of 100-nanosecond intervals in one second. + */ + private const SECOND_INTERVALS = '10000000'; + + /** + * The number of 100-nanosecond intervals in one microsecond. + */ + private const MICROSECOND_INTERVALS = '10'; + + /** + * @var CalculatorInterface + */ + private $calculator; + + public function __construct(CalculatorInterface $calculator) + { + $this->calculator = $calculator; + } + + public function calculateTime(string $seconds, string $microseconds): Hexadecimal + { + $timestamp = new Time($seconds, $microseconds); + + // Convert the seconds into a count of 100-nanosecond intervals. + $sec = $this->calculator->multiply( + $timestamp->getSeconds(), + new IntegerObject(self::SECOND_INTERVALS) + ); + + // Convert the microseconds into a count of 100-nanosecond intervals. + $usec = $this->calculator->multiply( + $timestamp->getMicroseconds(), + new IntegerObject(self::MICROSECOND_INTERVALS) + ); + + // Combine the seconds and microseconds intervals and add the count of + // 100-nanosecond intervals from the Gregorian calendar epoch to the + // Unix epoch. This gives us the correct count of 100-nanosecond + // intervals since the Gregorian calendar epoch for the given seconds + // and microseconds. + /** @var IntegerObject $uuidTime */ + $uuidTime = $this->calculator->add( + $sec, + $usec, + new IntegerObject(self::GREGORIAN_TO_UNIX_INTERVALS) + ); + + $uuidTimeHex = str_pad( + $this->calculator->toHexadecimal($uuidTime)->toString(), + 16, + '0', + STR_PAD_LEFT + ); + + return new Hexadecimal($uuidTimeHex); + } + + public function convertTime(Hexadecimal $uuidTimestamp): Time + { + // From the total, subtract the number of 100-nanosecond intervals from + // the Gregorian calendar epoch to the Unix epoch. This gives us the + // number of 100-nanosecond intervals from the Unix epoch, which also + // includes the microtime. + $epochNanoseconds = $this->calculator->subtract( + $this->calculator->toInteger($uuidTimestamp), + new IntegerObject(self::GREGORIAN_TO_UNIX_INTERVALS) + ); + + // Convert the 100-nanosecond intervals into seconds and microseconds. + $unixTimestamp = $this->calculator->divide( + RoundingMode::HALF_UP, + 6, + $epochNanoseconds, + new IntegerObject(self::SECOND_INTERVALS) + ); + + $split = explode('.', (string) $unixTimestamp, 2); + + return new Time($split[0], $split[1] ?? 0); + } +} 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 0000000..538d2f2 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php @@ -0,0 +1,183 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Converter\Time; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Math\BrickMathCalculator; +use Ramsey\Uuid\Math\CalculatorInterface; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Type\Time; + +use function count; +use function dechex; +use function explode; +use function is_float; +use function is_int; +use function str_pad; +use function strlen; +use function substr; + +use const STR_PAD_LEFT; +use const STR_PAD_RIGHT; + +/** + * 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 + * + * @psalm-immutable + */ +class PhpTimeConverter implements TimeConverterInterface +{ + /** + * The number of 100-nanosecond intervals from the Gregorian calendar epoch + * to the Unix epoch. + */ + private const GREGORIAN_TO_UNIX_INTERVALS = 0x01b21dd213814000; + + /** + * The number of 100-nanosecond intervals in one second. + */ + private const SECOND_INTERVALS = 10000000; + + /** + * The number of 100-nanosecond intervals in one microsecond. + */ + private const MICROSECOND_INTERVALS = 10; + + /** + * @var CalculatorInterface + */ + private $calculator; + + /** + * @var TimeConverterInterface + */ + private $fallbackConverter; + + /** + * @var int + */ + private $phpPrecision; + + public function __construct( + ?CalculatorInterface $calculator = null, + ?TimeConverterInterface $fallbackConverter = null + ) { + if ($calculator === null) { + $calculator = new BrickMathCalculator(); + } + + if ($fallbackConverter === null) { + $fallbackConverter = new GenericTimeConverter($calculator); + } + + $this->calculator = $calculator; + $this->fallbackConverter = $fallbackConverter; + $this->phpPrecision = (int) ini_get('precision'); + } + + public function calculateTime(string $seconds, string $microseconds): Hexadecimal + { + $seconds = new IntegerObject($seconds); + $microseconds = new IntegerObject($microseconds); + + // Calculate the count of 100-nanosecond intervals since the Gregorian + // calendar epoch for the given seconds and microseconds. + $uuidTime = ((int) $seconds->toString() * self::SECOND_INTERVALS) + + ((int) $microseconds->toString() * self::MICROSECOND_INTERVALS) + + self::GREGORIAN_TO_UNIX_INTERVALS; + + // Check to see whether we've overflowed the max/min integer size. + // If so, we will default to a different time converter. + /** @psalm-suppress RedundantCondition */ + if (!is_int($uuidTime)) { + return $this->fallbackConverter->calculateTime( + $seconds->toString(), + $microseconds->toString() + ); + } + + return new Hexadecimal(str_pad(dechex($uuidTime), 16, '0', STR_PAD_LEFT)); + } + + public function convertTime(Hexadecimal $uuidTimestamp): Time + { + $timestamp = $this->calculator->toInteger($uuidTimestamp); + + // Convert the 100-nanosecond intervals into seconds and microseconds. + $splitTime = $this->splitTime( + ((int) $timestamp->toString() - self::GREGORIAN_TO_UNIX_INTERVALS) + / self::SECOND_INTERVALS + ); + + if (count($splitTime) === 0) { + return $this->fallbackConverter->convertTime($uuidTimestamp); + } + + return new Time($splitTime['sec'], $splitTime['usec']); + } + + /** + * @param int|float $time The time to split into seconds and microseconds + * + * @return string[] + */ + private function splitTime($time): array + { + $split = explode('.', (string) $time, 2); + + // If the $time value is a float but $split only has 1 element, then the + // float math was rounded up to the next second, so we want to return + // an empty array to allow use of the fallback converter. + if (is_float($time) && count($split) === 1) { + return []; + } + + if (count($split) === 1) { + return [ + 'sec' => $split[0], + 'usec' => '0', + ]; + } + + // If the microseconds are less than six characters AND the length of + // the number is greater than or equal to the PHP precision, then it's + // possible that we lost some precision for the microseconds. Return an + // empty array, so that we can choose to use the fallback converter. + if (strlen($split[1]) < 6 && strlen((string) $time) >= $this->phpPrecision) { + return []; + } + + $microseconds = $split[1]; + + // Ensure the microseconds are no longer than 6 digits. If they are, + // truncate the number to the first 6 digits and round up, if needed. + if (strlen($microseconds) > 6) { + $roundingDigit = (int) substr($microseconds, 6, 1); + $microseconds = (int) substr($microseconds, 0, 6); + + if ($roundingDigit >= 5) { + $microseconds++; + } + } + + return [ + 'sec' => $split[0], + 'usec' => str_pad((string) $microseconds, 6, '0', STR_PAD_RIGHT), + ]; + } +} diff --git a/vendor/ramsey/uuid/src/Converter/TimeConverterInterface.php b/vendor/ramsey/uuid/src/Converter/TimeConverterInterface.php new file mode 100644 index 0000000..1e84807 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/TimeConverterInterface.php @@ -0,0 +1,58 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Converter; + +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Time; + +/** + * A time converter converts timestamps into representations that may be used + * in UUIDs + * + * @psalm-immutable + */ +interface TimeConverterInterface +{ + /** + * Uses the provided seconds and micro-seconds to calculate the count of + * 100-nanosecond intervals since UTC 00:00:00.00, 15 October 1582, for + * RFC 4122 variant UUIDs + * + * @link http://tools.ietf.org/html/rfc4122#section-4.2.2 RFC 4122, § 4.2.2: Generation Details + * + * @param string $seconds A string representation of the number of seconds + * since the Unix epoch for the time to calculate + * @param string $microseconds A string representation of the micro-seconds + * associated with the time to calculate + * + * @return Hexadecimal The full UUID timestamp as a Hexadecimal value + * + * @psalm-pure + */ + public function calculateTime(string $seconds, string $microseconds): Hexadecimal; + + /** + * Converts a timestamp extracted from a UUID to a Unix timestamp + * + * @param Hexadecimal $uuidTimestamp A hexadecimal representation of a UUID + * timestamp; a UUID timestamp is a count of 100-nanosecond intervals + * since UTC 00:00:00.00, 15 October 1582. + * + * @return Time An instance of {@see Time} + * + * @psalm-pure + */ + public function convertTime(Hexadecimal $uuidTimestamp): Time; +} diff --git a/vendor/ramsey/uuid/src/DegradedUuid.php b/vendor/ramsey/uuid/src/DegradedUuid.php new file mode 100644 index 0000000..9166042 --- /dev/null +++ b/vendor/ramsey/uuid/src/DegradedUuid.php @@ -0,0 +1,25 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +/** + * @deprecated DegradedUuid is no longer necessary to represent UUIDs on 32-bit + * systems. Transition typehints to {@see UuidInterface}. + * + * @psalm-immutable + */ +class DegradedUuid extends Uuid +{ +} diff --git a/vendor/ramsey/uuid/src/DeprecatedUuidInterface.php b/vendor/ramsey/uuid/src/DeprecatedUuidInterface.php new file mode 100644 index 0000000..ed6d9de --- /dev/null +++ b/vendor/ramsey/uuid/src/DeprecatedUuidInterface.php @@ -0,0 +1,147 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +use DateTimeInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; + +/** + * This interface encapsulates deprecated methods for ramsey/uuid; this + * interface and its methods will be removed in ramsey/uuid 5.0.0. + * + * @psalm-immutable + */ +interface DeprecatedUuidInterface +{ + /** + * @deprecated This method will be removed in 5.0.0. There is no alternative + * recommendation, so plan accordingly. + */ + public function getNumberConverter(): NumberConverterInterface; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. + * + * @return string[] + */ + public function getFieldsHex(): array; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqHiAndReserved()}. + */ + public function getClockSeqHiAndReservedHex(): string; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqLow()}. + */ + public function getClockSeqLowHex(): string; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeq()}. + */ + public function getClockSequenceHex(): string; + + /** + * @deprecated In ramsey/uuid version 5.0.0, this will be removed from the + * interface. It is available at {@see UuidV1::getDateTime()}. + */ + public function getDateTime(): DateTimeInterface; + + /** + * @deprecated This method will be removed in 5.0.0. There is no direct + * alternative, but the same information may be obtained by splitting + * in half the value returned by {@see UuidInterface::getHex()}. + */ + public function getLeastSignificantBitsHex(): string; + + /** + * @deprecated This method will be removed in 5.0.0. There is no direct + * alternative, but the same information may be obtained by splitting + * in half the value returned by {@see UuidInterface::getHex()}. + */ + public function getMostSignificantBitsHex(): string; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getNode()}. + */ + public function getNodeHex(): string; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeHiAndVersion()}. + */ + public function getTimeHiAndVersionHex(): string; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeLow()}. + */ + public function getTimeLowHex(): string; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeMid()}. + */ + public function getTimeMidHex(): string; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimestamp()}. + */ + public function getTimestampHex(): string; + + /** + * @deprecated In ramsey/uuid version 5.0.0, this will be removed from this + * interface. It has moved to {@see \Ramsey\Uuid\Rfc4122\UuidInterface::getUrn()}. + */ + public function getUrn(): string; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVariant()}. + */ + public function getVariant(): ?int; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVersion()}. + */ + public function getVersion(): ?int; +} diff --git a/vendor/ramsey/uuid/src/DeprecatedUuidMethodsTrait.php b/vendor/ramsey/uuid/src/DeprecatedUuidMethodsTrait.php new file mode 100644 index 0000000..3428295 --- /dev/null +++ b/vendor/ramsey/uuid/src/DeprecatedUuidMethodsTrait.php @@ -0,0 +1,370 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +use DateTimeImmutable; +use DateTimeInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\DateTimeException; +use Ramsey\Uuid\Exception\UnsupportedOperationException; +use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Throwable; + +use function str_pad; +use function substr; + +use const STR_PAD_LEFT; + +/** + * This trait encapsulates deprecated methods for ramsey/uuid; this trait and + * its methods will be removed in ramsey/uuid 5.0.0. + * + * @psalm-immutable + */ +trait DeprecatedUuidMethodsTrait +{ + /** + * @var Rfc4122FieldsInterface + */ + protected $fields; + + /** + * @var NumberConverterInterface + */ + protected $numberConverter; + + /** + * @var TimeConverterInterface + */ + protected $timeConverter; + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqHiAndReserved()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + */ + public function getClockSeqHiAndReserved(): string + { + return $this->numberConverter->fromHex($this->fields->getClockSeqHiAndReserved()->toString()); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqHiAndReserved()}. + */ + public function getClockSeqHiAndReservedHex(): string + { + return $this->fields->getClockSeqHiAndReserved()->toString(); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqLow()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + */ + public function getClockSeqLow(): string + { + return $this->numberConverter->fromHex($this->fields->getClockSeqLow()->toString()); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqLow()}. + */ + public function getClockSeqLowHex(): string + { + return $this->fields->getClockSeqLow()->toString(); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getClockSeq()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + */ + public function getClockSequence(): string + { + return $this->numberConverter->fromHex($this->fields->getClockSeq()->toString()); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getClockSeq()}. + */ + public function getClockSequenceHex(): string + { + return $this->fields->getClockSeq()->toString(); + } + + /** + * @deprecated This method will be removed in 5.0.0. There is no alternative + * recommendation, so plan accordingly. + */ + public function getNumberConverter(): NumberConverterInterface + { + return $this->numberConverter; + } + + /** + * @deprecated In ramsey/uuid version 5.0.0, this will be removed. + * It is available at {@see UuidV1::getDateTime()}. + * + * @return DateTimeImmutable An immutable instance of DateTimeInterface + * + * @throws UnsupportedOperationException if UUID is not time-based + * @throws DateTimeException if DateTime throws an exception/error + */ + public function getDateTime(): DateTimeInterface + { + if ($this->fields->getVersion() !== 1) { + throw new UnsupportedOperationException('Not a time-based UUID'); + } + + $time = $this->timeConverter->convertTime($this->fields->getTimestamp()); + + try { + return new DateTimeImmutable( + '@' + . $time->getSeconds()->toString() + . '.' + . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT) + ); + } catch (Throwable $e) { + throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e); + } + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. + * + * @return string[] + */ + public function getFieldsHex(): array + { + return [ + 'time_low' => $this->fields->getTimeLow()->toString(), + 'time_mid' => $this->fields->getTimeMid()->toString(), + 'time_hi_and_version' => $this->fields->getTimeHiAndVersion()->toString(), + 'clock_seq_hi_and_reserved' => $this->fields->getClockSeqHiAndReserved()->toString(), + 'clock_seq_low' => $this->fields->getClockSeqLow()->toString(), + 'node' => $this->fields->getNode()->toString(), + ]; + } + + /** + * @deprecated This method will be removed in 5.0.0. There is no direct + * alternative, but the same information may be obtained by splitting + * in half the value returned by {@see UuidInterface::getHex()}. + */ + public function getLeastSignificantBits(): string + { + $leastSignificantHex = substr($this->getHex()->toString(), 16); + + return $this->numberConverter->fromHex($leastSignificantHex); + } + + /** + * @deprecated This method will be removed in 5.0.0. There is no direct + * alternative, but the same information may be obtained by splitting + * in half the value returned by {@see UuidInterface::getHex()}. + */ + public function getLeastSignificantBitsHex(): string + { + return substr($this->getHex()->toString(), 16); + } + + /** + * @deprecated This method will be removed in 5.0.0. There is no direct + * alternative, but the same information may be obtained by splitting + * in half the value returned by {@see UuidInterface::getHex()}. + */ + public function getMostSignificantBits(): string + { + $mostSignificantHex = substr($this->getHex()->toString(), 0, 16); + + return $this->numberConverter->fromHex($mostSignificantHex); + } + + /** + * @deprecated This method will be removed in 5.0.0. There is no direct + * alternative, but the same information may be obtained by splitting + * in half the value returned by {@see UuidInterface::getHex()}. + */ + public function getMostSignificantBitsHex(): string + { + return substr($this->getHex()->toString(), 0, 16); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getNode()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + */ + public function getNode(): string + { + return $this->numberConverter->fromHex($this->fields->getNode()->toString()); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getNode()}. + */ + public function getNodeHex(): string + { + return $this->fields->getNode()->toString(); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimeHiAndVersion()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + */ + public function getTimeHiAndVersion(): string + { + return $this->numberConverter->fromHex($this->fields->getTimeHiAndVersion()->toString()); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimeHiAndVersion()}. + */ + public function getTimeHiAndVersionHex(): string + { + return $this->fields->getTimeHiAndVersion()->toString(); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimeLow()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + */ + public function getTimeLow(): string + { + return $this->numberConverter->fromHex($this->fields->getTimeLow()->toString()); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimeLow()}. + */ + public function getTimeLowHex(): string + { + return $this->fields->getTimeLow()->toString(); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimeMid()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + */ + public function getTimeMid(): string + { + return $this->numberConverter->fromHex($this->fields->getTimeMid()->toString()); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimeMid()}. + */ + public function getTimeMidHex(): string + { + return $this->fields->getTimeMid()->toString(); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimestamp()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + */ + public function getTimestamp(): string + { + if ($this->fields->getVersion() !== 1) { + throw new UnsupportedOperationException('Not a time-based UUID'); + } + + return $this->numberConverter->fromHex($this->fields->getTimestamp()->toString()); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimestamp()}. + */ + public function getTimestampHex(): string + { + if ($this->fields->getVersion() !== 1) { + throw new UnsupportedOperationException('Not a time-based UUID'); + } + + return $this->fields->getTimestamp()->toString(); + } + + /** + * @deprecated This has moved to {@see Rfc4122FieldsInterface::getUrn()} and + * is available on {@see \Ramsey\Uuid\Rfc4122\UuidV1}, + * {@see \Ramsey\Uuid\Rfc4122\UuidV3}, {@see \Ramsey\Uuid\Rfc4122\UuidV4}, + * and {@see \Ramsey\Uuid\Rfc4122\UuidV5}. + */ + public function getUrn(): string + { + return 'urn:uuid:' . $this->toString(); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVariant()}. + */ + public function getVariant(): ?int + { + return $this->fields->getVariant(); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVersion()}. + */ + public function getVersion(): ?int + { + return $this->fields->getVersion(); + } +} diff --git a/vendor/ramsey/uuid/src/Exception/BuilderNotFoundException.php b/vendor/ramsey/uuid/src/Exception/BuilderNotFoundException.php new file mode 100644 index 0000000..220ffed --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/BuilderNotFoundException.php @@ -0,0 +1,24 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use RuntimeException as PhpRuntimeException; + +/** + * Thrown to indicate that no suitable builder could be found + */ +class BuilderNotFoundException extends PhpRuntimeException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/DateTimeException.php b/vendor/ramsey/uuid/src/Exception/DateTimeException.php new file mode 100644 index 0000000..5f0e658 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/DateTimeException.php @@ -0,0 +1,24 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use RuntimeException as PhpRuntimeException; + +/** + * Thrown to indicate that the PHP DateTime extension encountered an exception/error + */ +class DateTimeException extends PhpRuntimeException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/DceSecurityException.php b/vendor/ramsey/uuid/src/Exception/DceSecurityException.php new file mode 100644 index 0000000..e6d8001 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/DceSecurityException.php @@ -0,0 +1,25 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use RuntimeException as PhpRuntimeException; + +/** + * Thrown to indicate an exception occurred while dealing with DCE Security + * (version 2) UUIDs + */ +class DceSecurityException extends PhpRuntimeException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/InvalidArgumentException.php b/vendor/ramsey/uuid/src/Exception/InvalidArgumentException.php new file mode 100644 index 0000000..2a1fa3a --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/InvalidArgumentException.php @@ -0,0 +1,24 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use InvalidArgumentException as PhpInvalidArgumentException; + +/** + * Thrown to indicate that the argument received is not valid + */ +class InvalidArgumentException extends PhpInvalidArgumentException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/InvalidBytesException.php b/vendor/ramsey/uuid/src/Exception/InvalidBytesException.php new file mode 100644 index 0000000..1c94f65 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/InvalidBytesException.php @@ -0,0 +1,24 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use RuntimeException as PhpRuntimeException; + +/** + * Thrown to indicate that the bytes being operated on are invalid in some way + */ +class InvalidBytesException extends PhpRuntimeException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/InvalidUuidStringException.php b/vendor/ramsey/uuid/src/Exception/InvalidUuidStringException.php new file mode 100644 index 0000000..6d97581 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/InvalidUuidStringException.php @@ -0,0 +1,25 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +/** + * Thrown to indicate that the string received is not a valid UUID + * + * The InvalidArgumentException that this extends is the ramsey/uuid version + * of this exception. It exists in the same namespace as this class. + */ +class InvalidUuidStringException extends InvalidArgumentException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/NameException.php b/vendor/ramsey/uuid/src/Exception/NameException.php new file mode 100644 index 0000000..fd96a1f --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/NameException.php @@ -0,0 +1,25 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use RuntimeException as PhpRuntimeException; + +/** + * Thrown to indicate that an error occurred while attempting to hash a + * namespace and name + */ +class NameException extends PhpRuntimeException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/NodeException.php b/vendor/ramsey/uuid/src/Exception/NodeException.php new file mode 100644 index 0000000..0dbdd50 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/NodeException.php @@ -0,0 +1,24 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use RuntimeException as PhpRuntimeException; + +/** + * Thrown to indicate that attempting to fetch or create a node ID encountered an error + */ +class NodeException extends PhpRuntimeException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/RandomSourceException.php b/vendor/ramsey/uuid/src/Exception/RandomSourceException.php new file mode 100644 index 0000000..a44dd34 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/RandomSourceException.php @@ -0,0 +1,27 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use RuntimeException as PhpRuntimeException; + +/** + * Thrown to indicate that the source of random data encountered an error + * + * This exception is used mostly to indicate that random_bytes() or random_int() + * threw an exception. However, it may be used for other sources of random data. + */ +class RandomSourceException extends PhpRuntimeException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/TimeSourceException.php b/vendor/ramsey/uuid/src/Exception/TimeSourceException.php new file mode 100644 index 0000000..fc9cf36 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/TimeSourceException.php @@ -0,0 +1,24 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use RuntimeException as PhpRuntimeException; + +/** + * Thrown to indicate that the source of time encountered an error + */ +class TimeSourceException extends PhpRuntimeException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/UnableToBuildUuidException.php b/vendor/ramsey/uuid/src/Exception/UnableToBuildUuidException.php new file mode 100644 index 0000000..5ba26d8 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/UnableToBuildUuidException.php @@ -0,0 +1,24 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use RuntimeException as PhpRuntimeException; + +/** + * Thrown to indicate a builder is unable to build a UUID + */ +class UnableToBuildUuidException extends PhpRuntimeException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/UnsupportedOperationException.php b/vendor/ramsey/uuid/src/Exception/UnsupportedOperationException.php new file mode 100644 index 0000000..e1b3eda --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/UnsupportedOperationException.php @@ -0,0 +1,24 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use LogicException as PhpLogicException; + +/** + * Thrown to indicate that the requested operation is not supported + */ +class UnsupportedOperationException extends PhpLogicException implements UuidExceptionInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Exception/UuidExceptionInterface.php b/vendor/ramsey/uuid/src/Exception/UuidExceptionInterface.php new file mode 100644 index 0000000..a2f1c10 --- /dev/null +++ b/vendor/ramsey/uuid/src/Exception/UuidExceptionInterface.php @@ -0,0 +1,21 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Exception; + +use Throwable; + +interface UuidExceptionInterface extends Throwable +{ +} diff --git a/vendor/ramsey/uuid/src/FeatureSet.php b/vendor/ramsey/uuid/src/FeatureSet.php new file mode 100644 index 0000000..a8ab2fd --- /dev/null +++ b/vendor/ramsey/uuid/src/FeatureSet.php @@ -0,0 +1,449 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +use Ramsey\Uuid\Builder\BuilderCollection; +use Ramsey\Uuid\Builder\FallbackBuilder; +use Ramsey\Uuid\Builder\UuidBuilderInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Codec\GuidStringCodec; +use Ramsey\Uuid\Codec\StringCodec; +use Ramsey\Uuid\Converter\Number\GenericNumberConverter; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\Time\GenericTimeConverter; +use Ramsey\Uuid\Converter\Time\PhpTimeConverter; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Generator\DceSecurityGenerator; +use Ramsey\Uuid\Generator\DceSecurityGeneratorInterface; +use Ramsey\Uuid\Generator\NameGeneratorFactory; +use Ramsey\Uuid\Generator\NameGeneratorInterface; +use Ramsey\Uuid\Generator\PeclUuidNameGenerator; +use Ramsey\Uuid\Generator\PeclUuidRandomGenerator; +use Ramsey\Uuid\Generator\PeclUuidTimeGenerator; +use Ramsey\Uuid\Generator\RandomGeneratorFactory; +use Ramsey\Uuid\Generator\RandomGeneratorInterface; +use Ramsey\Uuid\Generator\TimeGeneratorFactory; +use Ramsey\Uuid\Generator\TimeGeneratorInterface; +use Ramsey\Uuid\Guid\GuidBuilder; +use Ramsey\Uuid\Math\BrickMathCalculator; +use Ramsey\Uuid\Math\CalculatorInterface; +use Ramsey\Uuid\Nonstandard\UuidBuilder as NonstandardUuidBuilder; +use Ramsey\Uuid\Provider\Dce\SystemDceSecurityProvider; +use Ramsey\Uuid\Provider\DceSecurityProviderInterface; +use Ramsey\Uuid\Provider\Node\FallbackNodeProvider; +use Ramsey\Uuid\Provider\Node\NodeProviderCollection; +use Ramsey\Uuid\Provider\Node\RandomNodeProvider; +use Ramsey\Uuid\Provider\Node\SystemNodeProvider; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Provider\Time\SystemTimeProvider; +use Ramsey\Uuid\Provider\TimeProviderInterface; +use Ramsey\Uuid\Rfc4122\UuidBuilder as Rfc4122UuidBuilder; +use Ramsey\Uuid\Validator\GenericValidator; +use Ramsey\Uuid\Validator\ValidatorInterface; + +use const PHP_INT_SIZE; + +/** + * FeatureSet detects and exposes available features in the current environment + * + * A feature set is used by UuidFactory to determine the available features and + * capabilities of the environment. + */ +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 DceSecurityGeneratorInterface + */ + private $dceSecurityGenerator; + + /** + * @var NameGeneratorInterface + */ + private $nameGenerator; + + /** + * @var NodeProviderInterface + */ + private $nodeProvider; + + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * @var RandomGeneratorInterface + */ + private $randomGenerator; + + /** + * @var TimeGeneratorInterface + */ + private $timeGenerator; + + /** + * @var TimeProviderInterface + */ + private $timeProvider; + + /** + * @var ValidatorInterface + */ + private $validator; + + /** + * @var CalculatorInterface + */ + private $calculator; + + /** + * @param bool $useGuids True build UUIDs using the GuidStringCodec + * @param bool $force32Bit True to force the use of 32-bit functionality + * (primarily for testing purposes) + * @param bool $forceNoBigNumber True to disable the use of moontoast/math + * (primarily for testing purposes) + * @param bool $ignoreSystemNode True to disable attempts to check for the + * system node ID (primarily for testing purposes) + * @param bool $enablePecl True to enable the use of the PeclUuidTimeGenerator + * to generate version 1 UUIDs + */ + public function __construct( + bool $useGuids = false, + bool $force32Bit = false, + bool $forceNoBigNumber = false, + bool $ignoreSystemNode = false, + bool $enablePecl = false + ) { + $this->disableBigNumber = $forceNoBigNumber; + $this->disable64Bit = $force32Bit; + $this->ignoreSystemNode = $ignoreSystemNode; + $this->enablePecl = $enablePecl; + + $this->setCalculator(new BrickMathCalculator()); + $this->builder = $this->buildUuidBuilder($useGuids); + $this->codec = $this->buildCodec($useGuids); + $this->nodeProvider = $this->buildNodeProvider(); + $this->nameGenerator = $this->buildNameGenerator(); + $this->randomGenerator = $this->buildRandomGenerator(); + $this->setTimeProvider(new SystemTimeProvider()); + $this->setDceSecurityProvider(new SystemDceSecurityProvider()); + $this->validator = new GenericValidator(); + } + + /** + * Returns the builder configured for this environment + */ + public function getBuilder(): UuidBuilderInterface + { + return $this->builder; + } + + /** + * Returns the calculator configured for this environment + */ + public function getCalculator(): CalculatorInterface + { + return $this->calculator; + } + + /** + * Returns the codec configured for this environment + */ + public function getCodec(): CodecInterface + { + return $this->codec; + } + + /** + * Returns the DCE Security generator configured for this environment + */ + public function getDceSecurityGenerator(): DceSecurityGeneratorInterface + { + return $this->dceSecurityGenerator; + } + + /** + * Returns the name generator configured for this environment + */ + public function getNameGenerator(): NameGeneratorInterface + { + return $this->nameGenerator; + } + + /** + * Returns the node provider configured for this environment + */ + public function getNodeProvider(): NodeProviderInterface + { + return $this->nodeProvider; + } + + /** + * Returns the number converter configured for this environment + */ + public function getNumberConverter(): NumberConverterInterface + { + return $this->numberConverter; + } + + /** + * Returns the random generator configured for this environment + */ + public function getRandomGenerator(): RandomGeneratorInterface + { + return $this->randomGenerator; + } + + /** + * Returns the time converter configured for this environment + */ + public function getTimeConverter(): TimeConverterInterface + { + return $this->timeConverter; + } + + /** + * Returns the time generator configured for this environment + */ + public function getTimeGenerator(): TimeGeneratorInterface + { + return $this->timeGenerator; + } + + /** + * Returns the validator configured for this environment + */ + public function getValidator(): ValidatorInterface + { + return $this->validator; + } + + /** + * Sets the calculator to use in this environment + */ + public function setCalculator(CalculatorInterface $calculator): void + { + $this->calculator = $calculator; + $this->numberConverter = $this->buildNumberConverter($calculator); + $this->timeConverter = $this->buildTimeConverter($calculator); + + /** @psalm-suppress RedundantPropertyInitializationCheck */ + if (isset($this->timeProvider)) { + $this->timeGenerator = $this->buildTimeGenerator($this->timeProvider); + } + } + + /** + * Sets the DCE Security provider to use in this environment + */ + public function setDceSecurityProvider(DceSecurityProviderInterface $dceSecurityProvider): void + { + $this->dceSecurityGenerator = $this->buildDceSecurityGenerator($dceSecurityProvider); + } + + /** + * Sets the node provider to use in this environment + */ + public function setNodeProvider(NodeProviderInterface $nodeProvider): void + { + $this->nodeProvider = $nodeProvider; + $this->timeGenerator = $this->buildTimeGenerator($this->timeProvider); + } + + /** + * Sets the time provider to use in this environment + */ + public function setTimeProvider(TimeProviderInterface $timeProvider): void + { + $this->timeProvider = $timeProvider; + $this->timeGenerator = $this->buildTimeGenerator($timeProvider); + } + + /** + * Set the validator to use in this environment + */ + public function setValidator(ValidatorInterface $validator): void + { + $this->validator = $validator; + } + + /** + * Returns a codec configured for this environment + * + * @param bool $useGuids Whether to build UUIDs using the GuidStringCodec + */ + private function buildCodec(bool $useGuids = false): CodecInterface + { + if ($useGuids) { + return new GuidStringCodec($this->builder); + } + + return new StringCodec($this->builder); + } + + /** + * Returns a DCE Security generator configured for this environment + */ + private function buildDceSecurityGenerator( + DceSecurityProviderInterface $dceSecurityProvider + ): DceSecurityGeneratorInterface { + return new DceSecurityGenerator( + $this->numberConverter, + $this->timeGenerator, + $dceSecurityProvider + ); + } + + /** + * Returns a node provider configured for this environment + */ + private function buildNodeProvider(): NodeProviderInterface + { + if ($this->ignoreSystemNode) { + return new RandomNodeProvider(); + } + + return new FallbackNodeProvider(new NodeProviderCollection([ + new SystemNodeProvider(), + new RandomNodeProvider(), + ])); + } + + /** + * Returns a number converter configured for this environment + */ + private function buildNumberConverter(CalculatorInterface $calculator): NumberConverterInterface + { + return new GenericNumberConverter($calculator); + } + + /** + * Returns a random generator configured for this environment + */ + private function buildRandomGenerator(): RandomGeneratorInterface + { + if ($this->enablePecl) { + return new PeclUuidRandomGenerator(); + } + + return (new RandomGeneratorFactory())->getGenerator(); + } + + /** + * Returns a time generator configured for this environment + * + * @param TimeProviderInterface $timeProvider The time provider to use with + * the time generator + */ + private function buildTimeGenerator(TimeProviderInterface $timeProvider): TimeGeneratorInterface + { + if ($this->enablePecl) { + return new PeclUuidTimeGenerator(); + } + + return (new TimeGeneratorFactory( + $this->nodeProvider, + $this->timeConverter, + $timeProvider + ))->getGenerator(); + } + + /** + * Returns a name generator configured for this environment + */ + private function buildNameGenerator(): NameGeneratorInterface + { + if ($this->enablePecl) { + return new PeclUuidNameGenerator(); + } + + return (new NameGeneratorFactory())->getGenerator(); + } + + /** + * Returns a time converter configured for this environment + */ + private function buildTimeConverter(CalculatorInterface $calculator): TimeConverterInterface + { + $genericConverter = new GenericTimeConverter($calculator); + + if ($this->is64BitSystem()) { + return new PhpTimeConverter($calculator, $genericConverter); + } + + return $genericConverter; + } + + /** + * Returns a UUID builder configured for this environment + * + * @param bool $useGuids Whether to build UUIDs using the GuidStringCodec + */ + private function buildUuidBuilder(bool $useGuids = false): UuidBuilderInterface + { + if ($useGuids) { + return new GuidBuilder($this->numberConverter, $this->timeConverter); + } + + /** @psalm-suppress ImpureArgument */ + return new FallbackBuilder(new BuilderCollection([ + new Rfc4122UuidBuilder($this->numberConverter, $this->timeConverter), + new NonstandardUuidBuilder($this->numberConverter, $this->timeConverter), + ])); + } + + /** + * Returns true if the PHP build is 64-bit + */ + private function is64BitSystem(): bool + { + return PHP_INT_SIZE === 8 && !$this->disable64Bit; + } +} diff --git a/vendor/ramsey/uuid/src/Fields/FieldsInterface.php b/vendor/ramsey/uuid/src/Fields/FieldsInterface.php new file mode 100644 index 0000000..f1b7a29 --- /dev/null +++ b/vendor/ramsey/uuid/src/Fields/FieldsInterface.php @@ -0,0 +1,32 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Fields; + +use Serializable; + +/** + * UUIDs are comprised of unsigned integers, the bytes of which are separated + * into fields and arranged in a particular layout defined by the specification + * for the variant + * + * @psalm-immutable + */ +interface FieldsInterface extends Serializable +{ + /** + * Returns the bytes that comprise the fields + */ + public function getBytes(): string; +} diff --git a/vendor/ramsey/uuid/src/Fields/SerializableFieldsTrait.php b/vendor/ramsey/uuid/src/Fields/SerializableFieldsTrait.php new file mode 100644 index 0000000..16e6525 --- /dev/null +++ b/vendor/ramsey/uuid/src/Fields/SerializableFieldsTrait.php @@ -0,0 +1,86 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Fields; + +use ValueError; + +use function base64_decode; +use function sprintf; +use function strlen; + +/** + * Provides common serialization functionality to fields + * + * @psalm-immutable + */ +trait SerializableFieldsTrait +{ + /** + * @param string $bytes The bytes that comprise the fields + */ + abstract public function __construct(string $bytes); + + /** + * Returns the bytes that comprise the fields + */ + abstract public function getBytes(): string; + + /** + * Returns a string representation of object + */ + public function serialize(): string + { + return $this->getBytes(); + } + + /** + * @return array{bytes: string} + */ + public function __serialize(): array + { + return ['bytes' => $this->getBytes()]; + } + + /** + * Constructs the object from a serialized string representation + * + * @param string $serialized The serialized string representation of the object + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + * @psalm-suppress UnusedMethodCall + */ + public function unserialize($serialized): void + { + if (strlen($serialized) === 16) { + $this->__construct($serialized); + } else { + $this->__construct(base64_decode($serialized)); + } + } + + /** + * @param array{bytes: string} $data + */ + public function __unserialize(array $data): void + { + // @codeCoverageIgnoreStart + if (!isset($data['bytes'])) { + throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__)); + } + // @codeCoverageIgnoreEnd + + $this->unserialize($data['bytes']); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/CombGenerator.php b/vendor/ramsey/uuid/src/Generator/CombGenerator.php new file mode 100644 index 0000000..49b0938 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/CombGenerator.php @@ -0,0 +1,127 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Exception\InvalidArgumentException; + +use function bin2hex; +use function explode; +use function hex2bin; +use function microtime; +use function str_pad; +use function substr; + +use const STR_PAD_LEFT; + +/** + * CombGenerator generates COMBs (combined UUID/timestamp) + * + * The CombGenerator, when used with the StringCodec (and, by proxy, the + * TimestampLastCombCodec) or the TimestampFirstCombCodec, combines the current + * timestamp with a UUID (hence the name "COMB"). The timestamp either appears + * as the first or last 48 bits of the COMB, depending on the codec used. + * + * By default, COMBs will have the timestamp set as the last 48 bits of the + * identifier. + * + * ``` php + * $factory = new UuidFactory(); + * + * $factory->setRandomGenerator(new CombGenerator( + * $factory->getRandomGenerator(), + * $factory->getNumberConverter() + * )); + * + * $comb = $factory->uuid4(); + * ``` + * + * To generate a COMB with the timestamp as the first 48 bits, set the + * TimestampFirstCombCodec as the codec. + * + * ``` php + * $factory->setCodec(new TimestampFirstCombCodec($factory->getUuidBuilder())); + * ``` + * + * @link https://www.informit.com/articles/printerfriendly/25862 The Cost of GUIDs as Primary Keys + */ +class CombGenerator implements RandomGeneratorInterface +{ + public const TIMESTAMP_BYTES = 6; + + /** + * @var RandomGeneratorInterface + */ + private $randomGenerator; + + /** + * @var NumberConverterInterface + */ + private $converter; + + public function __construct( + RandomGeneratorInterface $generator, + NumberConverterInterface $numberConverter + ) { + $this->converter = $numberConverter; + $this->randomGenerator = $generator; + } + + /** + * @throws InvalidArgumentException if $length is not a positive integer + * greater than or equal to CombGenerator::TIMESTAMP_BYTES + * + * @inheritDoc + */ + public function generate(int $length): string + { + if ($length < self::TIMESTAMP_BYTES || $length < 0) { + throw new InvalidArgumentException( + 'Length must be a positive integer greater than or equal to ' . self::TIMESTAMP_BYTES + ); + } + + $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 (string) hex2bin( + str_pad( + bin2hex($hash), + $length - self::TIMESTAMP_BYTES, + '0' + ) + . $lsbTime + ); + } + + /** + * Returns current timestamp a string integer, precise to 0.00001 seconds + */ + private function timestamp(): string + { + $time = explode(' ', microtime(false)); + + return $time[1] . substr($time[0], 2, 5); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php b/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php new file mode 100644 index 0000000..aca8c5d --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php @@ -0,0 +1,160 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Exception\DceSecurityException; +use Ramsey\Uuid\Provider\DceSecurityProviderInterface; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Uuid; + +use function hex2bin; +use function in_array; +use function pack; +use function str_pad; +use function strlen; +use function substr_replace; + +use const STR_PAD_LEFT; + +/** + * DceSecurityGenerator generates strings of binary data based on a local + * domain, local identifier, node ID, clock sequence, and the current time + */ +class DceSecurityGenerator implements DceSecurityGeneratorInterface +{ + private const DOMAINS = [ + Uuid::DCE_DOMAIN_PERSON, + Uuid::DCE_DOMAIN_GROUP, + Uuid::DCE_DOMAIN_ORG, + ]; + + /** + * Upper bounds for the clock sequence in DCE Security UUIDs. + */ + private const CLOCK_SEQ_HIGH = 63; + + /** + * Lower bounds for the clock sequence in DCE Security UUIDs. + */ + private const CLOCK_SEQ_LOW = 0; + + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var TimeGeneratorInterface + */ + private $timeGenerator; + + /** + * @var DceSecurityProviderInterface + */ + private $dceSecurityProvider; + + public function __construct( + NumberConverterInterface $numberConverter, + TimeGeneratorInterface $timeGenerator, + DceSecurityProviderInterface $dceSecurityProvider + ) { + $this->numberConverter = $numberConverter; + $this->timeGenerator = $timeGenerator; + $this->dceSecurityProvider = $dceSecurityProvider; + } + + public function generate( + int $localDomain, + ?IntegerObject $localIdentifier = null, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): string { + if (!in_array($localDomain, self::DOMAINS)) { + throw new DceSecurityException( + 'Local domain must be a valid DCE Security domain' + ); + } + + if ($localIdentifier && $localIdentifier->isNegative()) { + throw new DceSecurityException( + 'Local identifier out of bounds; it must be a value between 0 and 4294967295' + ); + } + + if ($clockSeq > self::CLOCK_SEQ_HIGH || $clockSeq < self::CLOCK_SEQ_LOW) { + throw new DceSecurityException( + 'Clock sequence out of bounds; it must be a value between 0 and 63' + ); + } + + switch ($localDomain) { + case Uuid::DCE_DOMAIN_ORG: + if ($localIdentifier === null) { + throw new DceSecurityException( + 'A local identifier must be provided for the org domain' + ); + } + + break; + case Uuid::DCE_DOMAIN_PERSON: + if ($localIdentifier === null) { + $localIdentifier = $this->dceSecurityProvider->getUid(); + } + + break; + case Uuid::DCE_DOMAIN_GROUP: + default: + if ($localIdentifier === null) { + $localIdentifier = $this->dceSecurityProvider->getGid(); + } + + break; + } + + $identifierHex = $this->numberConverter->toHex($localIdentifier->toString()); + + // The maximum value for the local identifier is 0xffffffff, or + // 4294967295. This is 8 hexadecimal digits, so if the length of + // hexadecimal digits is greater than 8, we know the value is greater + // than 0xffffffff. + if (strlen($identifierHex) > 8) { + throw new DceSecurityException( + 'Local identifier out of bounds; it must be a value between 0 and 4294967295' + ); + } + + $domainByte = pack('n', $localDomain)[1]; + $identifierBytes = (string) hex2bin(str_pad($identifierHex, 8, '0', STR_PAD_LEFT)); + + if ($node instanceof Hexadecimal) { + $node = $node->toString(); + } + + // Shift the clock sequence 8 bits to the left, so it matches 0x3f00. + if ($clockSeq !== null) { + $clockSeq = $clockSeq << 8; + } + + $bytes = $this->timeGenerator->generate($node, $clockSeq); + + // Replace bytes in the time-based UUID with DCE Security values. + $bytes = substr_replace($bytes, $identifierBytes, 0, 4); + $bytes = substr_replace($bytes, $domainByte, 9, 1); + + return $bytes; + } +} diff --git a/vendor/ramsey/uuid/src/Generator/DceSecurityGeneratorInterface.php b/vendor/ramsey/uuid/src/Generator/DceSecurityGeneratorInterface.php new file mode 100644 index 0000000..faa29a5 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/DceSecurityGeneratorInterface.php @@ -0,0 +1,53 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Rfc4122\UuidV2; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; + +/** + * A DCE Security generator generates strings of binary data based on a local + * domain, local identifier, node ID, clock sequence, and the current time + * + * @see UuidV2 + */ +interface DceSecurityGeneratorInterface +{ + /** + * Generate a binary string from a local domain, local identifier, node ID, + * clock sequence, and current time + * + * @param int $localDomain The local domain to use when generating bytes, + * according to DCE Security + * @param IntegerObject|null $localIdentifier The local identifier for the + * given domain; this may be a UID or GID on POSIX systems, if the local + * domain is person or group, or it may be a site-defined identifier + * if the local domain is org + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 string A binary string + */ + public function generate( + int $localDomain, + ?IntegerObject $localIdentifier = null, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): string; +} diff --git a/vendor/ramsey/uuid/src/Generator/DefaultNameGenerator.php b/vendor/ramsey/uuid/src/Generator/DefaultNameGenerator.php new file mode 100644 index 0000000..7303e9f --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/DefaultNameGenerator.php @@ -0,0 +1,48 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Exception\NameException; +use Ramsey\Uuid\UuidInterface; +use ValueError; + +use function hash; + +/** + * DefaultNameGenerator generates strings of binary data based on a namespace, + * name, and hashing algorithm + */ +class DefaultNameGenerator implements NameGeneratorInterface +{ + /** @psalm-pure */ + public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string + { + try { + /** @var string|bool $bytes */ + $bytes = @hash($hashAlgorithm, $ns->getBytes() . $name, true); + } catch (ValueError $e) { + $bytes = false; // keep same behavior than PHP 7 + } + + if ($bytes === false) { + throw new NameException(sprintf( + 'Unable to hash namespace and name with algorithm \'%s\'', + $hashAlgorithm + )); + } + + return (string) $bytes; + } +} diff --git a/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php b/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php new file mode 100644 index 0000000..d245c7b --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php @@ -0,0 +1,147 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Exception\RandomSourceException; +use Ramsey\Uuid\Exception\TimeSourceException; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Provider\TimeProviderInterface; +use Ramsey\Uuid\Type\Hexadecimal; +use Throwable; + +use function ctype_xdigit; +use function dechex; +use function hex2bin; +use function is_int; +use function pack; +use function sprintf; +use function str_pad; +use function strlen; + +use const STR_PAD_LEFT; + +/** + * DefaultTimeGenerator generates strings of binary data based on a node ID, + * clock sequence, and the current time + */ +class DefaultTimeGenerator implements TimeGeneratorInterface +{ + /** + * @var NodeProviderInterface + */ + private $nodeProvider; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * @var TimeProviderInterface + */ + private $timeProvider; + + public function __construct( + NodeProviderInterface $nodeProvider, + TimeConverterInterface $timeConverter, + TimeProviderInterface $timeProvider + ) { + $this->nodeProvider = $nodeProvider; + $this->timeConverter = $timeConverter; + $this->timeProvider = $timeProvider; + } + + /** + * @throws InvalidArgumentException if the parameters contain invalid values + * @throws RandomSourceException if random_int() throws an exception/error + * + * @inheritDoc + */ + public function generate($node = null, ?int $clockSeq = null): string + { + if ($node instanceof Hexadecimal) { + $node = $node->toString(); + } + + $node = $this->getValidNode($node); + + if ($clockSeq === null) { + try { + // This does not use "stable storage"; see RFC 4122, Section 4.2.1.1. + $clockSeq = random_int(0, 0x3fff); + } catch (Throwable $exception) { + throw new RandomSourceException( + $exception->getMessage(), + (int) $exception->getCode(), + $exception + ); + } + } + + $time = $this->timeProvider->getTime(); + + $uuidTime = $this->timeConverter->calculateTime( + $time->getSeconds()->toString(), + $time->getMicroseconds()->toString() + ); + + $timeHex = str_pad($uuidTime->toString(), 16, '0', STR_PAD_LEFT); + + if (strlen($timeHex) !== 16) { + throw new TimeSourceException(sprintf( + 'The generated time of \'%s\' is larger than expected', + $timeHex + )); + } + + $timeBytes = (string) hex2bin($timeHex); + + return $timeBytes[4] . $timeBytes[5] . $timeBytes[6] . $timeBytes[7] + . $timeBytes[2] . $timeBytes[3] + . $timeBytes[0] . $timeBytes[1] + . pack('n*', $clockSeq) + . $node; + } + + /** + * Uses the node provider given when constructing this instance to get + * the node ID (usually a MAC address) + * + * @param string|int|null $node A node value that may be used to override the node provider + * + * @return string 6-byte binary string representation of the node + * + * @throws InvalidArgumentException + */ + private function getValidNode($node): string + { + if ($node === null) { + $node = $this->nodeProvider->getNode(); + } + + // Convert the node to hex, if it is still an integer. + if (is_int($node)) { + $node = dechex($node); + } + + if (!ctype_xdigit((string) $node) || strlen((string) $node) > 12) { + throw new InvalidArgumentException('Invalid node value'); + } + + return (string) hex2bin(str_pad((string) $node, 12, '0', STR_PAD_LEFT)); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/NameGeneratorFactory.php b/vendor/ramsey/uuid/src/Generator/NameGeneratorFactory.php new file mode 100644 index 0000000..6f08e29 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/NameGeneratorFactory.php @@ -0,0 +1,30 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +/** + * NameGeneratorFactory retrieves a default name generator, based on the + * environment + */ +class NameGeneratorFactory +{ + /** + * Returns a default name generator, based on the current environment + */ + public function getGenerator(): NameGeneratorInterface + { + return new DefaultNameGenerator(); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/NameGeneratorInterface.php b/vendor/ramsey/uuid/src/Generator/NameGeneratorInterface.php new file mode 100644 index 0000000..cc43dd0 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/NameGeneratorInterface.php @@ -0,0 +1,38 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\UuidInterface; + +/** + * A name generator generates strings of binary data created by hashing together + * a namespace with a name, according to a hashing algorithm + */ +interface NameGeneratorInterface +{ + /** + * Generate a binary string from a namespace and name hashed together with + * the specified hashing algorithm + * + * @param UuidInterface $ns The namespace + * @param string $name The name to use for creating a UUID + * @param string $hashAlgorithm The hashing algorithm to use + * + * @return string A binary string + * + * @psalm-pure + */ + public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string; +} diff --git a/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php b/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php new file mode 100644 index 0000000..3780c5c --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php @@ -0,0 +1,54 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Exception\NameException; +use Ramsey\Uuid\UuidInterface; + +use function sprintf; +use function uuid_generate_md5; +use function uuid_generate_sha1; +use function uuid_parse; + +/** + * PeclUuidNameGenerator generates strings of binary data from a namespace and a + * name, using ext-uuid + * + * @link https://pecl.php.net/package/uuid ext-uuid + */ +class PeclUuidNameGenerator implements NameGeneratorInterface +{ + /** @psalm-pure */ + public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string + { + switch ($hashAlgorithm) { + case 'md5': + $uuid = uuid_generate_md5($ns->toString(), $name); + + break; + case 'sha1': + $uuid = uuid_generate_sha1($ns->toString(), $name); + + break; + default: + throw new NameException(sprintf( + 'Unable to hash namespace and name with algorithm \'%s\'', + $hashAlgorithm + )); + } + + return uuid_parse($uuid); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php b/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php new file mode 100644 index 0000000..07c47d2 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php @@ -0,0 +1,35 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use function uuid_create; +use function uuid_parse; + +use const UUID_TYPE_RANDOM; + +/** + * PeclUuidRandomGenerator generates strings of random binary data using ext-uuid + * + * @link https://pecl.php.net/package/uuid ext-uuid + */ +class PeclUuidRandomGenerator implements RandomGeneratorInterface +{ + public function generate(int $length): string + { + $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 0000000..e01f44e --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/PeclUuidTimeGenerator.php @@ -0,0 +1,39 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use function uuid_create; +use function uuid_parse; + +use const UUID_TYPE_TIME; + +/** + * PeclUuidTimeGenerator generates strings of binary data for time-base UUIDs, + * using ext-uuid + * + * @link https://pecl.php.net/package/uuid ext-uuid + */ +class PeclUuidTimeGenerator implements TimeGeneratorInterface +{ + /** + * @inheritDoc + */ + public function generate($node = null, ?int $clockSeq = null): string + { + $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 0000000..12edb96 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php @@ -0,0 +1,45 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Exception\RandomSourceException; +use Throwable; + +/** + * RandomBytesGenerator generates strings of random binary data using the + * built-in `random_bytes()` PHP function + * + * @link http://php.net/random_bytes random_bytes() + */ +class RandomBytesGenerator implements RandomGeneratorInterface +{ + /** + * @throws RandomSourceException if random_bytes() throws an exception/error + * + * @inheritDoc + */ + public function generate(int $length): string + { + try { + return random_bytes($length); + } catch (Throwable $exception) { + throw new RandomSourceException( + $exception->getMessage(), + (int) $exception->getCode(), + $exception + ); + } + } +} diff --git a/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php b/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php new file mode 100644 index 0000000..b723ac2 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php @@ -0,0 +1,30 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +/** + * RandomGeneratorFactory retrieves a default random generator, based on the + * environment + */ +class RandomGeneratorFactory +{ + /** + * Returns a default random generator, based on the current environment + */ + public function getGenerator(): RandomGeneratorInterface + { + 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 0000000..5c83cb4 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php @@ -0,0 +1,30 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +/** + * A random generator generates strings of random binary data + */ +interface RandomGeneratorInterface +{ + /** + * Generates a string of randomized binary data + * + * @param int $length The number of bytes of random binary data to generate + * + * @return string A binary string + */ + public function generate(int $length): string; +} diff --git a/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php b/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php new file mode 100644 index 0000000..24ed569 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php @@ -0,0 +1,55 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use RandomLib\Factory; +use RandomLib\Generator; + +/** + * RandomLibAdapter generates strings of random binary data using the + * paragonie/random-lib library + * + * @link https://packagist.org/packages/paragonie/random-lib paragonie/random-lib + */ +class RandomLibAdapter implements RandomGeneratorInterface +{ + /** + * @var Generator + */ + private $generator; + + /** + * Constructs a RandomLibAdapter + * + * By default, if no Generator is passed in, this creates a high-strength + * generator to use when generating random binary data. + * + * @param Generator|null $generator The generator to use when generating binary data + */ + public function __construct(?Generator $generator = null) + { + if ($generator === null) { + $factory = new Factory(); + $generator = $factory->getHighStrengthGenerator(); + } + + $this->generator = $generator; + } + + public function generate(int $length): string + { + return $this->generator->generate($length); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php b/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php new file mode 100644 index 0000000..3d55fc4 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php @@ -0,0 +1,63 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Provider\TimeProviderInterface; + +/** + * TimeGeneratorFactory retrieves a default time generator, based on the + * environment + */ +class TimeGeneratorFactory +{ + /** + * @var NodeProviderInterface + */ + private $nodeProvider; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * @var TimeProviderInterface + */ + private $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 + */ + public function getGenerator(): TimeGeneratorInterface + { + 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 0000000..18f21c4 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/TimeGeneratorInterface.php @@ -0,0 +1,38 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Type\Hexadecimal; + +/** + * A time generator generates strings of binary data based on a node ID, + * clock sequence, and the current time + */ +interface TimeGeneratorInterface +{ + /** + * Generate a binary string from a node ID, clock sequence, and current time + * + * @param Hexadecimal|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 string A binary string + */ + public function generate($node = null, ?int $clockSeq = null): string; +} diff --git a/vendor/ramsey/uuid/src/Guid/Fields.php b/vendor/ramsey/uuid/src/Guid/Fields.php new file mode 100644 index 0000000..d8a1a2b --- /dev/null +++ b/vendor/ramsey/uuid/src/Guid/Fields.php @@ -0,0 +1,194 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Guid; + +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Fields\SerializableFieldsTrait; +use Ramsey\Uuid\Rfc4122\FieldsInterface; +use Ramsey\Uuid\Rfc4122\NilTrait; +use Ramsey\Uuid\Rfc4122\VariantTrait; +use Ramsey\Uuid\Rfc4122\VersionTrait; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Uuid; + +use function bin2hex; +use function dechex; +use function hexdec; +use function pack; +use function sprintf; +use function str_pad; +use function strlen; +use function substr; +use function unpack; + +use const STR_PAD_LEFT; + +/** + * GUIDs are comprised of a set of named fields, according to RFC 4122 + * + * @see Guid + * + * @psalm-immutable + */ +final class Fields implements FieldsInterface +{ + use NilTrait; + use SerializableFieldsTrait; + use VariantTrait; + use VersionTrait; + + /** + * @var string + */ + private $bytes; + + /** + * @param string $bytes A 16-byte binary string representation of a UUID + * + * @throws InvalidArgumentException if the byte string is not exactly 16 bytes + * @throws InvalidArgumentException if the byte string does not represent a GUID + * @throws InvalidArgumentException if the byte string does not contain a valid version + */ + public function __construct(string $bytes) + { + if (strlen($bytes) !== 16) { + throw new InvalidArgumentException( + 'The byte string must be 16 bytes long; ' + . 'received ' . strlen($bytes) . ' bytes' + ); + } + + $this->bytes = $bytes; + + if (!$this->isCorrectVariant()) { + throw new InvalidArgumentException( + 'The byte string received does not conform to the RFC ' + . '4122 or Microsoft Corporation variants' + ); + } + + if (!$this->isCorrectVersion()) { + throw new InvalidArgumentException( + 'The byte string received does not contain a valid version' + ); + } + } + + public function getBytes(): string + { + return $this->bytes; + } + + public function getTimeLow(): Hexadecimal + { + // Swap the bytes from little endian to network byte order. + /** @var array $hex */ + $hex = unpack( + 'H*', + pack( + 'v*', + hexdec(bin2hex(substr($this->bytes, 2, 2))), + hexdec(bin2hex(substr($this->bytes, 0, 2))) + ) + ); + + return new Hexadecimal((string) ($hex[1] ?? '')); + } + + public function getTimeMid(): Hexadecimal + { + // Swap the bytes from little endian to network byte order. + /** @var array $hex */ + $hex = unpack( + 'H*', + pack( + 'v', + hexdec(bin2hex(substr($this->bytes, 4, 2))) + ) + ); + + return new Hexadecimal((string) ($hex[1] ?? '')); + } + + public function getTimeHiAndVersion(): Hexadecimal + { + // Swap the bytes from little endian to network byte order. + /** @var array $hex */ + $hex = unpack( + 'H*', + pack( + 'v', + hexdec(bin2hex(substr($this->bytes, 6, 2))) + ) + ); + + return new Hexadecimal((string) ($hex[1] ?? '')); + } + + public function getTimestamp(): Hexadecimal + { + return new Hexadecimal(sprintf( + '%03x%04s%08s', + hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff, + $this->getTimeMid()->toString(), + $this->getTimeLow()->toString() + )); + } + + public function getClockSeq(): Hexadecimal + { + $clockSeq = hexdec(bin2hex(substr($this->bytes, 8, 2))) & 0x3fff; + + return new Hexadecimal(str_pad(dechex($clockSeq), 4, '0', STR_PAD_LEFT)); + } + + public function getClockSeqHiAndReserved(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 8, 1))); + } + + public function getClockSeqLow(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 9, 1))); + } + + public function getNode(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 10))); + } + + public function getVersion(): ?int + { + if ($this->isNil()) { + return null; + } + + /** @var array $parts */ + $parts = unpack('n*', $this->bytes); + + return ((int) $parts[4] >> 4) & 0x00f; + } + + private function isCorrectVariant(): bool + { + if ($this->isNil()) { + return true; + } + + $variant = $this->getVariant(); + + return $variant === Uuid::RFC_4122 || $variant === Uuid::RESERVED_MICROSOFT; + } +} diff --git a/vendor/ramsey/uuid/src/Guid/Guid.php b/vendor/ramsey/uuid/src/Guid/Guid.php new file mode 100644 index 0000000..b3ed096 --- /dev/null +++ b/vendor/ramsey/uuid/src/Guid/Guid.php @@ -0,0 +1,61 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Guid; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Uuid; + +/** + * Guid represents a UUID with "native" (little-endian) byte order + * + * From Wikipedia: + * + * > The first three fields are unsigned 32- and 16-bit integers and are subject + * > to swapping, while the last two fields consist of uninterpreted bytes, not + * > subject to swapping. This byte swapping applies even for versions 3, 4, and + * > 5, where the canonical fields do not correspond to the content of the UUID. + * + * The first three fields of a GUID are encoded in little-endian byte order, + * while the last three fields are in network (big-endian) byte order. This is + * according to the history of the Microsoft definition of a GUID. + * + * According to the .NET Guid.ToByteArray method documentation: + * + * > Note that the order of bytes in the returned byte array is different from + * > the string representation of a Guid value. The order of the beginning + * > four-byte group and the next two two-byte groups is reversed, whereas the + * > order of the last two-byte group and the closing six-byte group is the + * > same. + * + * @link https://en.wikipedia.org/wiki/Universally_unique_identifier#Variants UUID Variants on Wikipedia + * @link https://docs.microsoft.com/en-us/windows/win32/api/guiddef/ns-guiddef-guid Windows GUID structure + * @link https://docs.microsoft.com/en-us/dotnet/api/system.guid .NET Guid Struct + * @link https://docs.microsoft.com/en-us/dotnet/api/system.guid.tobytearray .NET Guid.ToByteArray Method + * + * @psalm-immutable + */ +final class Guid extends Uuid +{ + public function __construct( + Fields $fields, + NumberConverterInterface $numberConverter, + CodecInterface $codec, + TimeConverterInterface $timeConverter + ) { + parent::__construct($fields, $numberConverter, $codec, $timeConverter); + } +} diff --git a/vendor/ramsey/uuid/src/Guid/GuidBuilder.php b/vendor/ramsey/uuid/src/Guid/GuidBuilder.php new file mode 100644 index 0000000..758dd6b --- /dev/null +++ b/vendor/ramsey/uuid/src/Guid/GuidBuilder.php @@ -0,0 +1,89 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Guid; + +use Ramsey\Uuid\Builder\UuidBuilderInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\UnableToBuildUuidException; +use Ramsey\Uuid\UuidInterface; +use Throwable; + +/** + * GuidBuilder builds instances of Guid + * + * @see Guid + * + * @psalm-immutable + */ +class GuidBuilder implements UuidBuilderInterface +{ + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * @param NumberConverterInterface $numberConverter The number converter to + * use when constructing the Guid + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to Unix timestamps + */ + public function __construct( + NumberConverterInterface $numberConverter, + TimeConverterInterface $timeConverter + ) { + $this->numberConverter = $numberConverter; + $this->timeConverter = $timeConverter; + } + + /** + * Builds and returns a Guid + * + * @param CodecInterface $codec The codec to use for building this Guid instance + * @param string $bytes The byte string from which to construct a UUID + * + * @return Guid The GuidBuilder returns an instance of Ramsey\Uuid\Guid\Guid + * + * @psalm-pure + */ + public function build(CodecInterface $codec, string $bytes): UuidInterface + { + try { + return new Guid( + $this->buildFields($bytes), + $this->numberConverter, + $codec, + $this->timeConverter + ); + } catch (Throwable $e) { + throw new UnableToBuildUuidException($e->getMessage(), (int) $e->getCode(), $e); + } + } + + /** + * Proxy method to allow injecting a mock, for testing + */ + protected function buildFields(string $bytes): Fields + { + return new Fields($bytes); + } +} diff --git a/vendor/ramsey/uuid/src/Lazy/LazyUuidFromString.php b/vendor/ramsey/uuid/src/Lazy/LazyUuidFromString.php new file mode 100644 index 0000000..8ba7579 --- /dev/null +++ b/vendor/ramsey/uuid/src/Lazy/LazyUuidFromString.php @@ -0,0 +1,575 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Lazy; + +use DateTimeInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Exception\UnsupportedOperationException; +use Ramsey\Uuid\Fields\FieldsInterface; +use Ramsey\Uuid\Nonstandard\UuidV6; +use Ramsey\Uuid\Rfc4122\UuidV1; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\UuidFactory; +use Ramsey\Uuid\UuidInterface; +use ValueError; + +use function assert; +use function bin2hex; +use function hex2bin; +use function sprintf; +use function str_replace; +use function substr; + +/** + * Lazy version of a UUID: its format has not been determined yet, so it is mostly only usable for string/bytes + * conversion. This object optimizes instantiation, serialization and string conversion time, at the cost of + * increased overhead for more advanced UUID operations. + * + * @internal this type is used internally for performance reasons, and is not supposed to be directly referenced + * in consumer libraries. + * + * @psalm-immutable + * + * Note: the {@see FieldsInterface} does not declare methods that deprecated API + * relies upon: the API has been ported from the {@see \Ramsey\Uuid\Uuid} definition, + * and is deprecated anyway. + * Note: the deprecated API from {@see \Ramsey\Uuid\Uuid} is in use here (on purpose): it will be removed + * once the deprecated API is gone from this class too. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + */ +final class LazyUuidFromString implements UuidInterface +{ + public const VALID_REGEX = '/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/ms'; + /** + * @var string + * @psalm-var non-empty-string + */ + private $uuid; + /** @var UuidInterface|null */ + private $unwrapped; + + /** @psalm-param non-empty-string $uuid */ + public function __construct(string $uuid) + { + $this->uuid = $uuid; + } + + /** @psalm-pure */ + public static function fromBytes(string $bytes): self + { + $base16Uuid = bin2hex($bytes); + + return new self( + substr($base16Uuid, 0, 8) + . '-' + . substr($base16Uuid, 8, 4) + . '-' + . substr($base16Uuid, 12, 4) + . '-' + . substr($base16Uuid, 16, 4) + . '-' + . substr($base16Uuid, 20, 12) + ); + } + + public function serialize(): string + { + return $this->uuid; + } + + /** + * @return array{string: string} + * + * @psalm-return array{string: non-empty-string} + */ + public function __serialize(): array + { + return ['string' => $this->uuid]; + } + + /** + * {@inheritDoc} + * + * @param string $serialized + * + * @psalm-param non-empty-string $serialized + */ + public function unserialize($serialized): void + { + $this->uuid = $serialized; + } + + /** + * @param array{string: string} $data + * + * @psalm-param array{string: non-empty-string} $data + */ + public function __unserialize(array $data): void + { + // @codeCoverageIgnoreStart + if (!isset($data['string'])) { + throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__)); + } + // @codeCoverageIgnoreEnd + + $this->unserialize($data['string']); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getNumberConverter(): NumberConverterInterface + { + return ($this->unwrapped ?? $this->unwrap()) + ->getNumberConverter(); + } + + /** + * {@inheritDoc} + * + * @psalm-suppress DeprecatedMethod + */ + public function getFieldsHex(): array + { + return ($this->unwrapped ?? $this->unwrap()) + ->getFieldsHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getClockSeqHiAndReservedHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getClockSeqHiAndReservedHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getClockSeqLowHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getClockSeqLowHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getClockSequenceHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getClockSequenceHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getDateTime(): DateTimeInterface + { + return ($this->unwrapped ?? $this->unwrap()) + ->getDateTime(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getLeastSignificantBitsHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getLeastSignificantBitsHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getMostSignificantBitsHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getMostSignificantBitsHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getNodeHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getNodeHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getTimeHiAndVersionHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getTimeHiAndVersionHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getTimeLowHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getTimeLowHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getTimeMidHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getTimeMidHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getTimestampHex(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getTimestampHex(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getUrn(): string + { + return ($this->unwrapped ?? $this->unwrap()) + ->getUrn(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getVariant(): ?int + { + return ($this->unwrapped ?? $this->unwrap()) + ->getVariant(); + } + + /** @psalm-suppress DeprecatedMethod */ + public function getVersion(): ?int + { + return ($this->unwrapped ?? $this->unwrap()) + ->getVersion(); + } + + public function compareTo(UuidInterface $other): int + { + return ($this->unwrapped ?? $this->unwrap()) + ->compareTo($other); + } + + public function equals(?object $other): bool + { + if (! $other instanceof UuidInterface) { + return false; + } + + return $this->uuid === $other->toString(); + } + + /** + * {@inheritDoc} + * + * @psalm-suppress MoreSpecificReturnType + * @psalm-suppress LessSpecificReturnStatement we know that {@see self::$uuid} is a non-empty string, so + * we know that {@see hex2bin} will retrieve a non-empty string too. + */ + public function getBytes(): string + { + /** @phpstan-ignore-next-line PHPStan complains that this is not a non-empty-string. */ + return (string) hex2bin(str_replace('-', '', $this->uuid)); + } + + public function getFields(): FieldsInterface + { + return ($this->unwrapped ?? $this->unwrap()) + ->getFields(); + } + + public function getHex(): Hexadecimal + { + return ($this->unwrapped ?? $this->unwrap()) + ->getHex(); + } + + public function getInteger(): IntegerObject + { + return ($this->unwrapped ?? $this->unwrap()) + ->getInteger(); + } + + public function toString(): string + { + return $this->uuid; + } + + public function __toString(): string + { + return $this->uuid; + } + + public function jsonSerialize(): string + { + return $this->uuid; + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqHiAndReserved()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getClockSeqHiAndReserved(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + return $instance->getNumberConverter() + ->fromHex( + $instance->getFields() + ->getClockSeqHiAndReserved() + ->toString() + ); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqLow()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getClockSeqLow(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + return $instance->getNumberConverter() + ->fromHex( + $instance->getFields() + ->getClockSeqLow() + ->toString() + ); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getClockSeq()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getClockSequence(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + return $instance->getNumberConverter() + ->fromHex( + $instance->getFields() + ->getClockSeq() + ->toString() + ); + } + + /** + * @deprecated This method will be removed in 5.0.0. There is no direct + * alternative, but the same information may be obtained by splitting + * in half the value returned by {@see UuidInterface::getHex()}. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getLeastSignificantBits(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + return $instance->getNumberConverter() + ->fromHex(substr($instance->getHex()->toString(), 16)); + } + + /** + * @deprecated This method will be removed in 5.0.0. There is no direct + * alternative, but the same information may be obtained by splitting + * in half the value returned by {@see UuidInterface::getHex()}. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getMostSignificantBits(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + return $instance->getNumberConverter() + ->fromHex(substr($instance->getHex()->toString(), 0, 16)); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getNode()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getNode(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + return $instance->getNumberConverter() + ->fromHex( + $instance->getFields() + ->getNode() + ->toString() + ); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimeHiAndVersion()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getTimeHiAndVersion(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + return $instance->getNumberConverter() + ->fromHex( + $instance->getFields() + ->getTimeHiAndVersion() + ->toString() + ); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimeLow()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getTimeLow(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + return $instance->getNumberConverter() + ->fromHex( + $instance->getFields() + ->getTimeLow() + ->toString() + ); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimeMid()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getTimeMid(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + return $instance->getNumberConverter() + ->fromHex( + $instance->getFields() + ->getTimeMid() + ->toString() + ); + } + + /** + * @deprecated Use {@see UuidInterface::getFields()} to get a + * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} + * instance, you may call {@see Rfc4122FieldsInterface::getTimestamp()} + * and use the arbitrary-precision math library of your choice to + * convert it to a string integer. + * + * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress DeprecatedMethod + * @psalm-suppress MixedArgument + * @psalm-suppress MixedMethodCall + */ + public function getTimestamp(): string + { + $instance = ($this->unwrapped ?? $this->unwrap()); + $fields = $instance->getFields(); + + if ($fields->getVersion() !== 1) { + throw new UnsupportedOperationException('Not a time-based UUID'); + } + + return $instance->getNumberConverter() + ->fromHex($fields->getTimestamp()->toString()); + } + + public function toUuidV1(): UuidV1 + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + if ($instance instanceof UuidV1) { + return $instance; + } + + assert($instance instanceof UuidV6); + + return $instance->toUuidV1(); + } + + public function toUuidV6(): UuidV6 + { + $instance = ($this->unwrapped ?? $this->unwrap()); + + assert($instance instanceof UuidV6); + + return $instance; + } + + /** + * @psalm-suppress ImpureMethodCall the retrieval of the factory is a clear violation of purity here: this is a + * known pitfall of the design of this library, where a value object contains + * a mutable reference to a factory. We use a fixed factory here, so the violation + * will not have real-world effects, as this object is only instantiated with the + * default factory settings/features. + * @psalm-suppress InaccessibleProperty property {@see $unwrapped} is used as a cache: we don't expose it to the + * outside world, so we should be fine here. + */ + private function unwrap(): UuidInterface + { + return $this->unwrapped = (new UuidFactory()) + ->fromString($this->uuid); + } +} diff --git a/vendor/ramsey/uuid/src/Math/BrickMathCalculator.php b/vendor/ramsey/uuid/src/Math/BrickMathCalculator.php new file mode 100644 index 0000000..f2d8678 --- /dev/null +++ b/vendor/ramsey/uuid/src/Math/BrickMathCalculator.php @@ -0,0 +1,144 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Math; + +use Brick\Math\BigDecimal; +use Brick\Math\BigInteger; +use Brick\Math\Exception\MathException; +use Brick\Math\RoundingMode as BrickMathRounding; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Type\Decimal; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Type\NumberInterface; + +/** + * A calculator using the brick/math library for arbitrary-precision arithmetic + * + * @psalm-immutable + */ +final class BrickMathCalculator implements CalculatorInterface +{ + private const ROUNDING_MODE_MAP = [ + RoundingMode::UNNECESSARY => BrickMathRounding::UNNECESSARY, + RoundingMode::UP => BrickMathRounding::UP, + RoundingMode::DOWN => BrickMathRounding::DOWN, + RoundingMode::CEILING => BrickMathRounding::CEILING, + RoundingMode::FLOOR => BrickMathRounding::FLOOR, + RoundingMode::HALF_UP => BrickMathRounding::HALF_UP, + RoundingMode::HALF_DOWN => BrickMathRounding::HALF_DOWN, + RoundingMode::HALF_CEILING => BrickMathRounding::HALF_CEILING, + RoundingMode::HALF_FLOOR => BrickMathRounding::HALF_FLOOR, + RoundingMode::HALF_EVEN => BrickMathRounding::HALF_EVEN, + ]; + + public function add(NumberInterface $augend, NumberInterface ...$addends): NumberInterface + { + $sum = BigInteger::of($augend->toString()); + + foreach ($addends as $addend) { + $sum = $sum->plus($addend->toString()); + } + + return new IntegerObject((string) $sum); + } + + public function subtract(NumberInterface $minuend, NumberInterface ...$subtrahends): NumberInterface + { + $difference = BigInteger::of($minuend->toString()); + + foreach ($subtrahends as $subtrahend) { + $difference = $difference->minus($subtrahend->toString()); + } + + return new IntegerObject((string) $difference); + } + + public function multiply(NumberInterface $multiplicand, NumberInterface ...$multipliers): NumberInterface + { + $product = BigInteger::of($multiplicand->toString()); + + foreach ($multipliers as $multiplier) { + $product = $product->multipliedBy($multiplier->toString()); + } + + return new IntegerObject((string) $product); + } + + public function divide( + int $roundingMode, + int $scale, + NumberInterface $dividend, + NumberInterface ...$divisors + ): NumberInterface { + $brickRounding = $this->getBrickRoundingMode($roundingMode); + + $quotient = BigDecimal::of($dividend->toString()); + + foreach ($divisors as $divisor) { + $quotient = $quotient->dividedBy($divisor->toString(), $scale, $brickRounding); + } + + if ($scale === 0) { + return new IntegerObject((string) $quotient->toBigInteger()); + } + + return new Decimal((string) $quotient); + } + + public function fromBase(string $value, int $base): IntegerObject + { + try { + return new IntegerObject((string) BigInteger::fromBase($value, $base)); + } catch (MathException | \InvalidArgumentException $exception) { + throw new InvalidArgumentException( + $exception->getMessage(), + (int) $exception->getCode(), + $exception + ); + } + } + + public function toBase(IntegerObject $value, int $base): string + { + try { + return BigInteger::of($value->toString())->toBase($base); + } catch (MathException | \InvalidArgumentException $exception) { + throw new InvalidArgumentException( + $exception->getMessage(), + (int) $exception->getCode(), + $exception + ); + } + } + + public function toHexadecimal(IntegerObject $value): Hexadecimal + { + return new Hexadecimal($this->toBase($value, 16)); + } + + public function toInteger(Hexadecimal $value): IntegerObject + { + return $this->fromBase($value->toString(), 16); + } + + /** + * Maps ramsey/uuid rounding modes to those used by brick/math + */ + private function getBrickRoundingMode(int $roundingMode): int + { + return self::ROUNDING_MODE_MAP[$roundingMode] ?? 0; + } +} diff --git a/vendor/ramsey/uuid/src/Math/CalculatorInterface.php b/vendor/ramsey/uuid/src/Math/CalculatorInterface.php new file mode 100644 index 0000000..f03645d --- /dev/null +++ b/vendor/ramsey/uuid/src/Math/CalculatorInterface.php @@ -0,0 +1,106 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Math; + +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Type\NumberInterface; + +/** + * A calculator performs arithmetic operations on numbers + * + * @psalm-immutable + */ +interface CalculatorInterface +{ + /** + * Returns the sum of all the provided parameters + * + * @param NumberInterface $augend The first addend (the integer being added to) + * @param NumberInterface ...$addends The additional integers to a add to the augend + * + * @return NumberInterface The sum of all the parameters + */ + public function add(NumberInterface $augend, NumberInterface ...$addends): NumberInterface; + + /** + * Returns the difference of all the provided parameters + * + * @param NumberInterface $minuend The integer being subtracted from + * @param NumberInterface ...$subtrahends The integers to subtract from the minuend + * + * @return NumberInterface The difference after subtracting all parameters + */ + public function subtract(NumberInterface $minuend, NumberInterface ...$subtrahends): NumberInterface; + + /** + * Returns the product of all the provided parameters + * + * @param NumberInterface $multiplicand The integer to be multiplied + * @param NumberInterface ...$multipliers The factors by which to multiply the multiplicand + * + * @return NumberInterface The product of multiplying all the provided parameters + */ + public function multiply(NumberInterface $multiplicand, NumberInterface ...$multipliers): NumberInterface; + + /** + * Returns the quotient of the provided parameters divided left-to-right + * + * @param int $roundingMode The RoundingMode constant to use for this operation + * @param int $scale The scale to use for this operation + * @param NumberInterface $dividend The integer to be divided + * @param NumberInterface ...$divisors The integers to divide $dividend by, in + * the order in which the division operations should take place + * (left-to-right) + * + * @return NumberInterface The quotient of dividing the provided parameters left-to-right + */ + public function divide( + int $roundingMode, + int $scale, + NumberInterface $dividend, + NumberInterface ...$divisors + ): NumberInterface; + + /** + * Converts a value from an arbitrary base to a base-10 integer value + * + * @param string $value The value to convert + * @param int $base The base to convert from (i.e., 2, 16, 32, etc.) + * + * @return IntegerObject The base-10 integer value of the converted value + */ + public function fromBase(string $value, int $base): IntegerObject; + + /** + * Converts a base-10 integer value to an arbitrary base + * + * @param IntegerObject $value The integer value to convert + * @param int $base The base to convert to (i.e., 2, 16, 32, etc.) + * + * @return string The value represented in the specified base + */ + public function toBase(IntegerObject $value, int $base): string; + + /** + * Converts an Integer instance to a Hexadecimal instance + */ + public function toHexadecimal(IntegerObject $value): Hexadecimal; + + /** + * Converts a Hexadecimal instance to an Integer instance + */ + public function toInteger(Hexadecimal $value): IntegerObject; +} diff --git a/vendor/ramsey/uuid/src/Math/RoundingMode.php b/vendor/ramsey/uuid/src/Math/RoundingMode.php new file mode 100644 index 0000000..e710270 --- /dev/null +++ b/vendor/ramsey/uuid/src/Math/RoundingMode.php @@ -0,0 +1,146 @@ += 0.5; otherwise, behaves + * as for DOWN. Note that this is the rounding mode commonly taught at + * school. + */ + public const HALF_UP = 5; + + /** + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round down. + * + * Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves + * as for DOWN. + */ + public const HALF_DOWN = 6; + + /** + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round towards positive infinity. + * + * If the result is positive, behaves as for HALF_UP; if negative, behaves + * as for HALF_DOWN. + */ + public const HALF_CEILING = 7; + + /** + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round towards negative infinity. + * + * If the result is positive, behaves as for HALF_DOWN; if negative, behaves + * as for HALF_UP. + */ + public const HALF_FLOOR = 8; + + /** + * Rounds towards the "nearest neighbor" unless both neighbors are + * equidistant, in which case rounds towards the even neighbor. + * + * Behaves as for HALF_UP if the digit to the left of the discarded fraction + * is odd; behaves as for HALF_DOWN if it's even. + * + * Note that this is the rounding mode that statistically minimizes + * cumulative error when applied repeatedly over a sequence of calculations. + * It is sometimes known as "Banker's rounding", and is chiefly used in the + * USA. + */ + public const HALF_EVEN = 9; +} diff --git a/vendor/ramsey/uuid/src/Nonstandard/Fields.php b/vendor/ramsey/uuid/src/Nonstandard/Fields.php new file mode 100644 index 0000000..927bc6a --- /dev/null +++ b/vendor/ramsey/uuid/src/Nonstandard/Fields.php @@ -0,0 +1,133 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Nonstandard; + +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Fields\SerializableFieldsTrait; +use Ramsey\Uuid\Rfc4122\FieldsInterface; +use Ramsey\Uuid\Rfc4122\VariantTrait; +use Ramsey\Uuid\Type\Hexadecimal; + +use function bin2hex; +use function dechex; +use function hexdec; +use function sprintf; +use function str_pad; +use function strlen; +use function substr; + +use const STR_PAD_LEFT; + +/** + * Nonstandard UUID fields do not conform to the RFC 4122 standard + * + * Since some systems may create nonstandard UUIDs, this implements the + * Rfc4122\FieldsInterface, so that functionality of a nonstandard UUID is not + * degraded, in the event these UUIDs are expected to contain RFC 4122 fields. + * + * Internally, this class represents the fields together as a 16-byte binary + * string. + * + * @psalm-immutable + */ +final class Fields implements FieldsInterface +{ + use SerializableFieldsTrait; + use VariantTrait; + + /** + * @var string + */ + private $bytes; + + /** + * @param string $bytes A 16-byte binary string representation of a UUID + * + * @throws InvalidArgumentException if the byte string is not exactly 16 bytes + */ + public function __construct(string $bytes) + { + if (strlen($bytes) !== 16) { + throw new InvalidArgumentException( + 'The byte string must be 16 bytes long; ' + . 'received ' . strlen($bytes) . ' bytes' + ); + } + + $this->bytes = $bytes; + } + + public function getBytes(): string + { + return $this->bytes; + } + + public function getClockSeq(): Hexadecimal + { + $clockSeq = hexdec(bin2hex(substr($this->bytes, 8, 2))) & 0x3fff; + + return new Hexadecimal(str_pad(dechex($clockSeq), 4, '0', STR_PAD_LEFT)); + } + + public function getClockSeqHiAndReserved(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 8, 1))); + } + + public function getClockSeqLow(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 9, 1))); + } + + public function getNode(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 10))); + } + + public function getTimeHiAndVersion(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 6, 2))); + } + + public function getTimeLow(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 0, 4))); + } + + public function getTimeMid(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 4, 2))); + } + + public function getTimestamp(): Hexadecimal + { + return new Hexadecimal(sprintf( + '%03x%04s%08s', + hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff, + $this->getTimeMid()->toString(), + $this->getTimeLow()->toString() + )); + } + + public function getVersion(): ?int + { + return null; + } + + public function isNil(): bool + { + return false; + } +} diff --git a/vendor/ramsey/uuid/src/Nonstandard/Uuid.php b/vendor/ramsey/uuid/src/Nonstandard/Uuid.php new file mode 100644 index 0000000..715f825 --- /dev/null +++ b/vendor/ramsey/uuid/src/Nonstandard/Uuid.php @@ -0,0 +1,37 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Nonstandard; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Uuid as BaseUuid; + +/** + * Nonstandard\Uuid is a UUID that doesn't conform to RFC 4122 + * + * @psalm-immutable + */ +final class Uuid extends BaseUuid +{ + public function __construct( + Fields $fields, + NumberConverterInterface $numberConverter, + CodecInterface $codec, + TimeConverterInterface $timeConverter + ) { + parent::__construct($fields, $numberConverter, $codec, $timeConverter); + } +} diff --git a/vendor/ramsey/uuid/src/Nonstandard/UuidBuilder.php b/vendor/ramsey/uuid/src/Nonstandard/UuidBuilder.php new file mode 100644 index 0000000..0c89277 --- /dev/null +++ b/vendor/ramsey/uuid/src/Nonstandard/UuidBuilder.php @@ -0,0 +1,88 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Nonstandard; + +use Ramsey\Uuid\Builder\UuidBuilderInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\UnableToBuildUuidException; +use Ramsey\Uuid\UuidInterface; +use Throwable; + +/** + * Nonstandard\UuidBuilder builds instances of Nonstandard\Uuid + * + * @psalm-immutable + */ +class UuidBuilder implements UuidBuilderInterface +{ + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * @param NumberConverterInterface $numberConverter The number converter to + * use when constructing the Nonstandard\Uuid + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to Unix timestamps + */ + public function __construct( + NumberConverterInterface $numberConverter, + TimeConverterInterface $timeConverter + ) { + $this->numberConverter = $numberConverter; + $this->timeConverter = $timeConverter; + } + + /** + * Builds and returns a Nonstandard\Uuid + * + * @param CodecInterface $codec The codec to use for building this instance + * @param string $bytes The byte string from which to construct a UUID + * + * @return Uuid The Nonstandard\UuidBuilder returns an instance of + * Nonstandard\Uuid + * + * @psalm-pure + */ + public function build(CodecInterface $codec, string $bytes): UuidInterface + { + try { + return new Uuid( + $this->buildFields($bytes), + $this->numberConverter, + $codec, + $this->timeConverter + ); + } catch (Throwable $e) { + throw new UnableToBuildUuidException($e->getMessage(), (int) $e->getCode(), $e); + } + } + + /** + * Proxy method to allow injecting a mock, for testing + */ + protected function buildFields(string $bytes): Fields + { + return new Fields($bytes); + } +} diff --git a/vendor/ramsey/uuid/src/Nonstandard/UuidV6.php b/vendor/ramsey/uuid/src/Nonstandard/UuidV6.php new file mode 100644 index 0000000..05586b3 --- /dev/null +++ b/vendor/ramsey/uuid/src/Nonstandard/UuidV6.php @@ -0,0 +1,133 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Nonstandard; + +use DateTimeImmutable; +use DateTimeInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\DateTimeException; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Lazy\LazyUuidFromString; +use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Rfc4122\UuidInterface; +use Ramsey\Uuid\Rfc4122\UuidV1; +use Ramsey\Uuid\Uuid; +use Throwable; + +use function hex2bin; +use function str_pad; +use function substr; + +use const STR_PAD_LEFT; + +/** + * Ordered-time, or version 6, UUIDs include timestamp, clock sequence, and node + * values that are combined into a 128-bit unsigned integer + * + * @link https://github.com/uuid6/uuid6-ietf-draft UUID version 6 IETF draft + * @link http://gh.peabody.io/uuidv6/ "Version 6" UUIDs + * + * @psalm-immutable + */ +final class UuidV6 extends Uuid implements UuidInterface +{ + /** + * Creates a version 6 (time-based) UUID + * + * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID + * @param NumberConverterInterface $numberConverter 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 + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to unix timestamps + */ + public function __construct( + Rfc4122FieldsInterface $fields, + NumberConverterInterface $numberConverter, + CodecInterface $codec, + TimeConverterInterface $timeConverter + ) { + if ($fields->getVersion() !== Uuid::UUID_TYPE_PEABODY) { + throw new InvalidArgumentException( + 'Fields used to create a UuidV6 must represent a ' + . 'version 6 (ordered-time) UUID' + ); + } + + parent::__construct($fields, $numberConverter, $codec, $timeConverter); + } + + /** + * Returns a DateTimeInterface object representing the timestamp associated + * with the UUID + * + * @return DateTimeImmutable A PHP DateTimeImmutable instance representing + * the timestamp of a version 6 UUID + */ + public function getDateTime(): DateTimeInterface + { + $time = $this->timeConverter->convertTime($this->fields->getTimestamp()); + + try { + return new DateTimeImmutable( + '@' + . $time->getSeconds()->toString() + . '.' + . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT) + ); + } catch (Throwable $e) { + throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e); + } + } + + /** + * Converts this UUID into an instance of a version 1 UUID + */ + public function toUuidV1(): UuidV1 + { + $hex = $this->getHex()->toString(); + $hex = substr($hex, 7, 5) + . substr($hex, 13, 3) + . substr($hex, 3, 4) + . '1' . substr($hex, 0, 3) + . substr($hex, 16); + + /** @var LazyUuidFromString $uuid */ + $uuid = Uuid::fromBytes((string) hex2bin($hex)); + + return $uuid->toUuidV1(); + } + + /** + * Converts a version 1 UUID into an instance of a version 6 UUID + */ + public static function fromUuidV1(UuidV1 $uuidV1): UuidV6 + { + $hex = $uuidV1->getHex()->toString(); + $hex = substr($hex, 13, 3) + . substr($hex, 8, 4) + . substr($hex, 0, 5) + . '6' . substr($hex, 5, 3) + . substr($hex, 16); + + /** @var LazyUuidFromString $uuid */ + $uuid = Uuid::fromBytes((string) hex2bin($hex)); + + return $uuid->toUuidV6(); + } +} diff --git a/vendor/ramsey/uuid/src/Provider/Dce/SystemDceSecurityProvider.php b/vendor/ramsey/uuid/src/Provider/Dce/SystemDceSecurityProvider.php new file mode 100644 index 0000000..6d6240b --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Dce/SystemDceSecurityProvider.php @@ -0,0 +1,234 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider\Dce; + +use Ramsey\Uuid\Exception\DceSecurityException; +use Ramsey\Uuid\Provider\DceSecurityProviderInterface; +use Ramsey\Uuid\Type\Integer as IntegerObject; + +use function escapeshellarg; +use function preg_split; +use function str_getcsv; +use function strpos; +use function strrpos; +use function strtolower; +use function strtoupper; +use function substr; +use function trim; + +use const PREG_SPLIT_NO_EMPTY; + +/** + * SystemDceSecurityProvider retrieves the user or group identifiers from the system + */ +class SystemDceSecurityProvider implements DceSecurityProviderInterface +{ + /** + * @throws DceSecurityException if unable to get a user identifier + * + * @inheritDoc + */ + public function getUid(): IntegerObject + { + static $uid = null; + + if ($uid instanceof IntegerObject) { + return $uid; + } + + if ($uid === null) { + $uid = $this->getSystemUid(); + } + + if ($uid === '') { + throw new DceSecurityException( + 'Unable to get a user identifier using the system DCE ' + . 'Security provider; please provide a custom identifier or ' + . 'use a different provider' + ); + } + + $uid = new IntegerObject($uid); + + return $uid; + } + + /** + * @throws DceSecurityException if unable to get a group identifier + * + * @inheritDoc + */ + public function getGid(): IntegerObject + { + static $gid = null; + + if ($gid instanceof IntegerObject) { + return $gid; + } + + if ($gid === null) { + $gid = $this->getSystemGid(); + } + + if ($gid === '') { + throw new DceSecurityException( + 'Unable to get a group identifier using the system DCE ' + . 'Security provider; please provide a custom identifier or ' + . 'use a different provider' + ); + } + + $gid = new IntegerObject($gid); + + return $gid; + } + + /** + * Returns the UID from the system + */ + private function getSystemUid(): string + { + if (!$this->hasShellExec()) { + return ''; + } + + switch ($this->getOs()) { + case 'WIN': + return $this->getWindowsUid(); + case 'DAR': + case 'FRE': + case 'LIN': + default: + return trim((string) shell_exec('id -u')); + } + } + + /** + * Returns the GID from the system + */ + private function getSystemGid(): string + { + if (!$this->hasShellExec()) { + return ''; + } + + switch ($this->getOs()) { + case 'WIN': + return $this->getWindowsGid(); + case 'DAR': + case 'FRE': + case 'LIN': + default: + return trim((string) shell_exec('id -g')); + } + } + + /** + * Returns true if shell_exec() is available for use + */ + private function hasShellExec(): bool + { + $disabledFunctions = strtolower((string) ini_get('disable_functions')); + + return strpos($disabledFunctions, 'shell_exec') === false; + } + + /** + * Returns the PHP_OS string + */ + private function getOs(): string + { + return strtoupper(substr(constant('PHP_OS'), 0, 3)); + } + + /** + * Returns the user identifier for a user on a Windows system + * + * Windows does not have the same concept as an effective POSIX UID for the + * running script. Instead, each user is uniquely identified by an SID + * (security identifier). The SID includes three 32-bit unsigned integers + * that make up a unique domain identifier, followed by an RID (relative + * identifier) that we will use as the UID. The primary caveat is that this + * UID may not be unique to the system, since it is, instead, unique to the + * domain. + * + * @link https://www.lifewire.com/what-is-an-sid-number-2626005 What Is an SID Number? + * @link https://bit.ly/30vE7NM Well-known SID Structures + * @link https://bit.ly/2FWcYKJ Well-known security identifiers in Windows operating systems + * @link https://www.windows-commandline.com/get-sid-of-user/ Get SID of user + */ + private function getWindowsUid(): string + { + $response = shell_exec('whoami /user /fo csv /nh'); + + if ($response === null) { + return ''; + } + + $sid = str_getcsv(trim((string) $response))[1] ?? ''; + + if (($lastHyphen = strrpos($sid, '-')) === false) { + return ''; + } + + return trim(substr($sid, $lastHyphen + 1)); + } + + /** + * Returns a group identifier for a user on a Windows system + * + * Since Windows does not have the same concept as an effective POSIX GID + * for the running script, we will get the local group memberships for the + * user running the script. Then, we will get the SID (security identifier) + * for the first group that appears in that list. Finally, we will return + * the RID (relative identifier) for the group and use that as the GID. + * + * @link https://www.windows-commandline.com/list-of-user-groups-command-line/ List of user groups command line + */ + private function getWindowsGid(): string + { + $response = shell_exec('net user %username% | findstr /b /i "Local Group Memberships"'); + + if ($response === null) { + return ''; + } + + /** @var string[] $userGroups */ + $userGroups = preg_split('/\s{2,}/', (string) $response, -1, PREG_SPLIT_NO_EMPTY); + + $firstGroup = trim($userGroups[1] ?? '', "* \t\n\r\0\x0B"); + + if ($firstGroup === '') { + return ''; + } + + $response = shell_exec('wmic group get name,sid | findstr /b /i ' . escapeshellarg($firstGroup)); + + if ($response === null) { + return ''; + } + + /** @var string[] $userGroup */ + $userGroup = preg_split('/\s{2,}/', (string) $response, -1, PREG_SPLIT_NO_EMPTY); + + $sid = $userGroup[1] ?? ''; + + if (($lastHyphen = strrpos($sid, '-')) === false) { + return ''; + } + + return trim((string) substr($sid, $lastHyphen + 1)); + } +} diff --git a/vendor/ramsey/uuid/src/Provider/DceSecurityProviderInterface.php b/vendor/ramsey/uuid/src/Provider/DceSecurityProviderInterface.php new file mode 100644 index 0000000..8325da6 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/DceSecurityProviderInterface.php @@ -0,0 +1,41 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider; + +use Ramsey\Uuid\Rfc4122\UuidV2; +use Ramsey\Uuid\Type\Integer as IntegerObject; + +/** + * A DCE provider provides access to local domain identifiers for version 2, + * DCE Security, UUIDs + * + * @see UuidV2 + */ +interface DceSecurityProviderInterface +{ + /** + * Returns a user identifier for the system + * + * @link https://en.wikipedia.org/wiki/User_identifier User identifier + */ + public function getUid(): IntegerObject; + + /** + * Returns a group identifier for the system + * + * @link https://en.wikipedia.org/wiki/Group_identifier Group identifier + */ + public function getGid(): IntegerObject; +} 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 0000000..cad0104 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Node/FallbackNodeProvider.php @@ -0,0 +1,60 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider\Node; + +use Ramsey\Uuid\Exception\NodeException; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Type\Hexadecimal; + +/** + * FallbackNodeProvider retrieves the system node ID by stepping through a list + * of providers until a node ID can be obtained + */ +class FallbackNodeProvider implements NodeProviderInterface +{ + /** + * @var NodeProviderCollection + */ + private $nodeProviders; + + /** + * @param NodeProviderCollection $providers Array of node providers + */ + public function __construct(NodeProviderCollection $providers) + { + $this->nodeProviders = $providers; + } + + public function getNode(): Hexadecimal + { + $lastProviderException = null; + + foreach ($this->nodeProviders as $provider) { + try { + return $provider->getNode(); + } catch (NodeException $exception) { + $lastProviderException = $exception; + + continue; + } + } + + throw new NodeException( + 'Unable to find a suitable node provider', + 0, + $lastProviderException + ); + } +} diff --git a/vendor/ramsey/uuid/src/Provider/Node/NodeProviderCollection.php b/vendor/ramsey/uuid/src/Provider/Node/NodeProviderCollection.php new file mode 100644 index 0000000..536cb60 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Node/NodeProviderCollection.php @@ -0,0 +1,61 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider\Node; + +use Ramsey\Collection\AbstractCollection; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Type\Hexadecimal; + +/** + * A collection of NodeProviderInterface objects + * + * @extends AbstractCollection + */ +class NodeProviderCollection extends AbstractCollection +{ + public function getType(): string + { + return NodeProviderInterface::class; + } + + /** + * Re-constructs the object from its serialized form + * + * @param string $serialized The serialized PHP string to unserialize into + * a UuidInterface instance + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + * @psalm-suppress RedundantConditionGivenDocblockType + */ + public function unserialize($serialized): void + { + /** @var array $data */ + $data = unserialize($serialized, [ + 'allowed_classes' => [ + Hexadecimal::class, + RandomNodeProvider::class, + StaticNodeProvider::class, + SystemNodeProvider::class, + ], + ]); + + $this->data = array_filter( + $data, + function ($unserialized): bool { + return $unserialized instanceof NodeProviderInterface; + } + ); + } +} 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 0000000..7614136 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Node/RandomNodeProvider.php @@ -0,0 +1,69 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider\Node; + +use Ramsey\Uuid\Exception\RandomSourceException; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Type\Hexadecimal; +use Throwable; + +use function bin2hex; +use function dechex; +use function hex2bin; +use function hexdec; +use function str_pad; +use function substr; + +use const STR_PAD_LEFT; + +/** + * RandomNodeProvider generates a random node ID + * + * @link http://tools.ietf.org/html/rfc4122#section-4.5 RFC 4122, § 4.5: Node IDs that Do Not Identify the Host + */ +class RandomNodeProvider implements NodeProviderInterface +{ + public function getNode(): Hexadecimal + { + try { + $nodeBytes = random_bytes(6); + } catch (Throwable $exception) { + throw new RandomSourceException( + $exception->getMessage(), + (int) $exception->getCode(), + $exception + ); + } + + // Split the node bytes for math on 32-bit systems. + $nodeMsb = substr($nodeBytes, 0, 3); + $nodeLsb = substr($nodeBytes, 3); + + // Set the multicast bit; see RFC 4122, section 4.5. + $nodeMsb = hex2bin( + str_pad( + dechex(hexdec(bin2hex($nodeMsb)) | 0x010000), + 6, + '0', + STR_PAD_LEFT + ) + ); + + // Recombine the node bytes. + $node = $nodeMsb . $nodeLsb; + + return new Hexadecimal(str_pad(bin2hex($node), 12, '0', STR_PAD_LEFT)); + } +} diff --git a/vendor/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php b/vendor/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php new file mode 100644 index 0000000..51f1b02 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php @@ -0,0 +1,76 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider\Node; + +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Type\Hexadecimal; + +use function dechex; +use function hexdec; +use function str_pad; +use function substr; + +use const STR_PAD_LEFT; + +/** + * StaticNodeProvider provides a static node value with the multicast bit set + * + * @link http://tools.ietf.org/html/rfc4122#section-4.5 RFC 4122, § 4.5: Node IDs that Do Not Identify the Host + */ +class StaticNodeProvider implements NodeProviderInterface +{ + /** + * @var Hexadecimal + */ + private $node; + + /** + * @param Hexadecimal $node The static node value to use + */ + public function __construct(Hexadecimal $node) + { + if (strlen($node->toString()) > 12) { + throw new InvalidArgumentException( + 'Static node value cannot be greater than 12 hexadecimal characters' + ); + } + + $this->node = $this->setMulticastBit($node); + } + + public function getNode(): Hexadecimal + { + return $this->node; + } + + /** + * Set the multicast bit for the static node value + */ + private function setMulticastBit(Hexadecimal $node): Hexadecimal + { + $nodeHex = str_pad($node->toString(), 12, '0', STR_PAD_LEFT); + $firstOctet = substr($nodeHex, 0, 2); + + $firstOctet = str_pad( + dechex(hexdec($firstOctet) | 0x01), + 2, + '0', + STR_PAD_LEFT + ); + + return new Hexadecimal($firstOctet . substr($nodeHex, 2)); + } +} 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 0000000..d512f22 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php @@ -0,0 +1,173 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider\Node; + +use Ramsey\Uuid\Exception\NodeException; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Type\Hexadecimal; + +use function array_filter; +use function array_map; +use function array_walk; +use function count; +use function ob_get_clean; +use function ob_start; +use function preg_match; +use function preg_match_all; +use function reset; +use function str_replace; +use function strpos; +use function strtolower; +use function strtoupper; +use function substr; + +use const GLOB_NOSORT; +use const PREG_PATTERN_ORDER; + +/** + * SystemNodeProvider retrieves the system node ID, if possible + * + * The system node ID, or host ID, is often the same as the MAC address for a + * network interface on the host. + */ +class SystemNodeProvider implements NodeProviderInterface +{ + /** + * Pattern to match nodes in ifconfig and ipconfig output. + */ + private const IFCONFIG_PATTERN = '/[^:]([0-9a-f]{2}([:-])[0-9a-f]{2}(\2[0-9a-f]{2}){4})[^:]/i'; + + /** + * Pattern to match nodes in sysfs stream output. + */ + private const SYSFS_PATTERN = '/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i'; + + public function getNode(): Hexadecimal + { + $node = $this->getNodeFromSystem(); + + if ($node === '') { + throw new NodeException( + 'Unable to fetch a node for this system' + ); + } + + return new Hexadecimal($node); + } + + /** + * Returns the system node, if it can find it + */ + protected function getNodeFromSystem(): string + { + static $node = null; + + if ($node !== null) { + return (string) $node; + } + + // First, try a Linux-specific approach. + $node = $this->getSysfs(); + + if ($node === '') { + // Search ifconfig output for MAC addresses & return the first one. + $node = $this->getIfconfig(); + } + + $node = str_replace([':', '-'], '', $node); + + return $node; + } + + /** + * Returns the network interface configuration for the system + * + * @codeCoverageIgnore + */ + protected function getIfconfig(): string + { + $disabledFunctions = strtolower((string) ini_get('disable_functions')); + + if (strpos($disabledFunctions, 'passthru') !== false) { + return ''; + } + + ob_start(); + switch (strtoupper(substr(constant('PHP_OS'), 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; + } + + $ifconfig = (string) ob_get_clean(); + + $node = ''; + if (preg_match_all(self::IFCONFIG_PATTERN, $ifconfig, $matches, PREG_PATTERN_ORDER)) { + $node = $matches[1][0] ?? ''; + } + + return $node; + } + + /** + * Returns MAC address from the first system interface via the sysfs interface + */ + protected function getSysfs(): string + { + $mac = ''; + + if (strtoupper(constant('PHP_OS')) === 'LINUX') { + $addressPaths = glob('/sys/class/net/*/address', GLOB_NOSORT); + + if ($addressPaths === false || count($addressPaths) === 0) { + return ''; + } + + $macs = []; + + array_walk($addressPaths, function (string $addressPath) use (&$macs): void { + if (is_readable($addressPath)) { + $macs[] = file_get_contents($addressPath); + } + }); + + $macs = array_map('trim', $macs); + + // Remove invalid entries. + $macs = array_filter($macs, function (string $address) { + return $address !== '00:00:00:00:00:00' + && preg_match(self::SYSFS_PATTERN, $address); + }); + + $mac = reset($macs); + } + + return (string) $mac; + } +} diff --git a/vendor/ramsey/uuid/src/Provider/NodeProviderInterface.php b/vendor/ramsey/uuid/src/Provider/NodeProviderInterface.php new file mode 100644 index 0000000..d536b45 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/NodeProviderInterface.php @@ -0,0 +1,30 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider; + +use Ramsey\Uuid\Type\Hexadecimal; + +/** + * A node provider retrieves or generates a node ID + */ +interface NodeProviderInterface +{ + /** + * Returns a node ID + * + * @return Hexadecimal The node ID as a hexadecimal string + */ + public function getNode(): Hexadecimal; +} 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 0000000..b8bfd72 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Time/FixedTimeProvider.php @@ -0,0 +1,63 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider\Time; + +use Ramsey\Uuid\Provider\TimeProviderInterface; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Type\Time; + +/** + * FixedTimeProvider uses an known time to provide the time + * + * This provider allows the use of a previously-generated, or known, time + * when generating time-based UUIDs. + */ +class FixedTimeProvider implements TimeProviderInterface +{ + /** + * @var Time + */ + private $fixedTime; + + public function __construct(Time $time) + { + $this->fixedTime = $time; + } + + /** + * Sets the `usec` component of the time + * + * @param int|string|IntegerObject $value The `usec` value to set + */ + public function setUsec($value): void + { + $this->fixedTime = new Time($this->fixedTime->getSeconds(), $value); + } + + /** + * Sets the `sec` component of the time + * + * @param int|string|IntegerObject $value The `sec` value to set + */ + public function setSec($value): void + { + $this->fixedTime = new Time($value, $this->fixedTime->getMicroseconds()); + } + + public function getTime(): Time + { + 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 0000000..3a1e09c --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/Time/SystemTimeProvider.php @@ -0,0 +1,33 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider\Time; + +use Ramsey\Uuid\Provider\TimeProviderInterface; +use Ramsey\Uuid\Type\Time; + +use function gettimeofday; + +/** + * SystemTimeProvider retrieves the current time using built-in PHP functions + */ +class SystemTimeProvider implements TimeProviderInterface +{ + public function getTime(): Time + { + $time = gettimeofday(); + + return new Time($time['sec'], $time['usec']); + } +} diff --git a/vendor/ramsey/uuid/src/Provider/TimeProviderInterface.php b/vendor/ramsey/uuid/src/Provider/TimeProviderInterface.php new file mode 100644 index 0000000..43588e0 --- /dev/null +++ b/vendor/ramsey/uuid/src/Provider/TimeProviderInterface.php @@ -0,0 +1,28 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Provider; + +use Ramsey\Uuid\Type\Time; + +/** + * A time provider retrieves the current time + */ +interface TimeProviderInterface +{ + /** + * Returns a time object + */ + public function getTime(): Time; +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/Fields.php b/vendor/ramsey/uuid/src/Rfc4122/Fields.php new file mode 100644 index 0000000..2ccc20b --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/Fields.php @@ -0,0 +1,194 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Fields\SerializableFieldsTrait; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Uuid; + +use function bin2hex; +use function dechex; +use function hexdec; +use function sprintf; +use function str_pad; +use function strlen; +use function substr; +use function unpack; + +use const STR_PAD_LEFT; + +/** + * RFC 4122 variant UUIDs are comprised of a set of named fields + * + * Internally, this class represents the fields together as a 16-byte binary + * string. + * + * @psalm-immutable + */ +final class Fields implements FieldsInterface +{ + use NilTrait; + use SerializableFieldsTrait; + use VariantTrait; + use VersionTrait; + + /** + * @var string + */ + private $bytes; + + /** + * @param string $bytes A 16-byte binary string representation of a UUID + * + * @throws InvalidArgumentException if the byte string is not exactly 16 bytes + * @throws InvalidArgumentException if the byte string does not represent an RFC 4122 UUID + * @throws InvalidArgumentException if the byte string does not contain a valid version + */ + public function __construct(string $bytes) + { + if (strlen($bytes) !== 16) { + throw new InvalidArgumentException( + 'The byte string must be 16 bytes long; ' + . 'received ' . strlen($bytes) . ' bytes' + ); + } + + $this->bytes = $bytes; + + if (!$this->isCorrectVariant()) { + throw new InvalidArgumentException( + 'The byte string received does not conform to the RFC 4122 variant' + ); + } + + if (!$this->isCorrectVersion()) { + throw new InvalidArgumentException( + 'The byte string received does not contain a valid RFC 4122 version' + ); + } + } + + public function getBytes(): string + { + return $this->bytes; + } + + public function getClockSeq(): Hexadecimal + { + $clockSeq = hexdec(bin2hex(substr($this->bytes, 8, 2))) & 0x3fff; + + return new Hexadecimal(str_pad(dechex($clockSeq), 4, '0', STR_PAD_LEFT)); + } + + public function getClockSeqHiAndReserved(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 8, 1))); + } + + public function getClockSeqLow(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 9, 1))); + } + + public function getNode(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 10))); + } + + public function getTimeHiAndVersion(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 6, 2))); + } + + public function getTimeLow(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 0, 4))); + } + + public function getTimeMid(): Hexadecimal + { + return new Hexadecimal(bin2hex(substr($this->bytes, 4, 2))); + } + + /** + * Returns the full 60-bit timestamp, without the version + * + * For version 2 UUIDs, the time_low field is the local identifier and + * should not be returned as part of the time. For this reason, we set the + * bottom 32 bits of the timestamp to 0's. As a result, there is some loss + * of fidelity of the timestamp, for version 2 UUIDs. The timestamp can be + * off by a range of 0 to 429.4967295 seconds (or 7 minutes, 9 seconds, and + * 496730 microseconds). + * + * For version 6 UUIDs, the timestamp order is reversed from the typical RFC + * 4122 order (the time bits are in the correct bit order, so that it is + * monotonically increasing). In returning the timestamp value, we put the + * bits in the order: time_low + time_mid + time_hi. + */ + public function getTimestamp(): Hexadecimal + { + switch ($this->getVersion()) { + case Uuid::UUID_TYPE_DCE_SECURITY: + $timestamp = sprintf( + '%03x%04s%08s', + hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff, + $this->getTimeMid()->toString(), + '' + ); + + break; + case Uuid::UUID_TYPE_PEABODY: + $timestamp = sprintf( + '%08s%04s%03x', + $this->getTimeLow()->toString(), + $this->getTimeMid()->toString(), + hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff + ); + + break; + default: + $timestamp = sprintf( + '%03x%04s%08s', + hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff, + $this->getTimeMid()->toString(), + $this->getTimeLow()->toString() + ); + } + + return new Hexadecimal($timestamp); + } + + public function getVersion(): ?int + { + if ($this->isNil()) { + return null; + } + + /** @var array $parts */ + $parts = unpack('n*', $this->bytes); + + return (int) $parts[4] >> 12; + } + + private function isCorrectVariant(): bool + { + if ($this->isNil()) { + return true; + } + + return $this->getVariant() === Uuid::RFC_4122; + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php b/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php new file mode 100644 index 0000000..a303525 --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php @@ -0,0 +1,126 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\Fields\FieldsInterface as BaseFieldsInterface; +use Ramsey\Uuid\Type\Hexadecimal; + +/** + * RFC 4122 defines fields for a specific variant of UUID + * + * The fields of an RFC 4122 variant UUID are: + * + * * **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 + * + * @link http://tools.ietf.org/html/rfc4122#section-4.1 RFC 4122, § 4.1: Format + * + * @psalm-immutable + */ +interface FieldsInterface extends BaseFieldsInterface +{ + /** + * Returns the full 16-bit clock sequence, with the variant bits (two most + * significant bits) masked out + */ + public function getClockSeq(): Hexadecimal; + + /** + * Returns the high field of the clock sequence multiplexed with the variant + */ + public function getClockSeqHiAndReserved(): Hexadecimal; + + /** + * Returns the low field of the clock sequence + */ + public function getClockSeqLow(): Hexadecimal; + + /** + * Returns the node field + */ + public function getNode(): Hexadecimal; + + /** + * Returns the high field of the timestamp multiplexed with the version + */ + public function getTimeHiAndVersion(): Hexadecimal; + + /** + * Returns the low field of the timestamp + */ + public function getTimeLow(): Hexadecimal; + + /** + * Returns the middle field of the timestamp + */ + public function getTimeMid(): Hexadecimal; + + /** + * Returns the full 60-bit timestamp, without the version + */ + public function getTimestamp(): Hexadecimal; + + /** + * Returns the variant + * + * 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 + * - 6 - Reserved, Microsoft Corporation backward compatibility + * - 7 - Reserved for future definition + * + * For RFC 4122 variant UUIDs, this value should always be the integer `2`. + * + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 RFC 4122, § 4.1.1: Variant + */ + public function getVariant(): int; + + /** + * Returns the version + * + * The version number describes how the 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 + * + * This returns `null` if the UUID is not an RFC 4122 variant, since version + * is only meaningful for this variant. + * + * @link http://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, § 4.1.3: Version + */ + public function getVersion(): ?int; + + /** + * Returns true if these fields represent a nil UUID + * + * The nil UUID is special form of UUID that is specified to have all 128 + * bits set to zero. + */ + public function isNil(): bool; +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/NilTrait.php b/vendor/ramsey/uuid/src/Rfc4122/NilTrait.php new file mode 100644 index 0000000..9a9774d --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/NilTrait.php @@ -0,0 +1,41 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +/** + * Provides common functionality for nil UUIDs + * + * The nil UUID is special form of UUID that is specified to have all 128 bits + * set to zero. + * + * @link https://tools.ietf.org/html/rfc4122#section-4.1.7 RFC 4122, § 4.1.7: Nil UUID + * + * @psalm-immutable + */ +trait NilTrait +{ + /** + * Returns the bytes that comprise the fields + */ + abstract public function getBytes(): string; + + /** + * Returns true if the byte string represents a nil UUID + */ + public function isNil(): bool + { + return $this->getBytes() === "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/NilUuid.php b/vendor/ramsey/uuid/src/Rfc4122/NilUuid.php new file mode 100644 index 0000000..c49b994 --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/NilUuid.php @@ -0,0 +1,27 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\Uuid; + +/** + * The nil UUID is special form of UUID that is specified to have all 128 bits + * set to zero + * + * @psalm-immutable + */ +final class NilUuid extends Uuid implements UuidInterface +{ +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php b/vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php new file mode 100644 index 0000000..736931a --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php @@ -0,0 +1,111 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\Builder\UuidBuilderInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\UnableToBuildUuidException; +use Ramsey\Uuid\Exception\UnsupportedOperationException; +use Ramsey\Uuid\Nonstandard\UuidV6; +use Ramsey\Uuid\Rfc4122\UuidInterface as Rfc4122UuidInterface; +use Ramsey\Uuid\UuidInterface; +use Throwable; + +/** + * UuidBuilder builds instances of RFC 4122 UUIDs + * + * @psalm-immutable + */ +class UuidBuilder implements UuidBuilderInterface +{ + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * Constructs the DefaultUuidBuilder + * + * @param NumberConverterInterface $numberConverter The number converter to + * use when constructing the Uuid + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to Unix timestamps + */ + public function __construct( + NumberConverterInterface $numberConverter, + TimeConverterInterface $timeConverter + ) { + $this->numberConverter = $numberConverter; + $this->timeConverter = $timeConverter; + } + + /** + * Builds and returns a Uuid + * + * @param CodecInterface $codec The codec to use for building this Uuid instance + * @param string $bytes The byte string from which to construct a UUID + * + * @return Rfc4122UuidInterface UuidBuilder returns instances of Rfc4122UuidInterface + * + * @psalm-pure + */ + public function build(CodecInterface $codec, string $bytes): UuidInterface + { + try { + $fields = $this->buildFields($bytes); + + if ($fields->isNil()) { + return new NilUuid($fields, $this->numberConverter, $codec, $this->timeConverter); + } + + switch ($fields->getVersion()) { + case 1: + return new UuidV1($fields, $this->numberConverter, $codec, $this->timeConverter); + case 2: + return new UuidV2($fields, $this->numberConverter, $codec, $this->timeConverter); + case 3: + return new UuidV3($fields, $this->numberConverter, $codec, $this->timeConverter); + case 4: + return new UuidV4($fields, $this->numberConverter, $codec, $this->timeConverter); + case 5: + return new UuidV5($fields, $this->numberConverter, $codec, $this->timeConverter); + case 6: + return new UuidV6($fields, $this->numberConverter, $codec, $this->timeConverter); + } + + throw new UnsupportedOperationException( + 'The UUID version in the given fields is not supported ' + . 'by this UUID builder' + ); + } catch (Throwable $e) { + throw new UnableToBuildUuidException($e->getMessage(), (int) $e->getCode(), $e); + } + } + + /** + * Proxy method to allow injecting a mock, for testing + */ + protected function buildFields(string $bytes): FieldsInterface + { + return new Fields($bytes); + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php b/vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php new file mode 100644 index 0000000..3e4d9fa --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php @@ -0,0 +1,36 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\UuidInterface as BaseUuidInterface; + +/** + * Also known as a Leach-Salz variant UUID, an RFC 4122 variant UUID is a + * universally unique identifier defined by RFC 4122 + * + * @link https://tools.ietf.org/html/rfc4122 RFC 4122 + * + * @psalm-immutable + */ +interface UuidInterface extends BaseUuidInterface +{ + /** + * Returns the string standard representation of the UUID as a URN + * + * @link http://en.wikipedia.org/wiki/Uniform_Resource_Name Uniform Resource Name + * @link https://tools.ietf.org/html/rfc4122#section-3 RFC 4122, § 3: Namespace Registration Template + */ + public function getUrn(): string; +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV1.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV1.php new file mode 100644 index 0000000..764e42f --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV1.php @@ -0,0 +1,92 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use DateTimeImmutable; +use DateTimeInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\DateTimeException; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Uuid; +use Throwable; + +use function str_pad; + +use const STR_PAD_LEFT; + +/** + * Time-based, or version 1, UUIDs include timestamp, clock sequence, and node + * values that are combined into a 128-bit unsigned integer + * + * @psalm-immutable + */ +final class UuidV1 extends Uuid implements UuidInterface +{ + /** + * Creates a version 1 (time-based) UUID + * + * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID + * @param NumberConverterInterface $numberConverter 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 + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to unix timestamps + */ + public function __construct( + Rfc4122FieldsInterface $fields, + NumberConverterInterface $numberConverter, + CodecInterface $codec, + TimeConverterInterface $timeConverter + ) { + if ($fields->getVersion() !== Uuid::UUID_TYPE_TIME) { + throw new InvalidArgumentException( + 'Fields used to create a UuidV1 must represent a ' + . 'version 1 (time-based) UUID' + ); + } + + parent::__construct($fields, $numberConverter, $codec, $timeConverter); + } + + /** + * Returns a DateTimeInterface object representing the timestamp associated + * with the UUID + * + * The timestamp value is only meaningful in a time-based UUID, which + * has version type 1. + * + * @return DateTimeImmutable A PHP DateTimeImmutable instance representing + * the timestamp of a version 1 UUID + */ + public function getDateTime(): DateTimeInterface + { + $time = $this->timeConverter->convertTime($this->fields->getTimestamp()); + + try { + return new DateTimeImmutable( + '@' + . $time->getSeconds()->toString() + . '.' + . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT) + ); + } catch (Throwable $e) { + throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e); + } + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php new file mode 100644 index 0000000..74906f0 --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php @@ -0,0 +1,143 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use DateTimeImmutable; +use DateTimeInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\DateTimeException; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Uuid; +use Throwable; + +use function hexdec; +use function str_pad; + +use const STR_PAD_LEFT; + +/** + * DCE Security version, or version 2, UUIDs include local domain identifier, + * local ID for the specified domain, and node values that are combined into a + * 128-bit unsigned integer + * + * @link https://publications.opengroup.org/c311 DCE 1.1: Authentication and Security Services + * @link https://publications.opengroup.org/c706 DCE 1.1: Remote Procedure Call + * @link https://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01 DCE 1.1: Auth & Sec, §5.2.1.1 + * @link https://pubs.opengroup.org/onlinepubs/9696989899/chap11.htm#tagcjh_14_05_01_01 DCE 1.1: Auth & Sec, §11.5.1.1 + * @link https://pubs.opengroup.org/onlinepubs/9629399/apdxa.htm DCE 1.1: RPC, Appendix A + * @link https://github.com/google/uuid Go package for UUIDs (includes DCE implementation) + * + * @psalm-immutable + */ +final class UuidV2 extends Uuid implements UuidInterface +{ + /** + * Creates a version 2 (DCE Security) UUID + * + * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID + * @param NumberConverterInterface $numberConverter 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 + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to unix timestamps + */ + public function __construct( + Rfc4122FieldsInterface $fields, + NumberConverterInterface $numberConverter, + CodecInterface $codec, + TimeConverterInterface $timeConverter + ) { + if ($fields->getVersion() !== Uuid::UUID_TYPE_DCE_SECURITY) { + throw new InvalidArgumentException( + 'Fields used to create a UuidV2 must represent a ' + . 'version 2 (DCE Security) UUID' + ); + } + + parent::__construct($fields, $numberConverter, $codec, $timeConverter); + } + + /** + * Returns a DateTimeInterface object representing the timestamp associated + * with the UUID + * + * It is important to note that a version 2 UUID suffers from some loss of + * fidelity of the timestamp, due to replacing the time_low field with the + * local identifier. When constructing the timestamp value for date + * purposes, we replace the local identifier bits with zeros. As a result, + * the timestamp can be off by a range of 0 to 429.4967295 seconds (or 7 + * minutes, 9 seconds, and 496730 microseconds). + * + * Astute observers might note this value directly corresponds to 2^32 - 1, + * or 0xffffffff. The local identifier is 32-bits, and we have set each of + * these bits to 0, so the maximum range of timestamp drift is 0x00000000 + * to 0xffffffff (counted in 100-nanosecond intervals). + * + * @return DateTimeImmutable A PHP DateTimeImmutable instance representing + * the timestamp of a version 2 UUID + */ + public function getDateTime(): DateTimeInterface + { + $time = $this->timeConverter->convertTime($this->fields->getTimestamp()); + + try { + return new DateTimeImmutable( + '@' + . $time->getSeconds()->toString() + . '.' + . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT) + ); + } catch (Throwable $e) { + throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e); + } + } + + /** + * Returns the local domain used to create this version 2 UUID + */ + public function getLocalDomain(): int + { + /** @var Rfc4122FieldsInterface $fields */ + $fields = $this->getFields(); + + return (int) hexdec($fields->getClockSeqLow()->toString()); + } + + /** + * Returns the string name of the local domain + */ + public function getLocalDomainName(): string + { + return Uuid::DCE_DOMAIN_NAMES[$this->getLocalDomain()]; + } + + /** + * Returns the local identifier for the domain used to create this version 2 UUID + */ + public function getLocalIdentifier(): IntegerObject + { + /** @var Rfc4122FieldsInterface $fields */ + $fields = $this->getFields(); + + return new IntegerObject( + $this->numberConverter->fromHex($fields->getTimeLow()->toString()) + ); + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV3.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV3.php new file mode 100644 index 0000000..deaa54e --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV3.php @@ -0,0 +1,58 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Uuid; + +/** + * Version 3 UUIDs are named-based, using combination of a namespace and name + * that are hashed into a 128-bit unsigned integer using MD5 + * + * @psalm-immutable + */ +final class UuidV3 extends Uuid implements UuidInterface +{ + /** + * Creates a version 3 (name-based, MD5-hashed) UUID + * + * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID + * @param NumberConverterInterface $numberConverter 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 + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to unix timestamps + */ + public function __construct( + Rfc4122FieldsInterface $fields, + NumberConverterInterface $numberConverter, + CodecInterface $codec, + TimeConverterInterface $timeConverter + ) { + if ($fields->getVersion() !== Uuid::UUID_TYPE_HASH_MD5) { + throw new InvalidArgumentException( + 'Fields used to create a UuidV3 must represent a ' + . 'version 3 (name-based, MD5-hashed) UUID' + ); + } + + parent::__construct($fields, $numberConverter, $codec, $timeConverter); + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV4.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV4.php new file mode 100644 index 0000000..2e57246 --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV4.php @@ -0,0 +1,58 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Uuid; + +/** + * Random, or version 4, UUIDs are randomly or pseudo-randomly generated 128-bit + * integers + * + * @psalm-immutable + */ +final class UuidV4 extends Uuid implements UuidInterface +{ + /** + * Creates a version 4 (random) UUID + * + * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID + * @param NumberConverterInterface $numberConverter 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 + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to unix timestamps + */ + public function __construct( + Rfc4122FieldsInterface $fields, + NumberConverterInterface $numberConverter, + CodecInterface $codec, + TimeConverterInterface $timeConverter + ) { + if ($fields->getVersion() !== Uuid::UUID_TYPE_RANDOM) { + throw new InvalidArgumentException( + 'Fields used to create a UuidV4 must represent a ' + . 'version 4 (random) UUID' + ); + } + + parent::__construct($fields, $numberConverter, $codec, $timeConverter); + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV5.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV5.php new file mode 100644 index 0000000..2ef6ab3 --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV5.php @@ -0,0 +1,58 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Uuid; + +/** + * Version 5 UUIDs are named-based, using combination of a namespace and name + * that are hashed into a 128-bit unsigned integer using SHA1 + * + * @psalm-immutable + */ +final class UuidV5 extends Uuid implements UuidInterface +{ + /** + * Creates a version 5 (name-based, SHA1-hashed) UUID + * + * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID + * @param NumberConverterInterface $numberConverter 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 + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to unix timestamps + */ + public function __construct( + Rfc4122FieldsInterface $fields, + NumberConverterInterface $numberConverter, + CodecInterface $codec, + TimeConverterInterface $timeConverter + ) { + if ($fields->getVersion() !== Uuid::UUID_TYPE_HASH_SHA1) { + throw new InvalidArgumentException( + 'Fields used to create a UuidV5 must represent a ' + . 'version 5 (named-based, SHA1-hashed) UUID' + ); + } + + parent::__construct($fields, $numberConverter, $codec, $timeConverter); + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/Validator.php b/vendor/ramsey/uuid/src/Rfc4122/Validator.php new file mode 100644 index 0000000..ed43c98 --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/Validator.php @@ -0,0 +1,49 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\Validator\ValidatorInterface; + +use function preg_match; +use function str_replace; + +/** + * Rfc4122\Validator validates strings as UUIDs of the RFC 4122 variant + * + * @psalm-immutable + */ +final class Validator implements ValidatorInterface +{ + private const VALID_PATTERN = '\A[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-' + . '[1-5]{1}[0-9A-Fa-f]{3}-[ABab89]{1}[0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}\z'; + + /** + * @psalm-return non-empty-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function getPattern(): string + { + return self::VALID_PATTERN; + } + + public function validate(string $uuid): bool + { + $uuid = str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid); + + return $uuid === Uuid::NIL || preg_match('/' . self::VALID_PATTERN . '/Dms', $uuid); + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php b/vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php new file mode 100644 index 0000000..4c98165 --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php @@ -0,0 +1,90 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +use Ramsey\Uuid\Exception\InvalidBytesException; +use Ramsey\Uuid\Uuid; + +use function decbin; +use function str_pad; +use function strlen; +use function strpos; +use function substr; +use function unpack; + +use const STR_PAD_LEFT; + +/** + * Provides common functionality for handling the variant, as defined by RFC 4122 + * + * @psalm-immutable + */ +trait VariantTrait +{ + /** + * Returns the bytes that comprise the fields + */ + abstract public function getBytes(): string; + + /** + * Returns the variant identifier, according to RFC 4122, for the given bytes + * + * The following values may be returned: + * + * - `0` -- Reserved, NCS backward compatibility. + * - `2` -- The variant specified in RFC 4122. + * - `6` -- Reserved, Microsoft Corporation backward compatibility. + * - `7` -- Reserved for future definition. + * + * @link https://tools.ietf.org/html/rfc4122#section-4.1.1 RFC 4122, § 4.1.1: Variant + * + * @return int The variant identifier, according to RFC 4122 + */ + public function getVariant(): int + { + if (strlen($this->getBytes()) !== 16) { + throw new InvalidBytesException('Invalid number of bytes'); + } + + /** @var array $parts */ + $parts = unpack('n*', $this->getBytes()); + + // $parts[5] is a 16-bit, unsigned integer containing the variant bits + // of the UUID. We convert this integer into a string containing a + // binary representation, padded to 16 characters. We analyze the first + // three characters (three most-significant bits) to determine the + // variant. + $binary = str_pad( + decbin((int) $parts[5]), + 16, + '0', + STR_PAD_LEFT + ); + + $msb = substr($binary, 0, 3); + + if ($msb === '111') { + $variant = Uuid::RESERVED_FUTURE; + } elseif ($msb === '110') { + $variant = Uuid::RESERVED_MICROSOFT; + } elseif (strpos($msb, '10') === 0) { + $variant = Uuid::RFC_4122; + } else { + $variant = Uuid::RESERVED_NCS; + } + + return $variant; + } +} diff --git a/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php b/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php new file mode 100644 index 0000000..cee55fb --- /dev/null +++ b/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php @@ -0,0 +1,57 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Rfc4122; + +/** + * Provides common functionality for handling the version, as defined by RFC 4122 + * + * @psalm-immutable + */ +trait VersionTrait +{ + /** + * Returns the version + */ + abstract public function getVersion(): ?int; + + /** + * Returns true if these fields represent a nil UUID + */ + abstract public function isNil(): bool; + + /** + * Returns true if the version matches one of those defined by RFC 4122 + * + * @return bool True if the UUID version is valid, false otherwise + */ + private function isCorrectVersion(): bool + { + if ($this->isNil()) { + return true; + } + + switch ($this->getVersion()) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + return true; + } + + return false; + } +} diff --git a/vendor/ramsey/uuid/src/Type/Decimal.php b/vendor/ramsey/uuid/src/Type/Decimal.php new file mode 100644 index 0000000..10f9384 --- /dev/null +++ b/vendor/ramsey/uuid/src/Type/Decimal.php @@ -0,0 +1,137 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Type; + +use Ramsey\Uuid\Exception\InvalidArgumentException; +use ValueError; + +use function is_numeric; +use function sprintf; + +/** + * A value object representing a decimal + * + * This class exists for type-safety purposes, to ensure that decimals + * returned from ramsey/uuid methods as strings are truly decimals and not some + * other kind of string. + * + * To support values as true decimals and not as floats or doubles, we store the + * decimals as strings. + * + * @psalm-immutable + */ +final class Decimal implements NumberInterface +{ + /** + * @var string + */ + private $value; + + /** + * @var bool + */ + private $isNegative = false; + + /** + * @param mixed $value The decimal value to store + */ + public function __construct($value) + { + $value = (string) $value; + + if (!is_numeric($value)) { + throw new InvalidArgumentException( + 'Value must be a signed decimal or a string containing only ' + . 'digits 0-9 and, optionally, a decimal point or sign (+ or -)' + ); + } + + // Remove the leading +-symbol. + if (strpos($value, '+') === 0) { + $value = substr($value, 1); + } + + // For cases like `-0` or `-0.0000`, convert the value to `0`. + if (abs((float) $value) === 0.0) { + $value = '0'; + } + + if (strpos($value, '-') === 0) { + $this->isNegative = true; + } + + $this->value = $value; + } + + public function isNegative(): bool + { + return $this->isNegative; + } + + public function toString(): string + { + return $this->value; + } + + public function __toString(): string + { + return $this->toString(); + } + + public function jsonSerialize(): string + { + return $this->toString(); + } + + public function serialize(): string + { + return $this->toString(); + } + + /** + * @return array{string: string} + */ + public function __serialize(): array + { + return ['string' => $this->toString()]; + } + + /** + * Constructs the object from a serialized string representation + * + * @param string $serialized The serialized string representation of the object + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + * @psalm-suppress UnusedMethodCall + */ + public function unserialize($serialized): void + { + $this->__construct($serialized); + } + + /** + * @param array{string: string} $data + */ + public function __unserialize(array $data): void + { + // @codeCoverageIgnoreStart + if (!isset($data['string'])) { + throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__)); + } + // @codeCoverageIgnoreEnd + + $this->unserialize($data['string']); + } +} diff --git a/vendor/ramsey/uuid/src/Type/Hexadecimal.php b/vendor/ramsey/uuid/src/Type/Hexadecimal.php new file mode 100644 index 0000000..88adc2e --- /dev/null +++ b/vendor/ramsey/uuid/src/Type/Hexadecimal.php @@ -0,0 +1,116 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Type; + +use Ramsey\Uuid\Exception\InvalidArgumentException; +use ValueError; + +use function ctype_xdigit; +use function sprintf; +use function strpos; +use function strtolower; +use function substr; + +/** + * A value object representing a hexadecimal number + * + * This class exists for type-safety purposes, to ensure that hexadecimal numbers + * returned from ramsey/uuid methods as strings are truly hexadecimal and not some + * other kind of string. + * + * @psalm-immutable + */ +final class Hexadecimal implements TypeInterface +{ + /** + * @var string + */ + private $value; + + /** + * @param string $value The hexadecimal value to store + */ + public function __construct(string $value) + { + $value = strtolower($value); + + if (strpos($value, '0x') === 0) { + $value = substr($value, 2); + } + + if (!ctype_xdigit($value)) { + throw new InvalidArgumentException( + 'Value must be a hexadecimal number' + ); + } + + $this->value = $value; + } + + public function toString(): string + { + return $this->value; + } + + public function __toString(): string + { + return $this->toString(); + } + + public function jsonSerialize(): string + { + return $this->toString(); + } + + public function serialize(): string + { + return $this->toString(); + } + + /** + * @return array{string: string} + */ + public function __serialize(): array + { + return ['string' => $this->toString()]; + } + + /** + * Constructs the object from a serialized string representation + * + * @param string $serialized The serialized string representation of the object + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + * @psalm-suppress UnusedMethodCall + */ + public function unserialize($serialized): void + { + $this->__construct($serialized); + } + + /** + * @param array{string: string} $data + */ + public function __unserialize(array $data): void + { + // @codeCoverageIgnoreStart + if (!isset($data['string'])) { + throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__)); + } + // @codeCoverageIgnoreEnd + + $this->unserialize($data['string']); + } +} diff --git a/vendor/ramsey/uuid/src/Type/Integer.php b/vendor/ramsey/uuid/src/Type/Integer.php new file mode 100644 index 0000000..7690f6c --- /dev/null +++ b/vendor/ramsey/uuid/src/Type/Integer.php @@ -0,0 +1,153 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Type; + +use Ramsey\Uuid\Exception\InvalidArgumentException; +use ValueError; + +use function ctype_digit; +use function ltrim; +use function sprintf; +use function strpos; +use function substr; + +/** + * A value object representing an integer + * + * This class exists for type-safety purposes, to ensure that integers + * returned from ramsey/uuid methods as strings are truly integers and not some + * other kind of string. + * + * To support large integers beyond PHP_INT_MAX and PHP_INT_MIN on both 64-bit + * and 32-bit systems, we store the integers as strings. + * + * @psalm-immutable + */ +final class Integer implements NumberInterface +{ + /** + * @psalm-var numeric-string + */ + private $value; + + /** + * @var bool + */ + private $isNegative = false; + + /** + * @param mixed $value The integer value to store + */ + public function __construct($value) + { + $value = (string) $value; + $sign = '+'; + + // If the value contains a sign, remove it for ctype_digit() check. + if (strpos($value, '-') === 0 || strpos($value, '+') === 0) { + $sign = substr($value, 0, 1); + $value = substr($value, 1); + } + + if (!ctype_digit($value)) { + throw new InvalidArgumentException( + 'Value must be a signed integer or a string containing only ' + . 'digits 0-9 and, optionally, a sign (+ or -)' + ); + } + + // Trim any leading zeros. + $value = ltrim($value, '0'); + + // Set to zero if the string is empty after trimming zeros. + if ($value === '') { + $value = '0'; + } + + // Add the negative sign back to the value. + if ($sign === '-' && $value !== '0') { + $value = $sign . $value; + $this->isNegative = true; + } + + /** @psalm-var numeric-string $numericValue */ + $numericValue = $value; + + $this->value = $numericValue; + } + + public function isNegative(): bool + { + return $this->isNegative; + } + + /** + * @psalm-return numeric-string + */ + public function toString(): string + { + return $this->value; + } + + public function __toString(): string + { + return $this->toString(); + } + + public function jsonSerialize(): string + { + return $this->toString(); + } + + public function serialize(): string + { + return $this->toString(); + } + + /** + * @return array{string: string} + */ + public function __serialize(): array + { + return ['string' => $this->toString()]; + } + + /** + * Constructs the object from a serialized string representation + * + * @param string $serialized The serialized string representation of the object + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + * @psalm-suppress UnusedMethodCall + */ + public function unserialize($serialized): void + { + $this->__construct($serialized); + } + + /** + * @param array{string: string} $data + */ + public function __unserialize(array $data): void + { + // @codeCoverageIgnoreStart + if (!isset($data['string'])) { + throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__)); + } + // @codeCoverageIgnoreEnd + + $this->unserialize($data['string']); + } +} diff --git a/vendor/ramsey/uuid/src/Type/NumberInterface.php b/vendor/ramsey/uuid/src/Type/NumberInterface.php new file mode 100644 index 0000000..bf4ae9d --- /dev/null +++ b/vendor/ramsey/uuid/src/Type/NumberInterface.php @@ -0,0 +1,28 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Type; + +/** + * NumberInterface ensures consistency in numeric values returned by ramsey/uuid + * + * @psalm-immutable + */ +interface NumberInterface extends TypeInterface +{ + /** + * Returns true if this number is less than zero + */ + public function isNegative(): bool; +} diff --git a/vendor/ramsey/uuid/src/Type/Time.php b/vendor/ramsey/uuid/src/Type/Time.php new file mode 100644 index 0000000..dd1b8bc --- /dev/null +++ b/vendor/ramsey/uuid/src/Type/Time.php @@ -0,0 +1,139 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Type; + +use Ramsey\Uuid\Exception\UnsupportedOperationException; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use ValueError; +use stdClass; + +use function json_decode; +use function json_encode; +use function sprintf; + +/** + * A value object representing a timestamp + * + * This class exists for type-safety purposes, to ensure that timestamps used + * by ramsey/uuid are truly timestamp integers and not some other kind of string + * or integer. + * + * @psalm-immutable + */ +final class Time implements TypeInterface +{ + /** + * @var IntegerObject + */ + private $seconds; + + /** + * @var IntegerObject + */ + private $microseconds; + + /** + * @param mixed $seconds + * @param mixed $microseconds + */ + public function __construct($seconds, $microseconds = 0) + { + $this->seconds = new IntegerObject($seconds); + $this->microseconds = new IntegerObject($microseconds); + } + + public function getSeconds(): IntegerObject + { + return $this->seconds; + } + + public function getMicroseconds(): IntegerObject + { + return $this->microseconds; + } + + public function toString(): string + { + return $this->seconds->toString() . '.' . $this->microseconds->toString(); + } + + public function __toString(): string + { + return $this->toString(); + } + + /** + * @return string[] + */ + public function jsonSerialize(): array + { + return [ + 'seconds' => $this->getSeconds()->toString(), + 'microseconds' => $this->getMicroseconds()->toString(), + ]; + } + + public function serialize(): string + { + return (string) json_encode($this); + } + + /** + * @return array{seconds: string, microseconds: string} + */ + public function __serialize(): array + { + return [ + 'seconds' => $this->getSeconds()->toString(), + 'microseconds' => $this->getMicroseconds()->toString(), + ]; + } + + /** + * Constructs the object from a serialized string representation + * + * @param string $serialized The serialized string representation of the object + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + * @psalm-suppress UnusedMethodCall + */ + public function unserialize($serialized): void + { + /** @var stdClass $time */ + $time = json_decode($serialized); + + if (!isset($time->seconds) || !isset($time->microseconds)) { + throw new UnsupportedOperationException( + 'Attempted to unserialize an invalid value' + ); + } + + $this->__construct($time->seconds, $time->microseconds); + } + + /** + * @param array{seconds: string, microseconds: string} $data + */ + public function __unserialize(array $data): void + { + // @codeCoverageIgnoreStart + if (!isset($data['seconds']) || !isset($data['microseconds'])) { + throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__)); + } + // @codeCoverageIgnoreEnd + + $this->__construct($data['seconds'], $data['microseconds']); + } +} diff --git a/vendor/ramsey/uuid/src/Type/TypeInterface.php b/vendor/ramsey/uuid/src/Type/TypeInterface.php new file mode 100644 index 0000000..da2d8b2 --- /dev/null +++ b/vendor/ramsey/uuid/src/Type/TypeInterface.php @@ -0,0 +1,30 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Type; + +use JsonSerializable; +use Serializable; + +/** + * TypeInterface ensures consistency in typed values returned by ramsey/uuid + * + * @psalm-immutable + */ +interface TypeInterface extends JsonSerializable, Serializable +{ + public function toString(): string; + + public function __toString(): string; +} diff --git a/vendor/ramsey/uuid/src/Uuid.php b/vendor/ramsey/uuid/src/Uuid.php new file mode 100644 index 0000000..945480b --- /dev/null +++ b/vendor/ramsey/uuid/src/Uuid.php @@ -0,0 +1,664 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +use DateTimeInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Fields\FieldsInterface; +use Ramsey\Uuid\Lazy\LazyUuidFromString; +use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use ValueError; + +use function assert; +use function bin2hex; +use function preg_match; +use function sprintf; +use function str_replace; +use function strcmp; +use function strlen; +use function strtolower; +use function substr; + +/** + * Uuid provides constants and static methods for working with and generating UUIDs + * + * @psalm-immutable + */ +class Uuid implements UuidInterface +{ + use DeprecatedUuidMethodsTrait; + + /** + * When this namespace is specified, the name string is a fully-qualified + * domain name + * + * @link http://tools.ietf.org/html/rfc4122#appendix-C RFC 4122, Appendix C: Some Name Space IDs + */ + public 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 RFC 4122, Appendix C: Some Name Space IDs + */ + public 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 RFC 4122, Appendix C: Some Name Space IDs + */ + public 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 RFC 4122, Appendix C: Some Name Space IDs + */ + public const NAMESPACE_X500 = '6ba7b814-9dad-11d1-80b4-00c04fd430c8'; + + /** + * The nil UUID is a 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 RFC 4122, § 4.1.7: Nil UUID + */ + public const NIL = '00000000-0000-0000-0000-000000000000'; + + /** + * Variant: reserved, NCS backward compatibility + * + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 RFC 4122, § 4.1.1: Variant + */ + public const RESERVED_NCS = 0; + + /** + * Variant: the UUID layout specified in RFC 4122 + * + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 RFC 4122, § 4.1.1: Variant + */ + public const RFC_4122 = 2; + + /** + * Variant: reserved, Microsoft Corporation backward compatibility + * + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 RFC 4122, § 4.1.1: Variant + */ + public const RESERVED_MICROSOFT = 6; + + /** + * Variant: reserved for future definition + * + * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 RFC 4122, § 4.1.1: Variant + */ + public const RESERVED_FUTURE = 7; + + /** + * @deprecated Use {@see ValidatorInterface::getPattern()} instead. + */ + public 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 + * + * @link https://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, § 4.1.3: Version + */ + public const UUID_TYPE_TIME = 1; + + /** + * Version 2 (DCE Security) UUID + * + * @link https://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, § 4.1.3: Version + */ + public const UUID_TYPE_DCE_SECURITY = 2; + + /** + * @deprecated Use {@see Uuid::UUID_TYPE_DCE_SECURITY} instead. + */ + public const UUID_TYPE_IDENTIFIER = 2; + + /** + * Version 3 (name-based and hashed with MD5) UUID + * + * @link https://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, § 4.1.3: Version + */ + public const UUID_TYPE_HASH_MD5 = 3; + + /** + * Version 4 (random) UUID + * + * @link https://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, § 4.1.3: Version + */ + public const UUID_TYPE_RANDOM = 4; + + /** + * Version 5 (name-based and hashed with SHA1) UUID + * + * @link https://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, § 4.1.3: Version + */ + public const UUID_TYPE_HASH_SHA1 = 5; + + /** + * Version 6 (ordered-time) UUID + * + * This is named `UUID_TYPE_PEABODY`, since the specification is still in + * draft form, and the primary author/editor's name is Brad Peabody. + * + * @link https://github.com/uuid6/uuid6-ietf-draft UUID version 6 IETF draft + * @link http://gh.peabody.io/uuidv6/ "Version 6" UUIDs + */ + public const UUID_TYPE_PEABODY = 6; + + /** + * DCE Security principal domain + * + * @link https://pubs.opengroup.org/onlinepubs/9696989899/chap11.htm#tagcjh_14_05_01_01 DCE 1.1, §11.5.1.1 + */ + public const DCE_DOMAIN_PERSON = 0; + + /** + * DCE Security group domain + * + * @link https://pubs.opengroup.org/onlinepubs/9696989899/chap11.htm#tagcjh_14_05_01_01 DCE 1.1, §11.5.1.1 + */ + public const DCE_DOMAIN_GROUP = 1; + + /** + * DCE Security organization domain + * + * @link https://pubs.opengroup.org/onlinepubs/9696989899/chap11.htm#tagcjh_14_05_01_01 DCE 1.1, §11.5.1.1 + */ + public const DCE_DOMAIN_ORG = 2; + + /** + * DCE Security domain string names + * + * @link https://pubs.opengroup.org/onlinepubs/9696989899/chap11.htm#tagcjh_14_05_01_01 DCE 1.1, §11.5.1.1 + */ + public const DCE_DOMAIN_NAMES = [ + self::DCE_DOMAIN_PERSON => 'person', + self::DCE_DOMAIN_GROUP => 'group', + self::DCE_DOMAIN_ORG => 'org', + ]; + + /** + * @var UuidFactoryInterface|null + */ + private static $factory = null; + + /** + * @var bool flag to detect if the UUID factory was replaced internally, which disables all optimizations + * for the default/happy path internal scenarios + */ + private static $factoryReplaced = false; + + /** + * @var CodecInterface + */ + protected $codec; + + /** + * The fields that make up this UUID + * + * @var Rfc4122FieldsInterface + */ + protected $fields; + + /** + * @var NumberConverterInterface + */ + protected $numberConverter; + + /** + * @var TimeConverterInterface + */ + protected $timeConverter; + + /** + * 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 Rfc4122FieldsInterface $fields The fields from which to construct a UUID + * @param NumberConverterInterface $numberConverter 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 + * @param TimeConverterInterface $timeConverter The time converter to use + * for converting timestamps extracted from a UUID to unix timestamps + */ + public function __construct( + Rfc4122FieldsInterface $fields, + NumberConverterInterface $numberConverter, + CodecInterface $codec, + TimeConverterInterface $timeConverter + ) { + $this->fields = $fields; + $this->codec = $codec; + $this->numberConverter = $numberConverter; + $this->timeConverter = $timeConverter; + } + + /** + * @psalm-return non-empty-string + */ + public function __toString(): string + { + return $this->toString(); + } + + /** + * Converts the UUID to a string for JSON serialization + */ + public function jsonSerialize(): string + { + return $this->toString(); + } + + /** + * Converts the UUID to a string for PHP serialization + */ + public function serialize(): string + { + return $this->getFields()->getBytes(); + } + + /** + * @return array{bytes: string} + */ + public function __serialize(): array + { + return ['bytes' => $this->serialize()]; + } + + /** + * Re-constructs the object from its serialized form + * + * @param string $serialized The serialized PHP string to unserialize into + * a UuidInterface instance + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + */ + public function unserialize($serialized): void + { + if (strlen($serialized) === 16) { + /** @var Uuid $uuid */ + $uuid = self::getFactory()->fromBytes($serialized); + } else { + /** @var Uuid $uuid */ + $uuid = self::getFactory()->fromString($serialized); + } + + $this->codec = $uuid->codec; + $this->numberConverter = $uuid->numberConverter; + $this->fields = $uuid->fields; + $this->timeConverter = $uuid->timeConverter; + } + + /** + * @param array{bytes: string} $data + */ + public function __unserialize(array $data): void + { + // @codeCoverageIgnoreStart + if (!isset($data['bytes'])) { + throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__)); + } + // @codeCoverageIgnoreEnd + + $this->unserialize($data['bytes']); + } + + public function compareTo(UuidInterface $other): int + { + $compare = strcmp($this->toString(), $other->toString()); + + if ($compare < 0) { + return -1; + } + + if ($compare > 0) { + return 1; + } + + return 0; + } + + public function equals(?object $other): bool + { + if (!$other instanceof UuidInterface) { + return false; + } + + return $this->compareTo($other) === 0; + } + + /** + * @psalm-return non-empty-string + */ + public function getBytes(): string + { + return $this->codec->encodeBinary($this); + } + + public function getFields(): FieldsInterface + { + return $this->fields; + } + + public function getHex(): Hexadecimal + { + return new Hexadecimal(str_replace('-', '', $this->toString())); + } + + public function getInteger(): IntegerObject + { + return new IntegerObject($this->numberConverter->fromHex($this->getHex()->toString())); + } + + /** + * @psalm-return non-empty-string + */ + public function toString(): string + { + return $this->codec->encode($this); + } + + /** + * Returns the factory used to create UUIDs + */ + public static function getFactory(): UuidFactoryInterface + { + if (self::$factory === null) { + self::$factory = new UuidFactory(); + } + + return self::$factory; + } + + /** + * Sets the factory used to create UUIDs + * + * @param UuidFactoryInterface $factory A factory that will be used by this + * class to create UUIDs + */ + public static function setFactory(UuidFactoryInterface $factory): void + { + // Note: non-strict equality is intentional here. If the factory is configured differently, every assumption + // around purity is broken, and we have to internally decide everything differently. + // phpcs:ignore SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator + self::$factoryReplaced = ($factory != new UuidFactory()); + + self::$factory = $factory; + } + + /** + * Creates a UUID from a byte string + * + * @param string $bytes A binary string + * + * @return UuidInterface A UuidInterface instance created from a binary + * string representation + * + * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, + * but under constant factory setups, this method operates in functionally pure manners + * + * @psalm-suppress ImpureStaticProperty we know that the factory being replaced can lead to massive + * havoc across all consumers: that should never happen, and + * is generally to be discouraged. Until the factory is kept + * un-replaced, this method is effectively pure. + */ + public static function fromBytes(string $bytes): UuidInterface + { + if (! self::$factoryReplaced && strlen($bytes) === 16) { + $base16Uuid = bin2hex($bytes); + + // Note: we are calling `fromString` internally because we don't know if the given `$bytes` is a valid UUID + return self::fromString( + substr($base16Uuid, 0, 8) + . '-' + . substr($base16Uuid, 8, 4) + . '-' + . substr($base16Uuid, 12, 4) + . '-' + . substr($base16Uuid, 16, 4) + . '-' + . substr($base16Uuid, 20, 12) + ); + } + + return self::getFactory()->fromBytes($bytes); + } + + /** + * Creates a UUID from the string standard representation + * + * @param string $uuid A hexadecimal string + * + * @return UuidInterface A UuidInterface instance created from a hexadecimal + * string representation + * + * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, + * but under constant factory setups, this method operates in functionally pure manners + * + * @psalm-suppress ImpureStaticProperty we know that the factory being replaced can lead to massive + * havoc across all consumers: that should never happen, and + * is generally to be discouraged. Until the factory is kept + * un-replaced, this method is effectively pure. + */ + public static function fromString(string $uuid): UuidInterface + { + if (! self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) { + assert($uuid !== ''); + + return new LazyUuidFromString(strtolower($uuid)); + } + + return self::getFactory()->fromString($uuid); + } + + /** + * Creates a UUID from a DateTimeInterface instance + * + * @param DateTimeInterface $dateTime The date and time + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 A UuidInterface instance that represents a + * version 1 UUID created from a DateTimeInterface instance + */ + public static function fromDateTime( + DateTimeInterface $dateTime, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): UuidInterface { + return self::getFactory()->fromDateTime($dateTime, $node, $clockSeq); + } + + /** + * Creates a UUID from a 128-bit integer string + * + * @param string $integer String representation of 128-bit integer + * + * @return UuidInterface A UuidInterface instance created from the string + * representation of a 128-bit integer + * + * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, + * but under constant factory setups, this method operates in functionally pure manners + */ + public static function fromInteger(string $integer): UuidInterface + { + return self::getFactory()->fromInteger($integer); + } + + /** + * Returns true if the provided string is a valid UUID + * + * @param string $uuid A string to validate as a UUID + * + * @return bool True if the string is a valid UUID, false otherwise + * + * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, + * but under constant factory setups, this method operates in functionally pure manners + */ + public static function isValid(string $uuid): bool + { + return self::getFactory()->getValidator()->validate($uuid); + } + + /** + * Returns a version 1 (time-based) UUID from a host ID, sequence number, + * and the current time + * + * @param Hexadecimal|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 $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 A UuidInterface instance that represents a + * version 1 UUID + */ + public static function uuid1($node = null, ?int $clockSeq = null): UuidInterface + { + return self::getFactory()->uuid1($node, $clockSeq); + } + + /** + * Returns a version 2 (DCE Security) UUID from a local domain, local + * identifier, host ID, clock sequence, and the current time + * + * @param int $localDomain The local domain to use when generating bytes, + * according to DCE Security + * @param IntegerObject|null $localIdentifier The local identifier for the + * given domain; this may be a UID or GID on POSIX systems, if the local + * domain is person or group, or it may be a site-defined identifier + * if the local domain is org + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 (in a version 2 UUID, the lower 8 bits of this number + * are replaced with the domain). + * + * @return UuidInterface A UuidInterface instance that represents a + * version 2 UUID + */ + public static function uuid2( + int $localDomain, + ?IntegerObject $localIdentifier = null, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): UuidInterface { + return self::getFactory()->uuid2($localDomain, $localIdentifier, $node, $clockSeq); + } + + /** + * Returns a version 3 (name-based) UUID based on the MD5 hash of a + * namespace ID and a name + * + * @param string|UuidInterface $ns The namespace (must be a valid UUID) + * @param string $name The name to use for creating a UUID + * + * @return UuidInterface A UuidInterface instance that represents a + * version 3 UUID + * + * @psalm-suppress ImpureMethodCall we know that the factory being replaced can lead to massive + * havoc across all consumers: that should never happen, and + * is generally to be discouraged. Until the factory is kept + * un-replaced, this method is effectively pure. + * + * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, + * but under constant factory setups, this method operates in functionally pure manners + */ + public static function uuid3($ns, string $name): UuidInterface + { + return self::getFactory()->uuid3($ns, $name); + } + + /** + * Returns a version 4 (random) UUID + * + * @return UuidInterface A UuidInterface instance that represents a + * version 4 UUID + */ + public static function uuid4(): UuidInterface + { + return self::getFactory()->uuid4(); + } + + /** + * Returns a version 5 (name-based) UUID based on the SHA-1 hash of a + * namespace ID and a name + * + * @param string|UuidInterface $ns The namespace (must be a valid UUID) + * @param string $name The name to use for creating a UUID + * + * @return UuidInterface A UuidInterface instance that represents a + * version 5 UUID + * + * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, + * but under constant factory setups, this method operates in functionally pure manners + * + * @psalm-suppress ImpureMethodCall we know that the factory being replaced can lead to massive + * havoc across all consumers: that should never happen, and + * is generally to be discouraged. Until the factory is kept + * un-replaced, this method is effectively pure. + */ + public static function uuid5($ns, string $name): UuidInterface + { + return self::getFactory()->uuid5($ns, $name); + } + + /** + * Returns a version 6 (ordered-time) UUID from a host ID, sequence number, + * and the current time + * + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 A UuidInterface instance that represents a + * version 6 UUID + */ + public static function uuid6( + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): UuidInterface { + return self::getFactory()->uuid6($node, $clockSeq); + } +} diff --git a/vendor/ramsey/uuid/src/UuidFactory.php b/vendor/ramsey/uuid/src/UuidFactory.php new file mode 100644 index 0000000..6f2cea0 --- /dev/null +++ b/vendor/ramsey/uuid/src/UuidFactory.php @@ -0,0 +1,493 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +use DateTimeInterface; +use Ramsey\Uuid\Builder\UuidBuilderInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Generator\DceSecurityGeneratorInterface; +use Ramsey\Uuid\Generator\DefaultTimeGenerator; +use Ramsey\Uuid\Generator\NameGeneratorInterface; +use Ramsey\Uuid\Generator\RandomGeneratorInterface; +use Ramsey\Uuid\Generator\TimeGeneratorInterface; +use Ramsey\Uuid\Lazy\LazyUuidFromString; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Provider\Time\FixedTimeProvider; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Type\Time; +use Ramsey\Uuid\Validator\ValidatorInterface; + +use function bin2hex; +use function hex2bin; +use function pack; +use function str_pad; +use function strtolower; +use function substr; +use function substr_replace; +use function unpack; + +use const STR_PAD_LEFT; + +class UuidFactory implements UuidFactoryInterface +{ + /** + * @var CodecInterface + */ + private $codec; + + /** + * @var DceSecurityGeneratorInterface + */ + private $dceSecurityGenerator; + + /** + * @var NameGeneratorInterface + */ + private $nameGenerator; + + /** + * @var NodeProviderInterface + */ + private $nodeProvider; + + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var RandomGeneratorInterface + */ + private $randomGenerator; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; + + /** + * @var TimeGeneratorInterface + */ + private $timeGenerator; + + /** + * @var UuidBuilderInterface + */ + private $uuidBuilder; + + /** + * @var ValidatorInterface + */ + private $validator; + + /** @var bool whether the feature set was provided from outside, or we can operate under "default" assumptions */ + private $isDefaultFeatureSet; + + /** + * @param FeatureSet $features A set of available features in the current environment + */ + public function __construct(?FeatureSet $features = null) + { + $this->isDefaultFeatureSet = $features === null; + + $features = $features ?: new FeatureSet(); + + $this->codec = $features->getCodec(); + $this->dceSecurityGenerator = $features->getDceSecurityGenerator(); + $this->nameGenerator = $features->getNameGenerator(); + $this->nodeProvider = $features->getNodeProvider(); + $this->numberConverter = $features->getNumberConverter(); + $this->randomGenerator = $features->getRandomGenerator(); + $this->timeConverter = $features->getTimeConverter(); + $this->timeGenerator = $features->getTimeGenerator(); + $this->uuidBuilder = $features->getBuilder(); + $this->validator = $features->getValidator(); + } + + /** + * Returns the codec used by this factory + */ + public function getCodec(): CodecInterface + { + return $this->codec; + } + + /** + * Sets the codec to use for this factory + * + * @param CodecInterface $codec A UUID encoder-decoder + */ + public function setCodec(CodecInterface $codec): void + { + $this->isDefaultFeatureSet = false; + + $this->codec = $codec; + } + + /** + * Returns the name generator used by this factory + */ + public function getNameGenerator(): NameGeneratorInterface + { + return $this->nameGenerator; + } + + /** + * Sets the name generator to use for this factory + * + * @param NameGeneratorInterface $nameGenerator A generator to generate + * binary data, based on a namespace and name + */ + public function setNameGenerator(NameGeneratorInterface $nameGenerator): void + { + $this->isDefaultFeatureSet = false; + + $this->nameGenerator = $nameGenerator; + } + + /** + * Returns the node provider used by this factory + */ + public function getNodeProvider(): NodeProviderInterface + { + return $this->nodeProvider; + } + + /** + * Returns the random generator used by this factory + */ + public function getRandomGenerator(): RandomGeneratorInterface + { + return $this->randomGenerator; + } + + /** + * Returns the time generator used by this factory + */ + public function getTimeGenerator(): TimeGeneratorInterface + { + return $this->timeGenerator; + } + + /** + * Sets the time generator to use for this factory + * + * @param TimeGeneratorInterface $generator A generator to generate binary + * data, based on the time + */ + public function setTimeGenerator(TimeGeneratorInterface $generator): void + { + $this->isDefaultFeatureSet = false; + + $this->timeGenerator = $generator; + } + + /** + * Returns the DCE Security generator used by this factory + */ + public function getDceSecurityGenerator(): DceSecurityGeneratorInterface + { + return $this->dceSecurityGenerator; + } + + /** + * Sets the DCE Security generator to use for this factory + * + * @param DceSecurityGeneratorInterface $generator A generator to generate + * binary data, based on a local domain and local identifier + */ + public function setDceSecurityGenerator(DceSecurityGeneratorInterface $generator): void + { + $this->isDefaultFeatureSet = false; + + $this->dceSecurityGenerator = $generator; + } + + /** + * Returns the number converter used by this factory + */ + public function getNumberConverter(): NumberConverterInterface + { + return $this->numberConverter; + } + + /** + * Sets the random generator to use for this factory + * + * @param RandomGeneratorInterface $generator A generator to generate binary + * data, based on some random input + */ + public function setRandomGenerator(RandomGeneratorInterface $generator): void + { + $this->isDefaultFeatureSet = false; + + $this->randomGenerator = $generator; + } + + /** + * Sets the number converter to use for this factory + * + * @param NumberConverterInterface $converter A converter to use for working + * with large integers (i.e. integers greater than PHP_INT_MAX) + */ + public function setNumberConverter(NumberConverterInterface $converter): void + { + $this->isDefaultFeatureSet = false; + + $this->numberConverter = $converter; + } + + /** + * Returns the UUID builder used by this factory + */ + public function getUuidBuilder(): UuidBuilderInterface + { + return $this->uuidBuilder; + } + + /** + * Sets the UUID builder to use for this factory + * + * @param UuidBuilderInterface $builder A builder for constructing instances + * of UuidInterface + */ + public function setUuidBuilder(UuidBuilderInterface $builder): void + { + $this->isDefaultFeatureSet = false; + + $this->uuidBuilder = $builder; + } + + /** + * @psalm-mutation-free + */ + public function getValidator(): ValidatorInterface + { + return $this->validator; + } + + /** + * Sets the validator to use for this factory + * + * @param ValidatorInterface $validator A validator to use for validating + * whether a string is a valid UUID + */ + public function setValidator(ValidatorInterface $validator): void + { + $this->isDefaultFeatureSet = false; + + $this->validator = $validator; + } + + /** + * @psalm-pure + */ + public function fromBytes(string $bytes): UuidInterface + { + return $this->codec->decodeBytes($bytes); + } + + /** + * @psalm-pure + */ + public function fromString(string $uuid): UuidInterface + { + $uuid = strtolower($uuid); + + return $this->codec->decode($uuid); + } + + /** + * @psalm-pure + */ + public function fromInteger(string $integer): UuidInterface + { + $hex = $this->numberConverter->toHex($integer); + $hex = str_pad($hex, 32, '0', STR_PAD_LEFT); + + return $this->fromString($hex); + } + + public function fromDateTime( + DateTimeInterface $dateTime, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): UuidInterface { + $timeProvider = new FixedTimeProvider( + new Time($dateTime->format('U'), $dateTime->format('u')) + ); + + $timeGenerator = new DefaultTimeGenerator( + $this->nodeProvider, + $this->timeConverter, + $timeProvider + ); + + $nodeHex = $node ? $node->toString() : null; + + $bytes = $timeGenerator->generate($nodeHex, $clockSeq); + + return $this->uuidFromBytesAndVersion($bytes, 1); + } + + /** + * @inheritDoc + */ + public function uuid1($node = null, ?int $clockSeq = null): UuidInterface + { + $bytes = $this->timeGenerator->generate($node, $clockSeq); + + return $this->uuidFromBytesAndVersion($bytes, 1); + } + + public function uuid2( + int $localDomain, + ?IntegerObject $localIdentifier = null, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): UuidInterface { + $bytes = $this->dceSecurityGenerator->generate( + $localDomain, + $localIdentifier, + $node, + $clockSeq + ); + + return $this->uuidFromBytesAndVersion($bytes, 2); + } + + /** + * @inheritDoc + * @psalm-pure + */ + public function uuid3($ns, string $name): UuidInterface + { + return $this->uuidFromNsAndName($ns, $name, 3, 'md5'); + } + + public function uuid4(): UuidInterface + { + $bytes = $this->randomGenerator->generate(16); + + return $this->uuidFromBytesAndVersion($bytes, 4); + } + + /** + * @inheritDoc + * @psalm-pure + */ + public function uuid5($ns, string $name): UuidInterface + { + return $this->uuidFromNsAndName($ns, $name, 5, 'sha1'); + } + + public function uuid6(?Hexadecimal $node = null, ?int $clockSeq = null): UuidInterface + { + $nodeHex = $node ? $node->toString() : null; + $bytes = $this->timeGenerator->generate($nodeHex, $clockSeq); + + // Rearrange the bytes, according to the UUID version 6 specification. + $v6 = $bytes[6] . $bytes[7] . $bytes[4] . $bytes[5] + . $bytes[0] . $bytes[1] . $bytes[2] . $bytes[3]; + $v6 = bin2hex($v6); + + // Drop the first four bits, while adding an empty four bits for the + // version field. This allows us to reconstruct the correct time from + // the bytes of this UUID. + $v6Bytes = hex2bin(substr($v6, 1, 12) . '0' . substr($v6, -3)); + $v6Bytes .= substr($bytes, 8); + + return $this->uuidFromBytesAndVersion($v6Bytes, 6); + } + + /** + * Returns a Uuid created from the provided byte string + * + * Uses the configured builder and codec and the provided byte string to + * construct a Uuid object. + * + * @param string $bytes The byte string from which to construct a UUID + * + * @return UuidInterface An instance of UuidInterface, created from the + * provided bytes + * + * @psalm-pure + */ + public function uuid(string $bytes): UuidInterface + { + return $this->uuidBuilder->build($this->codec, $bytes); + } + + /** + * Returns a version 3 or 5 namespaced Uuid + * + * @param string|UuidInterface $ns The namespace (must be a valid UUID) + * @param string $name The name to hash together with the namespace + * @param int $version The version of UUID to create (3 or 5) + * @param string $hashAlgorithm The hashing algorithm to use when hashing + * together the namespace and name + * + * @return UuidInterface An instance of UuidInterface, created by hashing + * together the provided namespace and name + * + * @psalm-pure + */ + private function uuidFromNsAndName($ns, string $name, int $version, string $hashAlgorithm): UuidInterface + { + if (!($ns instanceof UuidInterface)) { + $ns = $this->fromString($ns); + } + + $bytes = $this->nameGenerator->generate($ns, $name, $hashAlgorithm); + + return $this->uuidFromBytesAndVersion(substr($bytes, 0, 16), $version); + } + + /** + * Returns an RFC 4122 variant Uuid, created from the provided bytes and version + * + * @param string $bytes The byte string to convert to a UUID + * @param int $version The RFC 4122 version to apply to the UUID + * + * @return UuidInterface An instance of UuidInterface, created from the + * byte string and version + * + * @psalm-pure + */ + private function uuidFromBytesAndVersion(string $bytes, int $version): UuidInterface + { + /** @var array $unpackedTime */ + $unpackedTime = unpack('n*', substr($bytes, 6, 2)); + $timeHi = (int) $unpackedTime[1]; + $timeHiAndVersion = pack('n*', BinaryUtils::applyVersion($timeHi, $version)); + + /** @var array $unpackedClockSeq */ + $unpackedClockSeq = unpack('n*', substr($bytes, 8, 2)); + $clockSeqHi = (int) $unpackedClockSeq[1]; + $clockSeqHiAndReserved = pack('n*', BinaryUtils::applyVariant($clockSeqHi)); + + $bytes = substr_replace($bytes, $timeHiAndVersion, 6, 2); + $bytes = substr_replace($bytes, $clockSeqHiAndReserved, 8, 2); + + if ($this->isDefaultFeatureSet) { + return LazyUuidFromString::fromBytes($bytes); + } + + return $this->uuid($bytes); + } +} diff --git a/vendor/ramsey/uuid/src/UuidFactoryInterface.php b/vendor/ramsey/uuid/src/UuidFactoryInterface.php new file mode 100644 index 0000000..468cc63 --- /dev/null +++ b/vendor/ramsey/uuid/src/UuidFactoryInterface.php @@ -0,0 +1,182 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +use DateTimeInterface; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Validator\ValidatorInterface; + +/** + * UuidFactoryInterface defines common functionality all `UuidFactory` instances + * must implement + */ +interface UuidFactoryInterface +{ + /** + * Returns the validator to use for the factory + * + * @psalm-mutation-free + */ + public function getValidator(): ValidatorInterface; + + /** + * Returns a version 1 (time-based) UUID from a host ID, sequence number, + * and the current time + * + * @param Hexadecimal|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 A UuidInterface instance that represents a + * version 1 UUID + */ + public function uuid1($node = null, ?int $clockSeq = null): UuidInterface; + + /** + * Returns a version 2 (DCE Security) UUID from a local domain, local + * identifier, host ID, clock sequence, and the current time + * + * @param int $localDomain The local domain to use when generating bytes, + * according to DCE Security + * @param IntegerObject|null $localIdentifier The local identifier for the + * given domain; this may be a UID or GID on POSIX systems, if the local + * domain is person or group, or it may be a site-defined identifier + * if the local domain is org + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 A UuidInterface instance that represents a + * version 2 UUID + */ + public function uuid2( + int $localDomain, + ?IntegerObject $localIdentifier = null, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): UuidInterface; + + /** + * Returns a version 3 (name-based) UUID based on the MD5 hash of a + * namespace ID and a name + * + * @param string|UuidInterface $ns The namespace (must be a valid UUID) + * @param string $name The name to use for creating a UUID + * + * @return UuidInterface A UuidInterface instance that represents a + * version 3 UUID + * + * @psalm-pure + */ + public function uuid3($ns, string $name): UuidInterface; + + /** + * Returns a version 4 (random) UUID + * + * @return UuidInterface A UuidInterface instance that represents a + * version 4 UUID + */ + public function uuid4(): UuidInterface; + + /** + * Returns a version 5 (name-based) UUID based on the SHA-1 hash of a + * namespace ID and a name + * + * @param string|UuidInterface $ns The namespace (must be a valid UUID) + * @param string $name The name to use for creating a UUID + * + * @return UuidInterface A UuidInterface instance that represents a + * version 5 UUID + * + * @psalm-pure + */ + public function uuid5($ns, string $name): UuidInterface; + + /** + * Returns a version 6 (ordered-time) UUID from a host ID, sequence number, + * and the current time + * + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 A UuidInterface instance that represents a + * version 6 UUID + */ + public function uuid6(?Hexadecimal $node = null, ?int $clockSeq = null): UuidInterface; + + /** + * Creates a UUID from a byte string + * + * @param string $bytes A binary string + * + * @return UuidInterface A UuidInterface instance created from a binary + * string representation + * + * @psalm-pure + */ + public function fromBytes(string $bytes): UuidInterface; + + /** + * Creates a UUID from the string standard representation + * + * @param string $uuid A hexadecimal string + * + * @return UuidInterface A UuidInterface instance created from a hexadecimal + * string representation + * + * @psalm-pure + */ + public function fromString(string $uuid): UuidInterface; + + /** + * Creates a UUID from a 128-bit integer string + * + * @param string $integer String representation of 128-bit integer + * + * @return UuidInterface A UuidInterface instance created from the string + * representation of a 128-bit integer + * + * @psalm-pure + */ + public function fromInteger(string $integer): UuidInterface; + + /** + * Creates a UUID from a DateTimeInterface instance + * + * @param DateTimeInterface $dateTime The date and time + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 A UuidInterface instance that represents a + * version 1 UUID created from a DateTimeInterface instance + */ + public function fromDateTime( + DateTimeInterface $dateTime, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): UuidInterface; +} diff --git a/vendor/ramsey/uuid/src/UuidInterface.php b/vendor/ramsey/uuid/src/UuidInterface.php new file mode 100644 index 0000000..f22eb0f --- /dev/null +++ b/vendor/ramsey/uuid/src/UuidInterface.php @@ -0,0 +1,99 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +use JsonSerializable; +use Ramsey\Uuid\Fields\FieldsInterface; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Serializable; + +/** + * A UUID is a universally unique identifier adhering to an agreed-upon + * representation format and standard for generation + * + * @psalm-immutable + */ +interface UuidInterface extends + DeprecatedUuidInterface, + JsonSerializable, + Serializable +{ + /** + * Returns -1, 0, or 1 if the UUID is less than, equal to, or greater than + * the other 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 The UUID to compare + * + * @return int -1, 0, or 1 if the UUID is less than, equal to, or greater than $other + */ + public function compareTo(UuidInterface $other): int; + + /** + * Returns true if the UUID is equal to the provided 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 the UUID. + * + * @param object|null $other An object to test for equality with this UUID + * + * @return bool True if the other object is equal to this UUID + */ + public function equals(?object $other): bool; + + /** + * Returns the binary string representation of the UUID + * + * @psalm-return non-empty-string + */ + public function getBytes(): string; + + /** + * Returns the fields that comprise this UUID + */ + public function getFields(): FieldsInterface; + + /** + * Returns the hexadecimal representation of the UUID + */ + public function getHex(): Hexadecimal; + + /** + * Returns the integer representation of the UUID + */ + public function getInteger(): IntegerObject; + + /** + * Returns the string standard representation of the UUID + * + * @psalm-return non-empty-string + */ + public function toString(): string; + + /** + * Casts the UUID to the string standard representation + * + * @psalm-return non-empty-string + */ + public function __toString(): string; +} diff --git a/vendor/ramsey/uuid/src/Validator/GenericValidator.php b/vendor/ramsey/uuid/src/Validator/GenericValidator.php new file mode 100644 index 0000000..fd60955 --- /dev/null +++ b/vendor/ramsey/uuid/src/Validator/GenericValidator.php @@ -0,0 +1,50 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Validator; + +use Ramsey\Uuid\Uuid; + +use function preg_match; +use function str_replace; + +/** + * GenericValidator validates strings as UUIDs of any variant + * + * @psalm-immutable + */ +final class GenericValidator implements ValidatorInterface +{ + /** + * Regular expression pattern for matching a UUID of any variant. + */ + private const VALID_PATTERN = '\A[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}\z'; + + /** + * @psalm-return non-empty-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function getPattern(): string + { + return self::VALID_PATTERN; + } + + public function validate(string $uuid): bool + { + $uuid = str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid); + + return $uuid === Uuid::NIL || preg_match('/' . self::VALID_PATTERN . '/Dms', $uuid); + } +} diff --git a/vendor/ramsey/uuid/src/Validator/ValidatorInterface.php b/vendor/ramsey/uuid/src/Validator/ValidatorInterface.php new file mode 100644 index 0000000..3d4bd6f --- /dev/null +++ b/vendor/ramsey/uuid/src/Validator/ValidatorInterface.php @@ -0,0 +1,41 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Validator; + +/** + * A validator validates a string as a proper UUID + * + * @psalm-immutable + */ +interface ValidatorInterface +{ + /** + * Returns the regular expression pattern used by this validator + * + * @return string The regular expression pattern this validator uses + * + * @psalm-return non-empty-string + */ + public function getPattern(): string; + + /** + * Returns true if the provided string represents a UUID + * + * @param string $uuid The string to validate as a UUID + * + * @return bool True if the string is a valid UUID, false otherwise + */ + public function validate(string $uuid): bool; +} diff --git a/vendor/ramsey/uuid/src/functions.php b/vendor/ramsey/uuid/src/functions.php new file mode 100644 index 0000000..f5df148 --- /dev/null +++ b/vendor/ramsey/uuid/src/functions.php @@ -0,0 +1,123 @@ + + * @license http://opensource.org/licenses/MIT MIT + * phpcs:disable Squiz.Functions.GlobalFunction + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid; + +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; + +/** + * Returns a version 1 (time-based) UUID from a host ID, sequence number, + * and the current time + * + * @param Hexadecimal|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 $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 non-empty-string Version 1 UUID as a string + */ +function v1($node = null, ?int $clockSeq = null): string +{ + return Uuid::uuid1($node, $clockSeq)->toString(); +} + +/** + * Returns a version 2 (DCE Security) UUID from a local domain, local + * identifier, host ID, clock sequence, and the current time + * + * @param int $localDomain The local domain to use when generating bytes, + * according to DCE Security + * @param IntegerObject|null $localIdentifier The local identifier for the + * given domain; this may be a UID or GID on POSIX systems, if the local + * domain is person or group, or it may be a site-defined identifier + * if the local domain is org + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 non-empty-string Version 2 UUID as a string + */ +function v2( + int $localDomain, + ?IntegerObject $localIdentifier = null, + ?Hexadecimal $node = null, + ?int $clockSeq = null +): string { + return Uuid::uuid2($localDomain, $localIdentifier, $node, $clockSeq)->toString(); +} + +/** + * Returns a version 3 (name-based) UUID based on the MD5 hash of a + * namespace ID and a name + * + * @param string|UuidInterface $ns The namespace (must be a valid UUID) + * + * @return non-empty-string Version 3 UUID as a string + * + * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, + * but under constant factory setups, this method operates in functionally pure manners + */ +function v3($ns, string $name): string +{ + return Uuid::uuid3($ns, $name)->toString(); +} + +/** + * Returns a version 4 (random) UUID + * + * @return non-empty-string Version 4 UUID as a string + */ +function v4(): string +{ + return Uuid::uuid4()->toString(); +} + +/** + * Returns a version 5 (name-based) UUID based on the SHA-1 hash of a + * namespace ID and a name + * + * @param string|UuidInterface $ns The namespace (must be a valid UUID) + * + * @return non-empty-string Version 5 UUID as a string + * + * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, + * but under constant factory setups, this method operates in functionally pure manners + */ +function v5($ns, string $name): string +{ + return Uuid::uuid5($ns, $name)->toString(); +} + +/** + * Returns a version 6 (ordered-time) UUID from a host ID, sequence number, + * and the current time + * + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 non-empty-string Version 6 UUID as a string + */ +function v6(?Hexadecimal $node = null, ?int $clockSeq = null): string +{ + return Uuid::uuid6($node, $clockSeq)->toString(); +} diff --git a/vendor/spatie/backtrace/.php-cs-fixer.dist.php b/vendor/spatie/backtrace/.php-cs-fixer.dist.php new file mode 100644 index 0000000..3de28fd --- /dev/null +++ b/vendor/spatie/backtrace/.php-cs-fixer.dist.php @@ -0,0 +1,40 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'no_unused_imports' => true, + 'not_operator_with_successor_space' => true, + 'trailing_comma_in_multiline' => true, + 'phpdoc_scalar' => true, + 'unary_operator_spaces' => true, + 'binary_operator_spaces' => true, + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], + ], + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_var_without_name' => true, + 'class_attributes_separation' => [ + 'elements' => [ + 'method' => 'one', + ], + ], + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + 'keep_multiple_spaces_after_comma' => true, + ], + 'single_trait_insert_per_statement' => true, + ]) + ->setFinder($finder); diff --git a/vendor/spatie/backtrace/CHANGELOG.md b/vendor/spatie/backtrace/CHANGELOG.md new file mode 100644 index 0000000..7f5c9dc --- /dev/null +++ b/vendor/spatie/backtrace/CHANGELOG.md @@ -0,0 +1,23 @@ +# Changelog + +All notable changes to `backtrace` will be documented in this file + +## 1.2.1 - 2021-11-09 + +- Add a return typehint (#4) + +## 1.2.0 - 2021-05-19 + +- add `firstApplicationFrameIndex` + +## 1.1.0 - 2021-01-29 + +- add `snippetProperties` + +## 1.0.1 - 2021-01-27 + +- add support for PHP 7.3 + +## 1.0.0 - 2020-11-24 + +- initial release diff --git a/vendor/spatie/backtrace/LICENSE.md b/vendor/spatie/backtrace/LICENSE.md new file mode 100644 index 0000000..59e5ec5 --- /dev/null +++ b/vendor/spatie/backtrace/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Spatie bvba + +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/spatie/backtrace/README.md b/vendor/spatie/backtrace/README.md new file mode 100644 index 0000000..9df948e --- /dev/null +++ b/vendor/spatie/backtrace/README.md @@ -0,0 +1,157 @@ +# A better PHP backtrace + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/backtrace.svg?style=flat-square)](https://packagist.org/packages/spatie/backtrace) +![Tests](https://github.com/spatie/backtrace/workflows/Tests/badge.svg) +[![Total Downloads](https://img.shields.io/packagist/dt/spatie/backtrace.svg?style=flat-square)](https://packagist.org/packages/spatie/backtrace) + +To get the backtrace in PHP you can use the `debug_backtrace` function. By default, it can be hard to work with. The +reported function name for a frame is skewed: it belongs to the previous frame. Also, options need to be passed using a bitmask. + +This package provides a better way than `debug_backtrace` to work with a back trace. Here's an example: + +```php +// returns an array with `Spatie\Backtrace\Frame` instances +$frames = Spatie\Backtrace\Backtrace::create()->frames(); + +$firstFrame = $frames[0]; + +$firstFrame->file; // returns the file name +$firstFrame->lineNumber; // returns the line number +$firstFrame->class; // returns the class name +``` + +## Support us + +[](https://spatie.be/github-ad-click/backtrace) + +We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can +support us by [buying one of our paid products](https://spatie.be/open-source/support-us). + +We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. +You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards +on [our virtual postcard wall](https://spatie.be/open-source/postcards). + +## Installation + +You can install the package via composer: + +```bash +composer require spatie/backtrace +``` + +## Usage + +This is how you can create a backtrace instance: + +```php +$backtrace = Spatie\Backtrace\Backtrace::create(); +``` + +### Getting the frames + +To get all the frames you can call `frames`. + +```php +$frames = $backtrace->frames(); // contains an array with `Spatie\Backtrace\Frame` instances +``` + +A `Spatie\Backtrace\Frame` has these properties: + +- `file`: the name of the file +- `lineNumber`: the line number +- `arguments`: the arguments used for this frame. Will be `null` if `withArguments` was not used. +- `class`: the class name for this frame. Will be `null` if the frame concerns a function. +- `method`: the method used in this frame +- `applicationFrame`: contains `true` is this frame belongs to your application, and `false` if it belongs to a file in + the vendor directory + +### Collecting arguments + +For performance reasons, the frames of the back trace will not contain the arguments of the called functions. If you +want to add those use the `withArguments` method. + +```php +$backtrace = Spatie\Backtrace\Backtrace::create()->withArguments(); +``` + +### Setting the application path + +You can use the `applicationPath` to pass the base path of your app. This value will be used to determine whether a +frame is an application frame, or a vendor frame. Here's an example using a Laravel specific function. + +```php +$backtrace = Spatie\Backtrace\Backtrace::create()->applicationPath(base_path()); +``` + +### Getting a certain part of a trace + +If you only want to have the frames starting from a particular frame in the backtrace you can use +the `startingFromFrame` method: + +```php +use Spatie\Backtrace\Backtrace; +use Spatie\Backtrace\Frame; + +$frames = Backtrace::create() + ->startingFromFrame(function (Frame $frame) { + return $frame->class === MyClass::class; + }) + ->frames(); +``` + +With this code, all frames before the frame that concerns `MyClass` will have been filtered out. + +Alternatively, you can use the `offSet` method, which will skip the given number of frames. In this example the first 2 frames will not end up in `$frames`. + +```php +$frames = Spatie\Backtrace\Backtrace::create() + ->offset(2) + ->frames(); +``` + +### Limiting the number of frames + +To only get a specific number of frames use the `limit` function. In this example, we'll only get the first two frames. + +```php +$frames = Spatie\Backtrace\Backtrace::create() + ->limit(2) + ->frames(); +``` + +### Getting a backtrace for a throwable + +Here's how you can get a backtrace for a throwable. + +```php +$frames = Spatie\Backtrace\Backtrace::createForThrowable($throwable) +``` + +Because we will use the backtrace that is already available the throwable, the frames will always contain the arguments used. + +## Testing + +``` bash +composer test +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. + +## Security Vulnerabilities + +Please review [our security policy](../../security/policy) on how to report security vulnerabilities. + +## Credits + +- [Freek Van de Herten](https://github.com/freekmurze) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/vendor/spatie/backtrace/composer.json b/vendor/spatie/backtrace/composer.json new file mode 100644 index 0000000..2c53834 --- /dev/null +++ b/vendor/spatie/backtrace/composer.json @@ -0,0 +1,57 @@ +{ + "name": "spatie/backtrace", + "description": "A better backtrace", + "keywords": [ + "spatie", + "backtrace" + ], + "homepage": "https://github.com/spatie/backtrace", + "license": "MIT", + "authors": [ + { + "name": "Freek Van de Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "require": { + "php": "^7.3|^8.0" + }, + "require-dev": { + "ext-json": "*", + "phpunit/phpunit": "^9.3", + "symfony/var-dumper": "^5.1" + }, + "autoload": { + "psr-4": { + "Spatie\\Backtrace\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Spatie\\Backtrace\\Tests\\": "tests" + } + }, + "scripts": { + "psalm": "vendor/bin/psalm", + "test": "vendor/bin/phpunit", + "test-coverage": "vendor/bin/phpunit --coverage-html coverage", + "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes" + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/spatie" + }, + { + "type": "other", + "url": "https://spatie.be/open-source/support-us" + } + ] +} diff --git a/vendor/spatie/backtrace/src/Backtrace.php b/vendor/spatie/backtrace/src/Backtrace.php new file mode 100644 index 0000000..c900731 --- /dev/null +++ b/vendor/spatie/backtrace/src/Backtrace.php @@ -0,0 +1,219 @@ +forThrowable($throwable); + } + + protected function forThrowable(Throwable $throwable): self + { + $this->throwable = $throwable; + + return $this; + } + + public function withArguments(): self + { + $this->withArguments = true; + + return $this; + } + + public function withObject(): self + { + $this->withObject = true; + + return $this; + } + + public function applicationPath(string $applicationPath): self + { + $this->applicationPath = $applicationPath; + + return $this; + } + + public function offset(int $offset): self + { + $this->offset = $offset; + + return $this; + } + + public function limit(int $limit): self + { + $this->limit = $limit; + + return $this; + } + + public function startingFromFrame(Closure $startingFromFrameClosure) + { + $this->startingFromFrameClosure = $startingFromFrameClosure; + + return $this; + } + + /** + * @return \Spatie\Backtrace\Frame[] + */ + public function frames(): array + { + $rawFrames = $this->getRawFrames(); + + return $this->toFrameObjects($rawFrames); + } + + public function firstApplicationFrameIndex(): ?int + { + foreach ($this->frames() as $index => $frame) { + if ($frame->applicationFrame) { + return $index; + } + } + + return null; + } + + protected function getRawFrames(): array + { + if ($this->throwable) { + return $this->throwable->getTrace(); + } + + $options = null; + + if (! $this->withArguments) { + $options = $options | DEBUG_BACKTRACE_IGNORE_ARGS; + } + + if ($this->withObject()) { + $options = $options | DEBUG_BACKTRACE_PROVIDE_OBJECT; + } + + $limit = $this->limit; + + if ($limit !== 0) { + $limit += 3; + } + + return debug_backtrace($options, $limit); + } + + /** + * @return \Spatie\Backtrace\Frame[] + */ + protected function toFrameObjects(array $rawFrames): array + { + $currentFile = $this->throwable ? $this->throwable->getFile() : ''; + $currentLine = $this->throwable ? $this->throwable->getLine() : 0; + + $frames = []; + + foreach ($rawFrames as $rawFrame) { + $frames[] = new Frame( + $currentFile, + $currentLine, + $rawFrame['args'] ?? null, + $rawFrame['function'] ?? null, + $rawFrame['class'] ?? null, + $this->isApplicationFrame($currentFile) + ); + + $currentFile = $rawFrame['file'] ?? 'unknown'; + $currentLine = $rawFrame['line'] ?? 0; + } + + $frames[] = new Frame( + $currentFile, + $currentLine, + [], + '[top]' + ); + + $frames = $this->removeBacktracePackageFrames($frames); + + if ($closure = $this->startingFromFrameClosure) { + $frames = $this->startAtFrameFromClosure($frames, $closure); + } + $frames = array_slice($frames, $this->offset, $this->limit === 0 ? PHP_INT_MAX : $this->limit); + + return array_values($frames); + } + + protected function isApplicationFrame(string $frameFilename): bool + { + $relativeFile = str_replace('\\', DIRECTORY_SEPARATOR, $frameFilename); + + if (! empty($this->applicationPath)) { + $relativeFile = array_reverse(explode($this->applicationPath ?? '', $frameFilename, 2))[0]; + } + + if (strpos($relativeFile, DIRECTORY_SEPARATOR . 'vendor') === 0) { + return false; + } + + return true; + } + + protected function removeBacktracePackageFrames(array $frames): array + { + return $this->startAtFrameFromClosure($frames, function (Frame $frame) { + return $frame->class !== static::class; + }); + } + + /** + * @param \Spatie\Backtrace\Frame[] $frames + * @param \Closure $closure + * + * @return array + */ + protected function startAtFrameFromClosure(array $frames, Closure $closure): array + { + foreach ($frames as $i => $frame) { + $foundStartingFrame = $closure($frame); + + if ($foundStartingFrame) { + return $frames; + } + + unset($frames[$i]); + } + + return $frames; + } +} diff --git a/vendor/spatie/backtrace/src/CodeSnippet.php b/vendor/spatie/backtrace/src/CodeSnippet.php new file mode 100644 index 0000000..0fea5ff --- /dev/null +++ b/vendor/spatie/backtrace/src/CodeSnippet.php @@ -0,0 +1,72 @@ +surroundingLine = $surroundingLine; + + return $this; + } + + public function snippetLineCount(int $snippetLineCount): self + { + $this->snippetLineCount = $snippetLineCount; + + return $this; + } + + public function get(string $fileName): array + { + if (! file_exists($fileName)) { + return []; + } + + try { + $file = new File($fileName); + + [$startLineNumber, $endLineNumber] = $this->getBounds($file->numberOfLines()); + + $code = []; + + $line = $file->getLine($startLineNumber); + + $currentLineNumber = $startLineNumber; + + while ($currentLineNumber <= $endLineNumber) { + $code[$currentLineNumber] = rtrim(substr($line, 0, 250)); + + $line = $file->getNextLine(); + $currentLineNumber++; + } + + return $code; + } catch (RuntimeException $exception) { + return []; + } + } + + protected function getBounds(int $totalNumberOfLineInFile): array + { + $startLine = max($this->surroundingLine - floor($this->snippetLineCount / 2), 1); + + $endLine = $startLine + ($this->snippetLineCount - 1); + + if ($endLine > $totalNumberOfLineInFile) { + $endLine = $totalNumberOfLineInFile; + $startLine = max($endLine - ($this->snippetLineCount - 1), 1); + } + + return [$startLine, $endLine]; + } +} diff --git a/vendor/spatie/backtrace/src/File.php b/vendor/spatie/backtrace/src/File.php new file mode 100644 index 0000000..6f1bbd2 --- /dev/null +++ b/vendor/spatie/backtrace/src/File.php @@ -0,0 +1,41 @@ +file = new SplFileObject($path); + } + + public function numberOfLines(): int + { + $this->file->seek(PHP_INT_MAX); + + return $this->file->key() + 1; + } + + public function getLine(int $lineNumber = null): string + { + if (is_null($lineNumber)) { + return $this->getNextLine(); + } + + $this->file->seek($lineNumber - 1); + + return $this->file->current(); + } + + public function getNextLine(): string + { + $this->file->next(); + + return $this->file->current(); + } +} diff --git a/vendor/spatie/backtrace/src/Frame.php b/vendor/spatie/backtrace/src/Frame.php new file mode 100644 index 0000000..2e75f9c --- /dev/null +++ b/vendor/spatie/backtrace/src/Frame.php @@ -0,0 +1,65 @@ +file = $file; + + $this->lineNumber = $lineNumber; + + $this->arguments = $arguments; + + $this->method = $method; + + $this->class = $class; + + $this->applicationFrame = $isApplicationFrame; + } + + public function getSnippet(int $lineCount): array + { + return (new CodeSnippet()) + ->surroundingLine($this->lineNumber) + ->snippetLineCount($lineCount) + ->get($this->file); + } + + public function getSnippetProperties(int $lineCount): array + { + $snippet = $this->getSnippet($lineCount); + + return array_map(function (int $lineNumber) use ($snippet) { + return [ + 'line_number' => $lineNumber, + 'text' => $snippet[$lineNumber], + ]; + }, array_keys($snippet)); + } +} diff --git a/vendor/spatie/macroable/CHANGELOG.md b/vendor/spatie/macroable/CHANGELOG.md new file mode 100644 index 0000000..e3f4e24 --- /dev/null +++ b/vendor/spatie/macroable/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +All notable changes to `macroable` will be documented in this file + +## 1.0.1 - 2020-11-03 + +- add support for PHP 8.0 +- drop support for PHP 7.1 and below + +## 1.0.0 - 2017-09-16 + +- initial release diff --git a/vendor/spatie/macroable/CONTRIBUTING.md b/vendor/spatie/macroable/CONTRIBUTING.md new file mode 100644 index 0000000..4da74e3 --- /dev/null +++ b/vendor/spatie/macroable/CONTRIBUTING.md @@ -0,0 +1,55 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +Please read and understand the contribution guide before creating an issue or pull request. + +## Etiquette + +This project is open source, and as such, the maintainers give their free time to build and maintain the source code +held within. They make the code freely available in the hope that it will be of use to other developers. It would be +extremely unfair for them to suffer abuse or anger for their hard work. + +Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the +world that developers are civilized and selfless people. + +It's the duty of the maintainer to ensure that all submissions to the project are of sufficient +quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. + +## Viability + +When requesting or submitting new features, first consider whether it might be useful to others. Open +source projects are used by many developers, who may have entirely different needs to your own. Think about +whether or not your feature is likely to be used by other users of the project. + +## Procedure + +Before filing an issue: + +- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. +- Check to make sure your feature suggestion isn't already present within the project. +- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. +- Check the pull requests tab to ensure that the feature isn't already in progress. + +Before submitting a pull request: + +- Check the codebase to ensure that your feature doesn't already exist. +- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. + +## Requirements + +If the project maintainer has any additional requirements, you will find them listed here. + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. + +- **One pull request per feature** - If you want to do more than one thing, send multiple 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](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. + +**Happy coding**! diff --git a/vendor/spatie/macroable/LICENSE.md b/vendor/spatie/macroable/LICENSE.md new file mode 100644 index 0000000..59e5ec5 --- /dev/null +++ b/vendor/spatie/macroable/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Spatie bvba + +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/spatie/macroable/README.md b/vendor/spatie/macroable/README.md new file mode 100644 index 0000000..4e7012d --- /dev/null +++ b/vendor/spatie/macroable/README.md @@ -0,0 +1,135 @@ +# A trait to dynamically add methods to a class + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/macroable.svg?style=flat-square)](https://packagist.org/packages/spatie/macroable) +![run-tests](https://github.com/spatie/macroable/workflows/run-tests/badge.svg) +[![Total Downloads](https://img.shields.io/packagist/dt/spatie/macroable.svg?style=flat-square)](https://packagist.org/packages/spatie/macroable) + +This package provides a trait that, when applied to a class, makes it possible to add methods to that class at runtime. + +Here's a quick example: + +```php +$myClass = new class() { + use Spatie\Macroable\Macroable; +}; + +$myClass::macro('concatenate', function(... $strings) { + return implode('-', $strings); +}); + +$myClass->concatenate('one', 'two', 'three'); // returns 'one-two-three' +``` + +The idea of a macroable trait and the implementation is taken from [the `macroable` trait](https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Traits/Macroable.php) of the [Laravel framework](https://laravel.com). + +## Support us + +[](https://spatie.be/github-ad-click/macroable) + +We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). + +We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). + +## Installation + +You can install the package via composer: + +```bash +composer require spatie/macroable +``` + +## Usage + +You can add a new method to a class using `macro`: + +```php +$macroableClass = new class() { + use Spatie\Macroable\Macroable; +}; + +$macroableClass::macro('concatenate', function(... $strings) { + return implode('-', $strings); +}; + +$macroableClass->concatenate('one', 'two', 'three'); // returns 'one-two-three' +``` + +Callables passed to the `macro` function will be bound to the `class` + +```php +$macroableClass = new class() { + + protected $name = 'myName'; + + use Spatie\Macroable\Macroable; +}; + +$macroableClass::macro('getName', function() { + return $this->name; +}; + +$macroableClass->getName(); // returns 'myName' +``` + +You can also add multiple methods in one go by using a mixin class. A mixin class contains methods that return callables. Each method from the mixin will be registered on the macroable class. + +```php +$mixin = new class() { + public function mixinMethod() + { + return function() { + return 'mixinMethod'; + }; + } + + public function anotherMixinMethod() + { + return function() { + return 'anotherMixinMethod'; + }; + } +}; + +$macroableClass->mixin($mixin); + +$macroableClass->mixinMethod() // returns 'mixinMethod'; + +$macroableClass->anotherMixinMethod() // returns 'anotherMixinMethod'; +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Testing + +``` bash +composer test +``` + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. + +## Security + +If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker. + +## Postcardware + +You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. + +Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium. + +We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards). + +## Credits + +- [Freek Van der Herten](https://github.com/freekmurze) +- [All Contributors](../../contributors) + +Idea and code is taken from [the `macroable` trait](https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Traits/Macroable.php) of the [Laravel framework](https://laravel.com). + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/vendor/spatie/macroable/composer.json b/vendor/spatie/macroable/composer.json new file mode 100644 index 0000000..ff6d4ba --- /dev/null +++ b/vendor/spatie/macroable/composer.json @@ -0,0 +1,40 @@ +{ + "name": "spatie/macroable", + "description": "A trait to dynamically add methods to a class", + "keywords": [ + "spatie", + "macroable" + ], + "homepage": "https://github.com/spatie/macroable", + "license": "MIT", + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "require": { + "php": "^7.2|^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.0|^9.3" + }, + "autoload": { + "psr-4": { + "Spatie\\Macroable\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Spatie\\Macroable\\Test\\": "tests" + } + }, + "scripts": { + "test": "vendor/bin/phpunit" + }, + "config": { + "sort-packages": true + } +} diff --git a/vendor/spatie/macroable/config/.gitkeep b/vendor/spatie/macroable/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/spatie/macroable/src/Macroable.php b/vendor/spatie/macroable/src/Macroable.php new file mode 100644 index 0000000..5469030 --- /dev/null +++ b/vendor/spatie/macroable/src/Macroable.php @@ -0,0 +1,77 @@ +getMethods( + ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED + ); + + foreach ($methods as $method) { + $method->setAccessible(true); + + static::macro($method->name, $method->invoke($mixin)); + } + } + + public static function hasMacro(string $name): bool + { + return isset(static::$macros[$name]); + } + + public static function __callStatic($method, $parameters) + { + if (! static::hasMacro($method)) { + throw new BadMethodCallException("Method {$method} does not exist."); + } + + $macro = static::$macros[$method]; + + if ($macro instanceof Closure) { + return call_user_func_array(Closure::bind($macro, null, static::class), $parameters); + } + + return call_user_func_array($macro, $parameters); + } + + public function __call($method, $parameters) + { + if (! static::hasMacro($method)) { + throw new BadMethodCallException("Method {$method} does not exist."); + } + + $macro = static::$macros[$method]; + + if ($macro instanceof Closure) { + return call_user_func_array($macro->bindTo($this, static::class), $parameters); + } + + return call_user_func_array($macro, $parameters); + } +} diff --git a/vendor/spatie/ray/.php_cs.dist.php b/vendor/spatie/ray/.php_cs.dist.php new file mode 100644 index 0000000..8d8a790 --- /dev/null +++ b/vendor/spatie/ray/.php_cs.dist.php @@ -0,0 +1,40 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PSR12' => true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'no_unused_imports' => true, + 'not_operator_with_successor_space' => true, + 'trailing_comma_in_multiline' => true, + 'phpdoc_scalar' => true, + 'unary_operator_spaces' => true, + 'binary_operator_spaces' => true, + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], + ], + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_var_without_name' => true, + 'class_attributes_separation' => [ + 'elements' => [ + 'method' => 'one', + ], + ], + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + 'keep_multiple_spaces_after_comma' => true, + ], + 'single_trait_insert_per_statement' => true, + ]) + ->setFinder($finder); diff --git a/vendor/spatie/ray/CHANGELOG.md b/vendor/spatie/ray/CHANGELOG.md new file mode 100644 index 0000000..eb0cb74 --- /dev/null +++ b/vendor/spatie/ray/CHANGELOG.md @@ -0,0 +1,396 @@ +# Changelog + +All notable changes to `ray` will be documented in this file + +## 1.33.1 - 2022-01-17 + +## What's Changed + +- Ignore docs folder on package install by @fschirinzi in https://github.com/spatie/ray/pull/625 + +## New Contributors + +- @fschirinzi made their first contribution in https://github.com/spatie/ray/pull/625 + +**Full Changelog**: https://github.com/spatie/ray/compare/1.33.0...1.33.1 + +## 1.33.0 - 2022-01-13 + +1.33.0 + +- add support for screen colors +- add support for project names +- send hostname along with request + +## 1.33.0 - 2022-01-13 + +- add support for screen colors +- add support for project names +- send hostname along with request + +## 1.32.3 - 2022-01-09 + +- allow Laravel 9 + +## 1.32.2 - 2021-12-20 + +- allow symfony 6 + +## 1.32.1 - 2021-11-30 + +- fix deprecation warning in PHP 8.1 + +## 1.32.0 - 2021-11-26 + +## What's Changed + +- Add separator payload by @freekmurze in https://github.com/spatie/ray/pull/599 + +**Full Changelog**: https://github.com/spatie/ray/compare/1.31.0...1.32.0 + +## 1.31.0 - 2021-11-17 + +## What's Changed + +- Docs for duplicate queries logging by @masterix21 in https://github.com/spatie/ray/pull/560 +- Add context to ApplicationLog by @keithbrink in https://github.com/spatie/ray/pull/562 + +## New Contributors + +- @masterix21 made their first contribution in https://github.com/spatie/ray/pull/560 +- @keithbrink made their first contribution in https://github.com/spatie/ray/pull/562 + +**Full Changelog**: https://github.com/spatie/ray/compare/1.30.4...1.31.0 + +## 1.30.4 - 2021-11-11 + +## What's Changed + +- Point to "servers" instead of singular "server" by @jmslbam in https://github.com/spatie/ray/pull/583 +- Fix for sending "value" (by @freekmurze) + +**Full Changelog**: https://github.com/spatie/ray/compare/1.30.3...1.30.4 + +## 1.30.3 - 2021-10-08 + +- Bug/567 global functions (#573) + +## 1.30.2 - 2021-09-10 + +- align carbon call argument type with carbon payload (#556) + +## 1.30.1 - 2021-09-07 + +- support PHP 8.1 + +## 1.30.0 - 2021-08-20 + +- add `catch` method + +## 1.29.2 - 2021-08-15 + +- revert curl check + +## 1.29.1 - 2021-08-14 + +- fix curl check + +## 1.29.0 - 2021-08-02 + +- add `label` method + +## 1.28.0 - 2021-07-04 + +- add support for base64-encoded images (#499) + +## 1.27.1 - 2021-06-24 + +- remove typehint to allow override + +## 1.27.0 - 2021-06-23 + +- add `once()` (#481) + +## 1.26.0 - 2021-06-10 + +- add rate limiter + +## 1.25.0 - 2021-06-07 + +- add `if` method + +## 1.24.0 - 2021-06-04 + +- add limit method (#464) + +## 1.23.0 - 2021-05-29 + +- add `text` method (#460) + +## 1.22.1 - 2021-04-28 + +- allow Throwables to be logged + +## 1.22.0 - 2021-04-28 + +- access named counter values (#437) + +## 1.21.4 - 2021-04-17 + +- color exceptions red by default + +## 1.21.3 - 2021-04-14 + +- allow spatie/macroable v2 [#426](https://github.com/spatie/ray/pull/426) + +## 1.21.2 - 2021-03-04 + +- fix hostname for other ray packages + +## 1.21.1 - 2021-03-03 + +- do not require hostname + +## 1.21.0 - 2021-03-03 + +- add `hostname` in the origin section of a payload + +## 1.20.1 - 2021-02-26 + +- fix config loading priorities in other packages + +## 1.20.0 - 2021-02-22 + +- add `exception` method + +## 1.19.5 - 2021-02-17 + +- allow instances of `CarbonInterface` to be used for `CarbonPayload` (#316) + +## 1.19.4 - 2021-02-11 + +- fix enabled status (#301) + +## 1.19.3 - 2021-02-09 + +- fix Client cache fingerprint initialization (#292) + +## 1.19.2 - 2021-02-09 + +- add curl throttling after failed connection (#286) + +## 1.19.1 - 2021-02-08 + +- allow symfony/stopwatch 4.0 (#284) + +## 1.19.0 - 2021-02-03 + +- send XML payloads (#272) + +## 1.18.0 - 2021-02-03 + +- add `enable` and `disable` methods + +## 1.17.4 - 2021-02-03 + +- fix: remote_path/local_path replacements (#269) + +## 1.17.3 - 2021-02-02 + +- use http v1.1 instead of 1.0 (#267) + +## 1.17.2 - 2021-02-02 + +- cache config file + +## 1.17.1 - 2021-01-27 + +- add support for PHP 7.3 + +## 1.17.0 - 2021-01-25 + +- add `showApp` and `hideApp` + +## 1.16.0 - 2021-01-22 + +- add `phpinfo` method + +## 1.15.0 - 2021-01-22 + +- add `table` method + +## 1.14.1 - 2021-01-22 + +- fix bug when `remote_path` is also in `filePath` (#227) + +## 1.14.0 - 2021-01-20 + +- Add support for CraftRay + +## 1.13.0 - 2021-01-18 + +- the package will now select the best payload type when passing something to `ray()` +- added `html` method +- added `NullPayload` +- added `BoolPayload` + +## 1.12.0 - 2021-01-18 + +- add `carbon` + +## 1.11.1 - 2021-01-17 + +- lower deps + +## 1.11.0 - 2021-01-15 + +- add `image()` + +## 1.10.0 - 2021-01-15 + +- add `clearAll` + +## 1.9.2 - 2021-01-15 + +- fix bugs around settings + +## 1.9.1 - 2021-01-15 + +- improve helper functions + +## 1.9.0 - 2021-01-15 + +- add `count` + +## 1.8.0 - 2021-01-14 + +- add a check for YiiRay's instance + +## 1.7.2 - 2021-01-13 + +- when passing `null`, let argument convertor return `null` + +## 1.7.1 - 2021-01-13 + +- improve return type of ray function + +## 1.7.0 - 2021-01-13 + +- support multiple arguments to `toJson()` and `json()` (#148) + +## 1.6.1 - 2021-01-13 + +- prevent possible memory leak (#143) + +## 1.6.0 - 2021-01-13 + +- add `file` function (#134) + +## 1.5.10 - 2021-01-13 + +- allow better compatibility with WordPress + +## 1.5.9 - 2021-01-13 + +- ignore package version errors + +## 1.5.8 - 2021-01-13 + +- ignore package check errors + +## 1.5.7 - 2021-01-13 + +- remove unneeded symfony/console dependency + +## 1.5.6 - 2021-01-13 + +- allow lower dependencies + +## 1.5.5 - 2021-01-11 + +- split origin factory in overridable functions + +## 1.5.4 - 2021-01-11 + +- support WordPressRay + +## 1.5.3 - 2021-01-10 + +- fix for traces of WordPress + +## 1.5.2 - 2021-01-10 + +- colorize app frames + +## 1.5.1 - 2021-01-10 + +- polish json functions + +## 1.5.0 - 2021-01-09 + +- add `json` function + +## 1.4.0 - 2021-01-09 + +- add `rd` function + +## 1.3.7 - 2021-01-09 + +- add `vendor_frame` attribute to frames + +## 1.3.6 - 2021-01-09 + +- allow older version of uuid package + +## 1.3.5 - 2021-01-09 + +- fix search for `$indexOfRay` to include calls from the parent directory (#80) + +## 1.3.4 - 2021-01-08 + +- prevent warning if `open_basedir` is enabled + +## 1.3.3 - 2021-01-08 + +- do not require Composer 2 + +## 1.3.2 - 2021-01-08 + +- prevent ray from blowing up when there is no config file + +## 1.3.1 - 2021-01-08 + +- do not blow up when the Ray app is not running + +## 1.3.0 - 2021-01-08 + +- add support for `remote_path` and `local_path` config values + +## 1.2.0 - 2021-01-08 + +- add `pass` function + +## 1.1.3 - 2021-01-08 + +- prevent exception when installing in an Orchestra powered testsuite + +## 1.1.2 - 2021-01-08 + +- enforce Composer 2 requirement + +### 1.1.1 - 2021-01-08 + +- fix for repeated calls to `ray()` throwing an exception (#30) + +## 1.1.0 - 2021-01-07 + +- add `makePathOsSafe` +- fix tests + +## 1.0.1 - 2021-01-07 + +- fix default settings + +## 1.0.0 - 2021-01-07 + +- initial release diff --git a/vendor/spatie/ray/LICENSE.md b/vendor/spatie/ray/LICENSE.md new file mode 100644 index 0000000..59e5ec5 --- /dev/null +++ b/vendor/spatie/ray/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Spatie bvba + +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/spatie/ray/README.md b/vendor/spatie/ray/README.md new file mode 100644 index 0000000..96abcae --- /dev/null +++ b/vendor/spatie/ray/README.md @@ -0,0 +1,48 @@ +# Debug with Ray to fix problems faster + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/ray.svg?style=flat-square)](https://packagist.org/packages/spatie/ray) +![Tests](https://github.com/spatie/ray/workflows/Tests/badge.svg) +[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-ray.svg?style=flat-square)](https://packagist.org/packages/spatie/ray) + +This package can be installed in any PHP application to send messages to [the Ray app](https://myray.app). + +[](https://spatie.be/github-ad-click/ray) + + +The desktop app: + +- can be used in WordPress, Laravel, PHP, JavaScript function +- shows you models, mails, queries, ... IN Laravel +- helps you to debug locally or via SSH +- lets you measure performance & set breakpoints + +## Documentation + +You can find the full documentation on [our documentation site](https://spatie.be/docs/ray). + +## Testing + +```bash +composer test +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. + +## Security Vulnerabilities + +Please review [our security policy](../../security/policy) on how to report security vulnerabilities. + +## Credits + +- [Freek Van der Herten](https://github.com/freekmurze) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/vendor/spatie/ray/composer.json b/vendor/spatie/ray/composer.json new file mode 100644 index 0000000..b4748ae --- /dev/null +++ b/vendor/spatie/ray/composer.json @@ -0,0 +1,70 @@ +{ + "name": "spatie/ray", + "description": "Debug with Ray to fix problems faster", + "keywords": [ + "spatie", + "ray" + ], + "homepage": "https://github.com/spatie/ray", + "license": "MIT", + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "require": { + "php": "^7.3|^8.0", + "ext-curl": "*", + "ext-json": "*", + "ramsey/uuid": "^3.0|^4.1", + "spatie/backtrace": "^1.1", + "spatie/macroable": "^1.0|^2.0", + "symfony/stopwatch": "^4.0|^5.1|^6.0", + "symfony/var-dumper": "^4.2|^5.1|^6.0" + }, + "require-dev": { + "illuminate/support": "6.x|^8.18|^9.0", + "nesbot/carbon": "^2.43", + "phpstan/phpstan": "^0.12.92", + "phpunit/phpunit": "^9.5", + "spatie/phpunit-snapshot-assertions": "^4.2", + "spatie/test-time": "^1.2" + }, + "autoload": { + "psr-4": { + "Spatie\\Ray\\": "src" + }, + "files": [ + "src/helpers.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Spatie\\Ray\\Tests\\": "tests" + } + }, + "scripts": { + "test": "vendor/bin/phpunit", + "test-coverage": "vendor/bin/phpunit --coverage-html coverage", + "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes", + "phpstan": "vendor/bin/phpstan analyse" + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/spatie" + }, + { + "type": "other", + "url": "https://spatie.be/open-source/support-us" + } + ] +} diff --git a/vendor/spatie/ray/phpstan-baseline.neon b/vendor/spatie/ray/phpstan-baseline.neon new file mode 100644 index 0000000..f7c5980 --- /dev/null +++ b/vendor/spatie/ray/phpstan-baseline.neon @@ -0,0 +1,42 @@ +parameters: + ignoreErrors: + - + message: "#^Variable \\$curlHandle might not be defined\\.$#" + count: 2 + path: src/Client.php + + - + message: "#^Variable \\$success might not be defined\\.$#" + count: 1 + path: src/Client.php + + - + message: "#^Function base_path not found\\.$#" + count: 1 + path: src/Ray.php + + - + message: "#^Access to static property \\$container on an unknown class Yii\\.$#" + count: 2 + path: src/helpers.php + + - + message: "#^Function app not found\\.$#" + count: 1 + path: src/helpers.php + + - + message: "#^Instantiated class Spatie\\\\RayBundle\\\\Ray not found\\.$#" + count: 1 + path: src/helpers.php + + - + message: "#^Instantiated class Spatie\\\\WordPressRay\\\\Ray not found\\.$#" + count: 1 + path: src/helpers.php + + - + message: "#^Call to an undefined method Spatie\\\\Ray\\\\Tests\\\\RayTest\\:\\:sendRequest\\(\\)\\.$#" + count: 1 + path: tests/RayTest.php + diff --git a/vendor/spatie/ray/phpstan.neon.dist b/vendor/spatie/ray/phpstan.neon.dist new file mode 100644 index 0000000..992569c --- /dev/null +++ b/vendor/spatie/ray/phpstan.neon.dist @@ -0,0 +1,11 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 1 + paths: + - src + - tests + + ignoreErrors: + - '#Unsafe usage of new static\(\)#' diff --git a/vendor/spatie/ray/src/ArgumentConverter.php b/vendor/spatie/ray/src/ArgumentConverter.php new file mode 100644 index 0000000..1f7adb9 --- /dev/null +++ b/vendor/spatie/ray/src/ArgumentConverter.php @@ -0,0 +1,36 @@ +cloneVar($argument); + + return $dumper->dump($clonedArgument, true); + } +} diff --git a/vendor/spatie/ray/src/Client.php b/vendor/spatie/ray/src/Client.php new file mode 100644 index 0000000..f62687d --- /dev/null +++ b/vendor/spatie/ray/src/Client.php @@ -0,0 +1,168 @@ +fingerprint = $host . ':' . $portNumber; + + $this->portNumber = $portNumber; + + $this->host = $host; + } + + public function serverIsAvailable(): bool + { + // purge expired entries from the cache + static::$cache = array_filter(static::$cache, function ($data) { + return microtime(true) < $data[1]; + }); + + if (! isset(static::$cache[$this->fingerprint])) { + $this->performAvailabilityCheck(); + } + + return static::$cache[$this->fingerprint][0] ?? true; + } + + public function performAvailabilityCheck(): bool + { + try { + $curlHandle = $this->getCurlHandleForUrl('get', '_availability_check'); + + curl_exec($curlHandle); + + $success = curl_errno($curlHandle) === CURLE_HTTP_NOT_FOUND; + // expire the cache entry after 30 sec + $expiresAt = microtime(true) + 30.0; + + static::$cache[$this->fingerprint] = [$success, $expiresAt]; + } finally { + curl_close($curlHandle); + + return $success ?? false; + } + } + + public function send(Request $request): void + { + if (! $this->serverIsAvailable()) { + return; + } + + try { + $curlHandle = $this->getCurlHandleForUrl('get', ''); + + $curlError = null; + + curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $request->toJson()); + curl_exec($curlHandle); + + if (curl_errno($curlHandle)) { + $curlError = curl_error($curlHandle); + } + + if ($curlError) { + // do nothing for now + } + } finally { + curl_close($curlHandle); + } + } + + public function lockExists(string $lockName): bool + { + if (! $this->serverIsAvailable()) { + return false; + } + + $queryString = http_build_query([ + 'hostname' => Hostname::get(), + 'project_name' => Ray::$projectName, + ]); + + $curlHandle = $this->getCurlHandleForUrl('get', "locks/{$lockName}?{$queryString}"); + $curlError = null; + + try { + $curlResult = curl_exec($curlHandle); + + if (curl_errno($curlHandle)) { + $curlError = curl_error($curlHandle); + } + + if ($curlError) { + throw new Exception(); + } + + if (! $curlResult) { + return false; + } + + $response = json_decode($curlResult, true); + + if ($response['stop_execution'] ?? false) { + throw StopExecutionRequested::make(); + } + + return $response['active'] ?? false; + } catch (Exception $exception) { + if ($exception instanceof StopExecutionRequested) { + throw $exception; + } + } finally { + curl_close($curlHandle); + } + + return false; + } + + protected function getCurlHandleForUrl(string $method, string $url) + { + return $this->getCurlHandle($method, "http://{$this->host}:{$this->portNumber}/{$url}"); + } + + protected function getCurlHandle(string $method, string $fullUrl) + { + $curlHandle = curl_init(); + + curl_setopt($curlHandle, CURLOPT_URL, $fullUrl); + + curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array_merge([ + 'Accept: application/json', + 'Content-Type: application/json', + ])); + + curl_setopt($curlHandle, CURLOPT_USERAGENT, 'Ray 1.0'); + curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curlHandle, CURLOPT_TIMEOUT, 2); + curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, true); + curl_setopt($curlHandle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($curlHandle, CURLOPT_ENCODING, ''); + curl_setopt($curlHandle, CURLINFO_HEADER_OUT, true); + curl_setopt($curlHandle, CURLOPT_FAILONERROR, true); + + if ($method === 'post') { + curl_setopt($curlHandle, CURLOPT_POST, true); + } + + return $curlHandle; + } +} diff --git a/vendor/spatie/ray/src/Concerns/RayColors.php b/vendor/spatie/ray/src/Concerns/RayColors.php new file mode 100644 index 0000000..8bc06da --- /dev/null +++ b/vendor/spatie/ray/src/Concerns/RayColors.php @@ -0,0 +1,37 @@ +color('green'); + } + + public function orange(): self + { + return $this->color('orange'); + } + + public function red(): self + { + return $this->color('red'); + } + + public function purple(): self + { + return $this->color('purple'); + } + + public function blue(): self + { + return $this->color('blue'); + } + + public function gray(): self + { + return $this->color('gray'); + } +} diff --git a/vendor/spatie/ray/src/Concerns/RayScreenColors.php b/vendor/spatie/ray/src/Concerns/RayScreenColors.php new file mode 100644 index 0000000..abc472e --- /dev/null +++ b/vendor/spatie/ray/src/Concerns/RayScreenColors.php @@ -0,0 +1,37 @@ +screenColor('green'); + } + + public function screenOrange(): self + { + return $this->screenColor('orange'); + } + + public function screenRed(): self + { + return $this->screenColor('red'); + } + + public function screenPurple(): self + { + return $this->screenColor('purple'); + } + + public function screenBlue(): self + { + return $this->screenColor('blue'); + } + + public function screenGray(): self + { + return $this->screenColor('gray'); + } +} diff --git a/vendor/spatie/ray/src/Concerns/RaySizes.php b/vendor/spatie/ray/src/Concerns/RaySizes.php new file mode 100644 index 0000000..0c9e660 --- /dev/null +++ b/vendor/spatie/ray/src/Concerns/RaySizes.php @@ -0,0 +1,17 @@ +size('sm'); + } + + public function large(): self + { + return $this->size('lg'); + } +} diff --git a/vendor/spatie/ray/src/Concerns/RemovesRayFrames.php b/vendor/spatie/ray/src/Concerns/RemovesRayFrames.php new file mode 100644 index 0000000..42acb97 --- /dev/null +++ b/vendor/spatie/ray/src/Concerns/RemovesRayFrames.php @@ -0,0 +1,37 @@ +isRayFrame($frame); + }); + + return array_values($frames); + } + + protected function isRayFrame(Frame $frame): bool + { + foreach ($this->rayNamespaces() as $rayNamespace) { + if (substr((string)$frame->class, 0, strlen($rayNamespace)) === $rayNamespace) { + return true; + } + } + + return false; + } + + protected function rayNamespaces(): array + { + return [ + 'Spatie\Ray', + 'Spatie\LaravelRay', + 'Spatie\WordPressRay', + ]; + } +} diff --git a/vendor/spatie/ray/src/Exceptions/CouldNotConnectToRay.php b/vendor/spatie/ray/src/Exceptions/CouldNotConnectToRay.php new file mode 100644 index 0000000..28dcec6 --- /dev/null +++ b/vendor/spatie/ray/src/Exceptions/CouldNotConnectToRay.php @@ -0,0 +1,13 @@ +getFrame(); + + return new Origin( + $frame ? $frame->file : null, + $frame ? $frame->lineNumber : null, + Hostname::get() + ); + } + + /** + * @return \Spatie\Backtrace\Frame|null + */ + protected function getFrame() + { + $frames = $this->getAllFrames(); + + $indexOfRay = $this->getIndexOfRayFrame($frames); + + return $frames[$indexOfRay] ?? null; + } + + protected function getAllFrames(): array + { + $frames = Backtrace::create()->frames(); + + return array_reverse($frames, true); + } + + /** + * @param array $frames + * + * @return int|null + */ + protected function getIndexOfRayFrame(array $frames) + { + $index = $this->search(function (Frame $frame) { + if ($frame->class === Ray::class) { + return true; + } + + if ($this->startsWith($frame->file, dirname(__DIR__))) { + return true; + } + + return false; + }, $frames); + + return $index + 1; + } + + public function startsWith(string $hayStack, string $needle): bool + { + return strpos($hayStack, $needle) === 0; + } + + /** + * @param callable $callable + * @param array $items + * + * @return int|null + */ + protected function search(callable $callable, array $items) + { + foreach ($items as $key => $item) { + if ($callable($item, $key)) { + return $key; + } + } + + return null; + } +} diff --git a/vendor/spatie/ray/src/Origin/Hostname.php b/vendor/spatie/ray/src/Origin/Hostname.php new file mode 100644 index 0000000..e926081 --- /dev/null +++ b/vendor/spatie/ray/src/Origin/Hostname.php @@ -0,0 +1,18 @@ +file = $file; + + $this->lineNumber = $lineNumber; + + $this->hostname = $hostname ?? Hostname::get(); + } + + public function toArray(): array + { + return [ + 'file' => $this->file, + 'line_number' => $this->lineNumber, + 'hostname' => $this->hostname, + ]; + } + + public function fingerPrint(): string + { + return md5(print_r($this->toArray(), true)); + } +} diff --git a/vendor/spatie/ray/src/Origin/OriginFactory.php b/vendor/spatie/ray/src/Origin/OriginFactory.php new file mode 100644 index 0000000..aa2cfc1 --- /dev/null +++ b/vendor/spatie/ray/src/Origin/OriginFactory.php @@ -0,0 +1,8 @@ +getPayloads(); + } + + public static function registerPayloadFinder(callable $callable) + { + self::$payloadFinder = $callable; + } + + public function __construct(array $values) + { + $this->values = $values; + } + + public function getPayloads(): array + { + return array_map(function ($value) { + return $this->getPayload($value); + }, $this->values); + } + + protected function getPayload($value): Payload + { + if (self::$payloadFinder) { + if ($payload = (static::$payloadFinder)($value)) { + return $payload; + } + } + + if (is_bool($value)) { + return new BoolPayload($value); + } + + if (is_null($value)) { + return new NullPayload(); + } + + if ($value instanceof CarbonInterface) { + return new CarbonPayload($value); + } + + $primitiveValue = ArgumentConverter::convertToPrimitive($value); + + return new LogPayload($primitiveValue); + } +} diff --git a/vendor/spatie/ray/src/Payloads/ApplicationLogPayload.php b/vendor/spatie/ray/src/Payloads/ApplicationLogPayload.php new file mode 100644 index 0000000..315ef51 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/ApplicationLogPayload.php @@ -0,0 +1,31 @@ +value = $value; + $this->context = $context; + } + + public function getType(): string + { + return 'application_log'; + } + + public function getContent(): array + { + return [ + 'value' => $this->value, + 'context' => $this->context, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/BoolPayload.php b/vendor/spatie/ray/src/Payloads/BoolPayload.php new file mode 100644 index 0000000..fa87062 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/BoolPayload.php @@ -0,0 +1,27 @@ +bool = $bool; + } + + public function getType(): string + { + return 'custom'; + } + + public function getContent(): array + { + return [ + 'content' => $this->bool, + 'label' => 'Boolean', + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/CallerPayload.php b/vendor/spatie/ray/src/Payloads/CallerPayload.php new file mode 100644 index 0000000..da3c9dc --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/CallerPayload.php @@ -0,0 +1,42 @@ +frames = $this->removeRayFrames($frames); + } + + public function getType(): string + { + return 'caller'; + } + + public function getContent(): array + { + $frames = array_slice($this->frames, 1, 1); + + /** @var Frame $frame */ + $frame = array_values($frames)[0]; + + return [ + 'frame' => [ + 'file_name' => $this->replaceRemotePathWithLocalPath($frame->file), + 'line_number' => $frame->lineNumber, + 'class' => $frame->class, + 'method' => $frame->method, + 'vendor_frame' => ! $frame->applicationFrame, + ], + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/CarbonPayload.php b/vendor/spatie/ray/src/Payloads/CarbonPayload.php new file mode 100644 index 0000000..3482de5 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/CarbonPayload.php @@ -0,0 +1,35 @@ +carbon = $carbon; + + $this->format = $format; + } + + public function getType(): string + { + return 'carbon'; + } + + public function getContent(): array + { + return [ + 'formatted' => $this->carbon ? $this->carbon->format($this->format) : null, + 'timestamp' => $this->carbon ? $this->carbon->timestamp : null, + 'timezone' => $this->carbon ? $this->carbon->timezone->getName() : null, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/ClearAllPayload.php b/vendor/spatie/ray/src/Payloads/ClearAllPayload.php new file mode 100644 index 0000000..8e3bf1c --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/ClearAllPayload.php @@ -0,0 +1,11 @@ +color = $color; + } + + public function getType(): string + { + return 'color'; + } + + public function getContent(): array + { + return [ + 'color' => $this->color, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/CreateLockPayload.php b/vendor/spatie/ray/src/Payloads/CreateLockPayload.php new file mode 100644 index 0000000..8ea0a49 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/CreateLockPayload.php @@ -0,0 +1,26 @@ +name = $name; + } + + public function getType(): string + { + return 'create_lock'; + } + + public function getContent(): array + { + return [ + 'name' => $this->name, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/CustomPayload.php b/vendor/spatie/ray/src/Payloads/CustomPayload.php new file mode 100644 index 0000000..71cf55b --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/CustomPayload.php @@ -0,0 +1,32 @@ +content = $content; + + $this->label = $label; + } + + public function getType(): string + { + return 'custom'; + } + + public function getContent(): array + { + return [ + 'content' => $this->content, + 'label' => $this->label, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/DecodedJsonPayload.php b/vendor/spatie/ray/src/Payloads/DecodedJsonPayload.php new file mode 100644 index 0000000..d0cef0b --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/DecodedJsonPayload.php @@ -0,0 +1,31 @@ +value = $value; + } + + public function getType(): string + { + return 'custom'; + } + + public function getContent(): array + { + $decodedJson = json_decode($this->value, true); + + return [ + 'content' => ArgumentConverter::convertToPrimitive($decodedJson), + 'label' => '', + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/ExceptionPayload.php b/vendor/spatie/ray/src/Payloads/ExceptionPayload.php new file mode 100644 index 0000000..ff1320e --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/ExceptionPayload.php @@ -0,0 +1,56 @@ +exception = $exception; + + $this->meta = $meta; + } + + public function getType(): string + { + return 'exception'; + } + + public function getContent(): array + { + Backtrace::createForThrowable($this->exception); + + return [ + 'class' => get_class($this->exception), + 'message' => $this->exception->getMessage(), + 'frames' => $this->getFrames(), + 'meta' => $this->meta, + ]; + } + + protected function getFrames(): array + { + $frames = Backtrace::createForThrowable($this->exception)->frames(); + + return array_map(function (Frame $frame) { + return [ + 'file_name' => $this->replaceRemotePathWithLocalPath($frame->file), + 'line_number' => $frame->lineNumber, + 'class' => $frame->class, + 'method' => $frame->method, + 'vendor_frame' => ! $frame->applicationFrame, + 'snippet' => $frame->getSnippetProperties(12), + ]; + }, $frames); + } +} diff --git a/vendor/spatie/ray/src/Payloads/FileContentsPayload.php b/vendor/spatie/ray/src/Payloads/FileContentsPayload.php new file mode 100644 index 0000000..d3fed09 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/FileContentsPayload.php @@ -0,0 +1,44 @@ +file = $file; + } + + public function getType(): string + { + return 'custom'; + } + + public function getContent(): array + { + if (! file_exists($this->file)) { + return [ + 'content' => "File not found: '{$this->file}'", + 'label' => 'File', + ]; + } + + $contents = file_get_contents($this->file); + + return [ + 'content' => $this->encodeContent($contents), + 'label' => basename($this->file), + ]; + } + + protected function encodeContent(string $content): string + { + $result = htmlentities($content, ENT_QUOTES | ENT_SUBSTITUTE); + + // using nl2br() causes tests to fail on Windows, so use
only + return str_replace(PHP_EOL, '
', $result); + } +} diff --git a/vendor/spatie/ray/src/Payloads/HideAppPayload.php b/vendor/spatie/ray/src/Payloads/HideAppPayload.php new file mode 100644 index 0000000..e754725 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/HideAppPayload.php @@ -0,0 +1,11 @@ +html = $html; + } + + public function getType(): string + { + return 'custom'; + } + + public function getContent(): array + { + return [ + 'content' => $this->html, + 'label' => 'HTML', + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/ImagePayload.php b/vendor/spatie/ray/src/Payloads/ImagePayload.php new file mode 100644 index 0000000..4d8b965 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/ImagePayload.php @@ -0,0 +1,54 @@ +location = $location; + } + + public function getType(): string + { + return 'custom'; + } + + public function getContent(): array + { + if (file_exists($this->location)) { + $this->location = 'file://' . $this->location; + } + + if ($this->hasBase64Data()) { + $this->location = $this->getLocationForBase64Data(); + } + + $location = str_replace('"', '', $this->location); + + return [ + 'content' => "\"\"", + 'label' => 'Image', + ]; + } + + protected function stripDataPrefix(string $data): string + { + return preg_replace('~^data:image/[a-z]+;base64,~', '', $data); + } + + protected function hasBase64Data(): bool + { + $data = $this->stripDataPrefix($this->location); + + return base64_encode(base64_decode($data, true)) === $data; + } + + protected function getLocationForBase64Data(): string + { + return 'data:image/png;base64,' . $this->stripDataPrefix($this->location); + } +} diff --git a/vendor/spatie/ray/src/Payloads/JsonStringPayload.php b/vendor/spatie/ray/src/Payloads/JsonStringPayload.php new file mode 100644 index 0000000..48086d0 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/JsonStringPayload.php @@ -0,0 +1,26 @@ +value = $value; + } + + public function getType(): string + { + return 'json_string'; + } + + public function getContent(): array + { + return [ + 'value' => json_encode($this->value), + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/LabelPayload.php b/vendor/spatie/ray/src/Payloads/LabelPayload.php new file mode 100644 index 0000000..08c7100 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/LabelPayload.php @@ -0,0 +1,26 @@ +label = $label; + } + + public function getType(): string + { + return 'label'; + } + + public function getContent(): array + { + return [ + 'label' => $this->label, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/LogPayload.php b/vendor/spatie/ray/src/Payloads/LogPayload.php new file mode 100644 index 0000000..62b14ff --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/LogPayload.php @@ -0,0 +1,41 @@ +values = $values; + } + + public function getType(): string + { + return 'log'; + } + + public function getContent(): array + { + return [ + 'values' => $this->values, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/MeasurePayload.php b/vendor/spatie/ray/src/Payloads/MeasurePayload.php new file mode 100644 index 0000000..08f4fbd --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/MeasurePayload.php @@ -0,0 +1,71 @@ +name = $name; + + $this->totalTime = $stopwatchEvent->getDuration(); + $this->maxMemoryUsageDuringTotalTime = $stopwatchEvent->getMemory(); + + $periods = $stopwatchEvent->getPeriods(); + + if ($lastPeriod = end($periods)) { + $this->timeSinceLastCall = $lastPeriod->getDuration() ; + $this->maxMemoryUsageSinceLastCall = $lastPeriod->getMemory(); + } + } + + public function concernsNewTimer(): self + { + $this->isNewTimer = true; + $this->totalTime = 0; + $this->maxMemoryUsageDuringTotalTime = 0; + $this->timeSinceLastCall = 0; + $this->maxMemoryUsageSinceLastCall = 0; + + return $this; + } + + public function getType(): string + { + return 'measure'; + } + + public function getContent(): array + { + return [ + 'name' => $this->name, + 'is_new_timer' => $this->isNewTimer, + + 'total_time' => $this->totalTime, + 'max_memory_usage_during_total_time' => $this->maxMemoryUsageDuringTotalTime, + + 'time_since_last_call' => $this->timeSinceLastCall, + 'max_memory_usage_since_last_call' => $this->maxMemoryUsageSinceLastCall, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/NewScreenPayload.php b/vendor/spatie/ray/src/Payloads/NewScreenPayload.php new file mode 100644 index 0000000..6ccbc50 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/NewScreenPayload.php @@ -0,0 +1,26 @@ +name = $name; + } + + public function getType(): string + { + return 'new_screen'; + } + + public function getContent(): array + { + return [ + 'name' => $this->name, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/NotifyPayload.php b/vendor/spatie/ray/src/Payloads/NotifyPayload.php new file mode 100644 index 0000000..aecf244 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/NotifyPayload.php @@ -0,0 +1,26 @@ +text = $text; + } + + public function getType(): string + { + return 'notify'; + } + + public function getContent(): array + { + return [ + 'value' => $this->text, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/NullPayload.php b/vendor/spatie/ray/src/Payloads/NullPayload.php new file mode 100644 index 0000000..e88af22 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/NullPayload.php @@ -0,0 +1,22 @@ + null, + 'label' => 'Null', + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/Payload.php b/vendor/spatie/ray/src/Payloads/Payload.php new file mode 100644 index 0000000..048b880 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/Payload.php @@ -0,0 +1,62 @@ +remotePath) || is_null($this->localPath)) { + return $filePath; + } + + $pattern = '~^' . preg_quote($this->remotePath, '~') . '~'; + + return preg_replace($pattern, $this->localPath, $filePath); + } + + public function getContent(): array + { + return []; + } + + public function toArray(): array + { + return [ + 'type' => $this->getType(), + 'content' => $this->getContent(), + 'origin' => $this->getOrigin()->toArray(), + ]; + } + + public function toJson(): string + { + return json_encode($this->toArray()); + } + + protected function getOrigin(): Origin + { + /** @var \Spatie\Ray\Origin\OriginFactory $originFactory */ + $originFactory = new self::$originFactoryClass(); + + $origin = $originFactory->getOrigin(); + + $origin->file = $this->replaceRemotePathWithLocalPath($origin->file); + + return $origin; + } +} diff --git a/vendor/spatie/ray/src/Payloads/PhpInfoPayload.php b/vendor/spatie/ray/src/Payloads/PhpInfoPayload.php new file mode 100644 index 0000000..5da54b5 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/PhpInfoPayload.php @@ -0,0 +1,45 @@ +properties = $properties; + } + + public function getType(): string + { + return 'table'; + } + + public function getContent(): array + { + $values = array_flip($this->properties); + + foreach ($values as $property => $value) { + $values[$property] = ini_get($property); + } + + if (empty($values)) { + $values = [ + 'PHP version' => phpversion(), + 'Memory limit' => ini_get('memory_limit'), + 'Max file upload size' => ini_get('max_file_uploads'), + 'Max post size' => ini_get('post_max_size'), + 'PHP ini file' => php_ini_loaded_file(), + "PHP scanned ini file" => php_ini_scanned_files(), + 'Extensions' => implode(', ', get_loaded_extensions()), + ]; + } + + return [ + 'values' => $values, + 'label' => 'PHPInfo', + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/RemovePayload.php b/vendor/spatie/ray/src/Payloads/RemovePayload.php new file mode 100644 index 0000000..b31c321 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/RemovePayload.php @@ -0,0 +1,11 @@ +color = $color; + } + + public function getType(): string + { + return 'screen_color'; + } + + public function getContent(): array + { + return [ + 'color' => $this->color, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/SeparatorPayload.php b/vendor/spatie/ray/src/Payloads/SeparatorPayload.php new file mode 100644 index 0000000..721329e --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/SeparatorPayload.php @@ -0,0 +1,11 @@ +size = $size; + } + + public function getType(): string + { + return 'size'; + } + + public function getContent(): array + { + return [ + 'size' => $this->size, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/TablePayload.php b/vendor/spatie/ray/src/Payloads/TablePayload.php new file mode 100644 index 0000000..a8d065b --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/TablePayload.php @@ -0,0 +1,38 @@ +values = $values; + + $this->label = $label; + } + + public function getType(): string + { + return 'table'; + } + + public function getContent(): array + { + $values = array_map(function ($value) { + return ArgumentConverter::convertToPrimitive($value); + }, $this->values); + + return [ + 'values' => $values, + 'label' => $this->label, + ]; + } +} diff --git a/vendor/spatie/ray/src/Payloads/TextPayload.php b/vendor/spatie/ray/src/Payloads/TextPayload.php new file mode 100644 index 0000000..a444eb9 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/TextPayload.php @@ -0,0 +1,34 @@ +text = $text; + } + + public function getType(): string + { + return 'custom'; + } + + public function getContent(): array + { + return [ + 'content' => $this->formatContent(), + 'label' => 'Text', + ]; + } + + protected function formatContent(): string + { + $result = htmlspecialchars($this->text, ENT_QUOTES | ENT_HTML5); + + return str_replace([' ', PHP_EOL], [' ', '
'], $result); + } +} diff --git a/vendor/spatie/ray/src/Payloads/TracePayload.php b/vendor/spatie/ray/src/Payloads/TracePayload.php new file mode 100644 index 0000000..3869cbc --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/TracePayload.php @@ -0,0 +1,63 @@ +frames = $this->removeRayFrames($frames); + } + + public function startFromIndex(int $index): self + { + $this->startFromIndex = $index; + + return $this; + } + + public function limit(int $limit): self + { + $this->limit = $limit; + + return $this; + } + + public function getType(): string + { + return 'trace'; + } + + public function getContent(): array + { + $frames = array_map(function (Frame $frame) { + return [ + 'file_name' => $this->replaceRemotePathWithLocalPath($frame->file), + 'line_number' => $frame->lineNumber, + 'class' => $frame->class, + 'method' => $frame->method, + 'vendor_frame' => ! $frame->applicationFrame, + ]; + }, $this->frames); + + if (! is_null($this->limit)) { + $frames = array_slice($frames, $this->startFromIndex ?? 0, $this->limit); + } + + return compact('frames'); + } +} diff --git a/vendor/spatie/ray/src/Payloads/XmlPayload.php b/vendor/spatie/ray/src/Payloads/XmlPayload.php new file mode 100644 index 0000000..0620052 --- /dev/null +++ b/vendor/spatie/ray/src/Payloads/XmlPayload.php @@ -0,0 +1,62 @@ +value = $value; + } + + public function getType(): string + { + return 'custom'; + } + + public function getContent(): array + { + $content = $this->formatXmlForDisplay($this->value); + + return [ + 'content' => $content, + 'label' => 'XML', + ]; + } + + protected function formatXmlForDisplay(string $xml): string + { + $content = $this->formatAndIndentXml($xml); + + return $this->encodeXml(trim($content)); + } + + protected function encodeXml(string $xml): string + { + $result = htmlentities($xml); + + return str_replace([PHP_EOL, "\n", ' '], ['
', '
', ' '], $result); + } + + protected function formatAndIndentXml(string $xml): string + { + if (! class_exists(\DOMDocument::class)) { + return $xml; + } + + $dom = new \DOMDocument(); + + $dom->preserveWhiteSpace = false; + $dom->strictErrorChecking = false; + $dom->formatOutput = true; + + if (! $dom->loadXML($xml, LIBXML_NOERROR | LIBXML_NOWARNING)) { + return $xml; + } + + return $dom->saveXML(); + } +} diff --git a/vendor/spatie/ray/src/Ray.php b/vendor/spatie/ray/src/Ray.php new file mode 100644 index 0000000..0d0e536 --- /dev/null +++ b/vendor/spatie/ray/src/Ray.php @@ -0,0 +1,791 @@ +settings = $settings; + + self::$client = $client ?? self::$client ?? new Client($settings->port, $settings->host); + + self::$counters = self::$counters ?? new Counters(); + + self::$limiters = self::$limiters ?? new Limiters(); + + $this->uuid = $uuid ?? static::$fakeUuid ?? Uuid::uuid4()->toString(); + + static::$enabled = static::$enabled ?? $this->settings->enable ?? true; + + static::$rateLimiter = static::$rateLimiter ?? RateLimiter::disabled(); + } + + /** + * @param string $projectName + * + * @return $this + */ + public function project($projectName): self + { + static::$projectName = $projectName; + + return $this; + } + + public function enable(): self + { + static::$enabled = true; + + return $this; + } + + public function disable(): self + { + static::$enabled = false; + + return $this; + } + + public function enabled(): bool + { + return static::$enabled || static::$enabled === null; + } + + public function disabled(): bool + { + return static::$enabled === false; + } + + public static function useClient(Client $client): void + { + self::$client = $client; + } + + public function newScreen(string $name = ''): self + { + $payload = new NewScreenPayload($name); + + return $this->sendRequest($payload); + } + + public function clearAll(): self + { + $payload = new ClearAllPayload(); + + return $this->sendRequest($payload); + } + + public function clearScreen(): self + { + return $this->newScreen(); + } + + public function color(string $color): self + { + $payload = new ColorPayload($color); + + return $this->sendRequest($payload); + } + + public function screenColor(string $color): self + { + $payload = new ScreenColorPayload($color); + + return $this->sendRequest($payload); + } + + public function label(string $label): self + { + $payload = new LabelPayload($label); + + return $this->sendRequest($payload); + } + + public function size(string $size): self + { + $payload = new SizePayload($size); + + return $this->sendRequest($payload); + } + + public function remove(): self + { + $payload = new RemovePayload(); + + return $this->sendRequest($payload); + } + + public function hide(): self + { + $payload = new HidePayload(); + + return $this->sendRequest($payload); + } + + /** + * @param string|callable $stopwatchName + * + * @return $this + */ + public function measure($stopwatchName = 'default'): self + { + if ($stopwatchName instanceof Closure) { + return $this->measureClosure($stopwatchName); + } + + if (! isset(static::$stopWatches[$stopwatchName])) { + $stopwatch = new Stopwatch(true); + static::$stopWatches[$stopwatchName] = $stopwatch; + + $event = $stopwatch->start($stopwatchName); + $payload = new MeasurePayload($stopwatchName, $event); + $payload->concernsNewTimer(); + + return $this->sendRequest($payload); + } + + $stopwatch = static::$stopWatches[$stopwatchName]; + $event = $stopwatch->lap($stopwatchName); + $payload = new MeasurePayload($stopwatchName, $event); + + return $this->sendRequest($payload); + } + + public function trace(?Closure $startingFromFrame = null): self + { + $backtrace = Backtrace::create(); + + if (class_exists(LaravelRay::class) && function_exists('base_path')) { + $backtrace->applicationPath(base_path()); + } + + if ($startingFromFrame) { + $backtrace->startingFromFrame($startingFromFrame); + } + + $payload = new TracePayload($backtrace->frames()); + + return $this->sendRequest($payload); + } + + public function backtrace(?Closure $startingFromFrame = null): self + { + return $this->trace($startingFromFrame); + } + + public function caller(): self + { + $backtrace = Backtrace::create(); + + $payload = (new CallerPayload($backtrace->frames())); + + return $this->sendRequest($payload); + } + + protected function measureClosure(Closure $closure): self + { + $stopwatch = new Stopwatch(true); + + $stopwatch->start('closure'); + + $closure(); + + $event = $stopwatch->stop('closure'); + + $payload = new MeasurePayload('closure', $event); + + return $this->sendRequest($payload); + } + + public function stopTime(string $stopwatchName = ''): self + { + if ($stopwatchName === '') { + static::$stopWatches = []; + + return $this; + } + + if (isset(static::$stopWatches[$stopwatchName])) { + unset(static::$stopWatches[$stopwatchName]); + + return $this; + } + + return $this; + } + + public function notify(string $text): self + { + $payload = new NotifyPayload($text); + + return $this->sendRequest($payload); + } + + /** + * Sends the provided value(s) encoded as a JSON string using json_encode(). + */ + public function toJson(...$values): self + { + $payloads = array_map(function ($value) { + return new JsonStringPayload($value); + }, $values); + + return $this->sendRequest($payloads); + } + + /** + * Sends the provided JSON string(s) decoded using json_decode(). + */ + public function json(string ...$jsons): self + { + $payloads = array_map(function ($json) { + return new DecodedJsonPayload($json); + }, $jsons); + + return $this->sendRequest($payloads); + } + + public function file(string $filename): self + { + $payload = new FileContentsPayload($filename); + + return $this->sendRequest($payload); + } + + public function image(string $location): self + { + $payload = new ImagePayload($location); + + return $this->sendRequest($payload); + } + + public function die($status = ''): void + { + die($status); + } + + public function className(object $object): self + { + return $this->send(get_class($object)); + } + + public function phpinfo(string ...$properties): self + { + $payload = new PhpInfoPayload(...$properties); + + return $this->sendRequest($payload); + } + + public function if($boolOrCallable, ?callable $callback = null): self + { + if (is_callable($boolOrCallable)) { + $boolOrCallable = (bool)$boolOrCallable(); + } + + if ($boolOrCallable && $callback !== null) { + $callback($this); + } + + if ($callback === null) { + $this->canSendPayload = $boolOrCallable; + } + + return $this; + } + + /** + * @deprecated Use `if` instead of this method + */ + public function showWhen($boolOrCallable): self + { + if (is_callable($boolOrCallable)) { + $boolOrCallable = (bool)$boolOrCallable(); + } + + if (! $boolOrCallable) { + $this->remove(); + } + + return $this; + } + + /** + * @deprecated Use `if` instead of this method + */ + public function showIf($boolOrCallable): self + { + return $this->showWhen($boolOrCallable); + } + + /** + * @deprecated Use `if` instead of this method + */ + public function removeWhen($boolOrCallable): self + { + if (is_callable($boolOrCallable)) { + $boolOrCallable = (bool)$boolOrCallable(); + } + + if ($boolOrCallable) { + $this->remove(); + } + + return $this; + } + + /** + * @deprecated Use `if` instead of this method + */ + public function removeIf($boolOrCallable): self + { + return $this->removeWhen($boolOrCallable); + } + + public function carbon(?CarbonInterface $carbon): self + { + $payload = new CarbonPayload($carbon); + + $this->sendRequest($payload); + + return $this; + } + + public function ban(): self + { + return $this->send('🕶'); + } + + public function charles(): self + { + return $this->send('🎶 🎹 🎷 🕺'); + } + + public function table(array $values, $label = 'Table'): self + { + $payload = new TablePayload($values, $label); + + return $this->sendRequest($payload); + } + + public function count(?string $name = null): self + { + $fingerPrint = (new DefaultOriginFactory())->getOrigin()->fingerPrint(); + + [$ray, $times] = self::$counters->increment($name ?? $fingerPrint); + + $message = "Called "; + + if ($name) { + $message .= "`{$name}` "; + } + + $message .= "{$times} "; + + $message .= $times === 1 + ? 'time' + : 'times'; + + $message .= '.'; + + $ray->sendCustom($message, 'Count'); + + return $ray; + } + + public function clearCounters(): self + { + self::$counters->clear(); + + return $this; + } + + public function counterValue(string $name): int + { + return self::$counters->get($name); + } + + public function pause(): self + { + $lockName = md5(time()); + + $payload = new CreateLockPayload($lockName); + + $this->sendRequest($payload); + + do { + sleep(1); + } while (self::$client->lockExists($lockName)); + + return $this; + } + + public function separator(): self + { + $payload = new SeparatorPayload(); + + return $this->sendRequest($payload); + } + + public function html(string $html = ''): self + { + $payload = new HtmlPayload($html); + + return $this->sendRequest($payload); + } + + public function exception(Throwable $exception, array $meta = []) + { + $payload = new ExceptionPayload($exception, $meta); + + $this->sendRequest($payload); + + $this->red(); + + return $this; + } + + public function xml(string $xml): self + { + $payload = new XmlPayload($xml); + + return $this->sendRequest($payload); + } + + public function text(string $text): self + { + $payload = new TextPayload($text); + + return $this->sendRequest($payload); + } + + public function raw(...$arguments): self + { + if (! count($arguments)) { + return $this; + } + + $payloads = array_map(function ($argument) { + return LogPayload::createForArguments([$argument]); + }, $arguments); + + return $this->sendRequest($payloads); + } + + public function limit(int $count): self + { + $this->limitOrigin = (new DefaultOriginFactory())->getOrigin(); + + self::$limiters->initialize($this->limitOrigin, $count); + + return $this; + } + + public function once(...$arguments): self + { + $this->limitOrigin = (new DefaultOriginFactory())->getOrigin(); + + self::$limiters->initialize($this->limitOrigin, 1); + + if (! empty($arguments)) { + return $this->send(...$arguments); + } + + return $this; + } + + /** + * @param callable|string|null $callback + * @return \Spatie\Ray\Ray + */ + public function catch($callback = null): self + { + $result = (new ExceptionHandler())->catch($this, $callback); + + if ($result instanceof Ray) { + return $result; + } + + return $this; + } + + public function throwExceptions(): self + { + while (! empty(self::$caughtExceptions)) { + throw array_shift(self::$caughtExceptions); + } + + return $this; + } + + public function send(...$arguments): self + { + if (! count($arguments)) { + return $this; + } + + if ($this->settings->always_send_raw_values) { + return $this->raw(...$arguments); + } + + $arguments = array_map(function ($argument) { + if (is_string($argument)) { + return $argument; + } + + if (! is_callable($argument)) { + return $argument; + } + + try { + $result = $argument($this); + + // use a specific class we can filter out instead of null so that null + // payloads can still be sent. + return $result instanceof Ray ? IgnoredValue::make() : $result; + } catch (Exception $exception) { + self::$caughtExceptions[] = $exception; + + return IgnoredValue::make(); + } catch (TypeError $error) { + return $argument; + } + }, $arguments); + + $arguments = array_filter($arguments, function ($argument) { + return ! $argument instanceof IgnoredValue; + }); + + if (empty($arguments)) { + return $this; + } + + $payloads = PayloadFactory::createForValues($arguments); + + return $this->sendRequest($payloads); + } + + public function pass($argument) + { + $this->send($argument); + + return $argument; + } + + public function showApp(): self + { + $payload = new ShowAppPayload(); + + return $this->sendRequest($payload); + } + + public function hideApp(): self + { + $payload = new HideAppPayload(); + + return $this->sendRequest($payload); + } + + public function sendCustom(string $content, string $label = ''): self + { + $customPayload = new CustomPayload($content, $label); + + return $this->sendRequest($customPayload); + } + + /** + * @param \Spatie\Ray\Payloads\Payload|\Spatie\Ray\Payloads\Payload[] $payloads + * @param array $meta + * + * @return $this + * @throws \Exception + */ + public function sendRequest($payloads, array $meta = []): self + { + if (! $this->enabled()) { + return $this; + } + + if (empty($payloads)) { + return $this; + } + + if (! $this->canSendPayload) { + return $this; + } + + if (! empty($this->limitOrigin)) { + if (! self::$limiters->canSendPayload($this->limitOrigin)) { + return $this; + } + + self::$limiters->increment($this->limitOrigin); + } + + if (! is_array($payloads)) { + $payloads = [$payloads]; + } + + try { + if (class_exists(InstalledVersions::class)) { + $meta['ray_package_version'] = InstalledVersions::getVersion('spatie/ray'); + } + } catch (Exception $e) { + // In WordPress this entire package will be rewritten + } + + if (self::rateLimiter()->isMaxReached() || + self::rateLimiter()->isMaxPerSecondReached()) { + $this->notifyWhenRateLimitReached(); + + return $this; + } + + $allMeta = array_merge([ + 'php_version' => phpversion(), + 'php_version_id' => PHP_VERSION_ID, + 'project_name' => static::$projectName, + ], $meta); + + foreach ($payloads as $payload) { + $payload->remotePath = $this->settings->remote_path; + $payload->localPath = $this->settings->local_path; + } + + $request = new Request($this->uuid, $payloads, $allMeta); + + self::$client->send($request); + + self::rateLimiter()->hit(); + + return $this; + } + + public static function makePathOsSafe(string $path): string + { + return str_replace('/', DIRECTORY_SEPARATOR, $path); + } + + public static function rateLimiter(): RateLimiter + { + return self::$rateLimiter; + } + + protected function notifyWhenRateLimitReached(): void + { + if (self::rateLimiter()->isNotified()) { + return; + } + + $customPayload = new CustomPayload('Rate limit has been reached...', 'Rate limit'); + + $request = new Request($this->uuid, [$customPayload], []); + + self::$client->send($request); + + self::rateLimiter()->notify(); + } +} diff --git a/vendor/spatie/ray/src/Request.php b/vendor/spatie/ray/src/Request.php new file mode 100644 index 0000000..eb1e389 --- /dev/null +++ b/vendor/spatie/ray/src/Request.php @@ -0,0 +1,44 @@ +uuid = $uuid; + + $this->payloads = $payloads; + + $this->meta = $meta; + } + + public function toArray(): array + { + $payloads = array_map(function (Payload $payload) { + return $payload->toArray(); + }, $this->payloads); + + return [ + 'uuid' => $this->uuid, + 'payloads' => $payloads, + 'meta' => $this->meta, + ]; + } + + public function toJson(): string + { + return json_encode($this->toArray()); + } +} diff --git a/vendor/spatie/ray/src/Settings/Settings.php b/vendor/spatie/ray/src/Settings/Settings.php new file mode 100644 index 0000000..141cda4 --- /dev/null +++ b/vendor/spatie/ray/src/Settings/Settings.php @@ -0,0 +1,68 @@ + true, + 'host' => 'localhost', + 'port' => 23517, + 'remote_path' => null, + 'local_path' => null, + 'always_send_raw_values' => false, + ]; + + public function __construct(array $settings) + { + $this->settings = array_merge($this->defaultSettings, $settings); + } + + public function markAsLoadedUsingSettingsFile() + { + $this->loadedUsingSettingsFile = true; + + return $this; + } + + public function setDefaultSettings(array $defaults) + { + foreach ($defaults as $name => $value) { + if ($this->wasLoadedUsingConfigFile($name)) { + $this->settings[$name] = $value; + } + } + + return $this; + } + + protected function wasLoadedUsingConfigFile($name) + { + if (! array_key_exists($name, $this->settings)) { + return true; + } + + if (! $this->loadedUsingSettingsFile) { + return true; + } + + return false; + } + + public function __set(string $name, $value) + { + $this->settings[$name] = $value; + } + + public function __get(string $name) + { + return $this->settings[$name] ?? null; + } +} diff --git a/vendor/spatie/ray/src/Settings/SettingsFactory.php b/vendor/spatie/ray/src/Settings/SettingsFactory.php new file mode 100644 index 0000000..9c661c2 --- /dev/null +++ b/vendor/spatie/ray/src/Settings/SettingsFactory.php @@ -0,0 +1,74 @@ +getSettingsFromConfigFile($configDirectory); + + $settings = new Settings($settingValues); + + if (count($settingValues)) { + $settings->markAsLoadedUsingSettingsFile(); + } + + return $settings; + } + + public function getSettingsFromConfigFile(string $configDirectory = null): array + { + $configFilePath = $this->searchConfigFiles($configDirectory); + + if (! file_exists($configFilePath)) { + return []; + } + + $options = include $configFilePath; + + return $options ?? []; + } + + protected function searchConfigFiles(string $configDirectory = null): string + { + if (! isset(self::$cache[$configDirectory])) { + self::$cache[$configDirectory] = $this->searchConfigFilesOnDisk($configDirectory); + } + + return self::$cache[$configDirectory]; + } + + protected function searchConfigFilesOnDisk(string $configDirectory = null): string + { + $configNames = [ + 'ray.php', + ]; + + $configDirectory = $configDirectory ?? getcwd(); + + while (@is_dir($configDirectory)) { + foreach ($configNames as $configName) { + $configFullPath = $configDirectory.DIRECTORY_SEPARATOR.$configName; + if (file_exists($configFullPath)) { + return $configFullPath; + } + } + + $parentDirectory = dirname($configDirectory); + + // We do a direct comparison here since there's a difference between + // the root directories on windows / *nix systems which does not + // let us compare it against the DIRECTORY_SEPARATOR directly + if ($parentDirectory === $configDirectory) { + return ''; + } + + $configDirectory = $parentDirectory; + } + + return ''; + } +} diff --git a/vendor/spatie/ray/src/Support/CacheStore.php b/vendor/spatie/ray/src/Support/CacheStore.php new file mode 100644 index 0000000..019c554 --- /dev/null +++ b/vendor/spatie/ray/src/Support/CacheStore.php @@ -0,0 +1,61 @@ +clock = $clock; + } + + public function hit(): self + { + $this->store[] = $this->clock->now(); + + return $this; + } + + public function clear(): self + { + $this->store = []; + + return $this; + } + + public function count(): int + { + return count($this->store); + } + + public function countLastSecond(): int + { + $amount = 0; + + $lastSecond = $this->clock->now()->modify('-1 second'); + + foreach ($this->store as $key => $item) { + if ($this->isBetween( + $item->getTimestamp(), + $lastSecond->getTimestamp(), + $this->clock->now()->getTimestamp() + ) + ) { + $amount++; + } + } + + return $amount; + } + + protected function isBetween($toCheck, $start, $end): bool + { + return $toCheck >= $start && $toCheck <= $end; + } +} diff --git a/vendor/spatie/ray/src/Support/Clock.php b/vendor/spatie/ray/src/Support/Clock.php new file mode 100644 index 0000000..3bb9c8e --- /dev/null +++ b/vendor/spatie/ray/src/Support/Clock.php @@ -0,0 +1,10 @@ +counters[$name])) { + $this->counters[$name] = [ray(), 0]; + } + + [$ray, $times] = $this->counters[$name]; + + $newTimes = $times + 1; + + $this->counters[$name] = [$ray, $newTimes]; + + return [$ray, $newTimes]; + } + + public function get(string $name): int + { + if (! isset($this->counters[$name])) { + return 0; + } + + return $this->counters[$name][1]; + } + + public function clear(): void + { + $this->counters = []; + } + + public function setRay(string $name, Ray $ray): void + { + $this->counters[$name][0] = $ray; + } +} diff --git a/vendor/spatie/ray/src/Support/ExceptionHandler.php b/vendor/spatie/ray/src/Support/ExceptionHandler.php new file mode 100644 index 0000000..545e23b --- /dev/null +++ b/vendor/spatie/ray/src/Support/ExceptionHandler.php @@ -0,0 +1,148 @@ +executeExceptionHandlerCallback($ray, $callback); + + if (! empty(Ray::$caughtExceptions)) { + throw array_shift(Ray::$caughtExceptions); + } + + return $ray; + } + + protected function executeCallableExceptionHandler(Ray $ray, $callback, $rethrow = true): Ray + { + $paramType = $this->getParamType(new ReflectionFunction($callback)); + $expectedClasses = $this->getExpectedClasses($paramType); + + if (count($expectedClasses)) { + $isExpected = false; + + foreach ($expectedClasses as $class) { + $isExpected = $this->isExpectedExceptionClass($class); + + if ($isExpected) { + break; + } + } + + if (! $isExpected && ! $rethrow) { + return $ray; + } + + if (! $isExpected && $rethrow) { + throw array_shift(Ray::$caughtExceptions); + } + } + + $exception = array_shift(Ray::$caughtExceptions); + + $callbackResult = $callback($exception, $ray); + + return $callbackResult instanceof Ray ? $callbackResult : $ray; + } + + protected function isExpectedExceptionClass($expectedClass): bool + { + foreach (Ray::$caughtExceptions as $caughtException) { + if (is_a($caughtException, $expectedClass, true)) { + return true; + } + } + + return false; + } + + protected function sendExceptionPayload(Ray $ray): Ray + { + $exception = array_shift(Ray::$caughtExceptions); + + return $ray->exception($exception); + } + + protected function executeExceptionHandlerCallback(Ray $ray, $callback, $rethrow = true): Ray + { + if (empty(Ray::$caughtExceptions)) { + return $ray; + } + + if (is_callable($callback)) { + return $this->executeCallableExceptionHandler($ray, $callback, $rethrow); + } + + // support arrays of both class names and callables + if (is_array($callback)) { + return $this->executeArrayOfExceptionHandlers($ray, $callback) ?? $ray; + } + + return $this->sendCallbackExceptionPayload($ray, $callback); + ; + } + + protected function executeArrayOfExceptionHandlers(Ray $ray, array $callbacks): ?Ray + { + foreach ($callbacks as $item) { + $result = $this->executeExceptionHandlerCallback($ray, $item, false); + + // the array item handled the exception + if (empty(Ray::$caughtExceptions)) { + return $result instanceof Ray ? $result : $ray; + } + } + + return $ray; + } + + protected function sendCallbackExceptionPayload(Ray $ray, $callback): Ray + { + if (! $callback) { + return $this->sendExceptionPayload($ray); + } + + // handle class names + foreach (Ray::$caughtExceptions as $caughtException) { + if (is_string($callback) && is_a($caughtException, $callback, true)) { + return $this->sendExceptionPayload($ray); + } + } + + return $ray; + } + + protected function getExpectedClasses($paramType): array + { + if (! $paramType) { + return [Exception::class]; + } + + $result = is_a($paramType, '\\ReflectionUnionType') ? $paramType->getTypes() : [$paramType->getName()]; + + return array_map(function ($type) { + if (is_string($type)) { + return $type; + } + + return method_exists($type, 'getName') ? $type->getName() : get_class($type); + }, $result); + } + + protected function getParamType(ReflectionFunction $reflection) + { + $paramType = null; + + if ($reflection->getNumberOfParameters() > 0) { + $paramType = $reflection->getParameters()[0]->getType(); + } + + return $paramType; + } +} diff --git a/vendor/spatie/ray/src/Support/IgnoredValue.php b/vendor/spatie/ray/src/Support/IgnoredValue.php new file mode 100644 index 0000000..77fb2dd --- /dev/null +++ b/vendor/spatie/ray/src/Support/IgnoredValue.php @@ -0,0 +1,11 @@ +counters[$origin->fingerPrint()])) { + $this->counters[$origin->fingerPrint()] = [0, $limit]; + } + + return $this->counters[$origin->fingerPrint()]; + } + + public function increment(Origin $origin): array + { + $name = $origin->fingerPrint(); + + if (! isset($this->counters[$name])) { + return [false, false]; + } + + [$times, $limit] = $this->counters[$name]; + + $newTimes = $times + 1; + + $this->counters[$name] = [$newTimes, $limit]; + + return [$newTimes, $limit]; + } + + public function canSendPayload(Origin $origin): bool + { + $name = $origin->fingerPrint(); + + if (! isset($this->counters[$name])) { + return true; + } + + [$times, $limit] = $this->counters[$name]; + + return $times < $limit || $limit <= 0; + } +} diff --git a/vendor/spatie/ray/src/Support/RateLimiter.php b/vendor/spatie/ray/src/Support/RateLimiter.php new file mode 100644 index 0000000..cbec9d6 --- /dev/null +++ b/vendor/spatie/ray/src/Support/RateLimiter.php @@ -0,0 +1,106 @@ +maxCalls = $maxCalls; + $this->maxPerSecond = $maxPerSecond; + $this->cache = new CacheStore(new SystemClock()); + } + + public static function disabled(): self + { + return new self(null, null); + } + + public function hit(): self + { + $this->cache()->hit(); + + return $this; + } + + public function max(?int $maxCalls): self + { + $this->maxCalls = $maxCalls; + + return $this; + } + + public function perSecond(?int $callsPerSecond): self + { + $this->maxPerSecond = $callsPerSecond; + + return $this; + } + + public function isMaxReached(): bool + { + if ($this->maxCalls === null) { + return false; + } + + $reached = $this->cache()->count() >= $this->maxCalls; + + if ($reached === false) { + $this->notified = false; + } + + return $reached; + } + + public function isMaxPerSecondReached(): bool + { + if ($this->maxPerSecond === null) { + return false; + } + + $reached = $this->cache()->countLastSecond() >= $this->maxPerSecond; + + if ($reached === false) { + $this->notified = false; + } + + return $reached; + } + + public function clear(): self + { + $this->maxCalls = null; + $this->maxPerSecond = null; + + $this->cache()->clear(); + + return $this; + } + + public function isNotified(): bool + { + return $this->notified; + } + + public function notify(): void + { + $this->notified = true; + } + + public function cache(): CacheStore + { + return $this->cache; + } +} diff --git a/vendor/spatie/ray/src/Support/SystemClock.php b/vendor/spatie/ray/src/Support/SystemClock.php new file mode 100644 index 0000000..30bcfd9 --- /dev/null +++ b/vendor/spatie/ray/src/Support/SystemClock.php @@ -0,0 +1,13 @@ +send(...$args); + } catch (BindingResolutionException $exception) { + // this exception can occur when requiring spatie/ray in an Orchestra powered + // testsuite without spatie/laravel-ray's service provider being registered + // in `getPackageProviders` of the base test suite + } + } + + if (class_exists(CraftRay::class)) { + return Yii::$container->get(CraftRay::class)->send(...$args); + } + + if (class_exists(YiiRay::class)) { + return Yii::$container->get(YiiRay::class)->send(...$args); + } + + $rayClass = Ray::class; + + if (class_exists(WordPressRay::class)) { + $rayClass = WordPressRay::class; + } + + if (class_exists(SymfonyRay::class)) { + $rayClass = SymfonyRay::class; + } + + $settings = SettingsFactory::createFromConfigFile(); + + return (new $rayClass($settings))->send(...$args); + } + + register_shutdown_function(function () { + ray()->throwExceptions(); + }); +} + +if (! function_exists('rd')) { + function rd(...$args) + { + ray(...$args)->die(); + } +} diff --git a/vendor/symfony/deprecation-contracts/.gitignore b/vendor/symfony/deprecation-contracts/.gitignore new file mode 100644 index 0000000..c49a5d8 --- /dev/null +++ b/vendor/symfony/deprecation-contracts/.gitignore @@ -0,0 +1,3 @@ +vendor/ +composer.lock +phpunit.xml diff --git a/vendor/symfony/deprecation-contracts/CHANGELOG.md b/vendor/symfony/deprecation-contracts/CHANGELOG.md new file mode 100644 index 0000000..7932e26 --- /dev/null +++ b/vendor/symfony/deprecation-contracts/CHANGELOG.md @@ -0,0 +1,5 @@ +CHANGELOG +========= + +The changelog is maintained for all Symfony contracts at the following URL: +https://github.com/symfony/contracts/blob/main/CHANGELOG.md diff --git a/vendor/symfony/deprecation-contracts/LICENSE b/vendor/symfony/deprecation-contracts/LICENSE new file mode 100644 index 0000000..ad85e17 --- /dev/null +++ b/vendor/symfony/deprecation-contracts/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2020-2021 Fabien Potencier + +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/symfony/deprecation-contracts/README.md b/vendor/symfony/deprecation-contracts/README.md new file mode 100644 index 0000000..4957933 --- /dev/null +++ b/vendor/symfony/deprecation-contracts/README.md @@ -0,0 +1,26 @@ +Symfony Deprecation Contracts +============================= + +A generic function and convention to trigger deprecation notices. + +This package provides a single global function named `trigger_deprecation()` that triggers silenced deprecation notices. + +By using a custom PHP error handler such as the one provided by the Symfony ErrorHandler component, +the triggered deprecations can be caught and logged for later discovery, both on dev and prod environments. + +The function requires at least 3 arguments: + - the name of the Composer package that is triggering the deprecation + - the version of the package that introduced the deprecation + - the message of the deprecation + - more arguments can be provided: they will be inserted in the message using `printf()` formatting + +Example: +```php +trigger_deprecation('symfony/blockchain', '8.9', 'Using "%s" is deprecated, use "%s" instead.', 'bitcoin', 'fabcoin'); +``` + +This will generate the following message: +`Since symfony/blockchain 8.9: Using "bitcoin" is deprecated, use "fabcoin" instead.` + +While not necessarily recommended, the deprecation notices can be completely ignored by declaring an empty +`function trigger_deprecation() {}` in your application. diff --git a/vendor/symfony/deprecation-contracts/composer.json b/vendor/symfony/deprecation-contracts/composer.json new file mode 100644 index 0000000..cc7cc12 --- /dev/null +++ b/vendor/symfony/deprecation-contracts/composer.json @@ -0,0 +1,35 @@ +{ + "name": "symfony/deprecation-contracts", + "type": "library", + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=7.1" + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-main": "2.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + } +} diff --git a/vendor/symfony/deprecation-contracts/function.php b/vendor/symfony/deprecation-contracts/function.php new file mode 100644 index 0000000..d437150 --- /dev/null +++ b/vendor/symfony/deprecation-contracts/function.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +if (!function_exists('trigger_deprecation')) { + /** + * Triggers a silenced deprecation notice. + * + * @param string $package The name of the Composer package that is triggering the deprecation + * @param string $version The version of the package that introduced the deprecation + * @param string $message The message of the deprecation + * @param mixed ...$args Values to insert in the message using printf() formatting + * + * @author Nicolas Grekas + */ + function trigger_deprecation(string $package, string $version, string $message, ...$args): void + { + @trigger_error(($package || $version ? "Since $package $version: " : '').($args ? vsprintf($message, $args) : $message), \E_USER_DEPRECATED); + } +} diff --git a/vendor/symfony/polyfill-ctype/Ctype.php b/vendor/symfony/polyfill-ctype/Ctype.php new file mode 100644 index 0000000..ba75a2c --- /dev/null +++ b/vendor/symfony/polyfill-ctype/Ctype.php @@ -0,0 +1,232 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Polyfill\Ctype; + +/** + * Ctype implementation through regex. + * + * @internal + * + * @author Gert de Pagter + */ +final class Ctype +{ + /** + * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise. + * + * @see https://php.net/ctype-alnum + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_alnum($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is a letter, FALSE otherwise. + * + * @see https://php.net/ctype-alpha + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_alpha($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); + } + + /** + * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise. + * + * @see https://php.net/ctype-cntrl + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_cntrl($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); + } + + /** + * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. + * + * @see https://php.net/ctype-digit + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_digit($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise. + * + * @see https://php.net/ctype-graph + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_graph($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); + } + + /** + * Returns TRUE if every character in text is a lowercase letter. + * + * @see https://php.net/ctype-lower + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_lower($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); + } + + /** + * Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all. + * + * @see https://php.net/ctype-print + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_print($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); + } + + /** + * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise. + * + * @see https://php.net/ctype-punct + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_punct($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); + } + + /** + * Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters. + * + * @see https://php.net/ctype-space + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_space($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); + } + + /** + * Returns TRUE if every character in text is an uppercase letter. + * + * @see https://php.net/ctype-upper + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_upper($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); + } + + /** + * Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise. + * + * @see https://php.net/ctype-xdigit + * + * @param mixed $text + * + * @return bool + */ + public static function ctype_xdigit($text) + { + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); + } + + /** + * Converts integers to their char versions according to normal ctype behaviour, if needed. + * + * If an integer between -128 and 255 inclusive is provided, + * it is interpreted as the ASCII value of a single character + * (negative values have 256 added in order to allow characters in the Extended ASCII range). + * Any other integer is interpreted as a string containing the decimal digits of the integer. + * + * @param mixed $int + * @param string $function + * + * @return mixed + */ + private static function convert_int_to_char_for_ctype($int, $function) + { + if (!\is_int($int)) { + return $int; + } + + if ($int < -128 || $int > 255) { + return (string) $int; + } + + if (\PHP_VERSION_ID >= 80100) { + @trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED); + } + + if ($int < 0) { + $int += 256; + } + + return \chr($int); + } +} diff --git a/vendor/symfony/polyfill-ctype/LICENSE b/vendor/symfony/polyfill-ctype/LICENSE new file mode 100644 index 0000000..3f853aa --- /dev/null +++ b/vendor/symfony/polyfill-ctype/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018-2019 Fabien Potencier + +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/symfony/polyfill-ctype/README.md b/vendor/symfony/polyfill-ctype/README.md new file mode 100644 index 0000000..8add1ab --- /dev/null +++ b/vendor/symfony/polyfill-ctype/README.md @@ -0,0 +1,12 @@ +Symfony Polyfill / Ctype +======================== + +This component provides `ctype_*` functions to users who run php versions without the ctype extension. + +More information can be found in the +[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md). + +License +======= + +This library is released under the [MIT license](LICENSE). diff --git a/vendor/symfony/polyfill-ctype/bootstrap.php b/vendor/symfony/polyfill-ctype/bootstrap.php new file mode 100644 index 0000000..d54524b --- /dev/null +++ b/vendor/symfony/polyfill-ctype/bootstrap.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Ctype as p; + +if (\PHP_VERSION_ID >= 80000) { + return require __DIR__.'/bootstrap80.php'; +} + +if (!function_exists('ctype_alnum')) { + function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); } +} +if (!function_exists('ctype_alpha')) { + function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); } +} +if (!function_exists('ctype_cntrl')) { + function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); } +} +if (!function_exists('ctype_digit')) { + function ctype_digit($text) { return p\Ctype::ctype_digit($text); } +} +if (!function_exists('ctype_graph')) { + function ctype_graph($text) { return p\Ctype::ctype_graph($text); } +} +if (!function_exists('ctype_lower')) { + function ctype_lower($text) { return p\Ctype::ctype_lower($text); } +} +if (!function_exists('ctype_print')) { + function ctype_print($text) { return p\Ctype::ctype_print($text); } +} +if (!function_exists('ctype_punct')) { + function ctype_punct($text) { return p\Ctype::ctype_punct($text); } +} +if (!function_exists('ctype_space')) { + function ctype_space($text) { return p\Ctype::ctype_space($text); } +} +if (!function_exists('ctype_upper')) { + function ctype_upper($text) { return p\Ctype::ctype_upper($text); } +} +if (!function_exists('ctype_xdigit')) { + function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); } +} diff --git a/vendor/symfony/polyfill-ctype/bootstrap80.php b/vendor/symfony/polyfill-ctype/bootstrap80.php new file mode 100644 index 0000000..ab2f861 --- /dev/null +++ b/vendor/symfony/polyfill-ctype/bootstrap80.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Ctype as p; + +if (!function_exists('ctype_alnum')) { + function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); } +} +if (!function_exists('ctype_alpha')) { + function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); } +} +if (!function_exists('ctype_cntrl')) { + function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); } +} +if (!function_exists('ctype_digit')) { + function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); } +} +if (!function_exists('ctype_graph')) { + function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); } +} +if (!function_exists('ctype_lower')) { + function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); } +} +if (!function_exists('ctype_print')) { + function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); } +} +if (!function_exists('ctype_punct')) { + function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); } +} +if (!function_exists('ctype_space')) { + function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); } +} +if (!function_exists('ctype_upper')) { + function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); } +} +if (!function_exists('ctype_xdigit')) { + function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); } +} diff --git a/vendor/symfony/polyfill-ctype/composer.json b/vendor/symfony/polyfill-ctype/composer.json new file mode 100644 index 0000000..ccb8e57 --- /dev/null +++ b/vendor/symfony/polyfill-ctype/composer.json @@ -0,0 +1,41 @@ +{ + "name": "symfony/polyfill-ctype", + "type": "library", + "description": "Symfony polyfill for ctype functions", + "keywords": ["polyfill", "compatibility", "portable", "ctype"], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-ctype": "*" + }, + "autoload": { + "psr-4": { "Symfony\\Polyfill\\Ctype\\": "" }, + "files": [ "bootstrap.php" ] + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + } +} diff --git a/vendor/symfony/polyfill-mbstring/Mbstring.php b/vendor/symfony/polyfill-mbstring/Mbstring.php index b599095..b65c54a 100644 --- a/vendor/symfony/polyfill-mbstring/Mbstring.php +++ b/vendor/symfony/polyfill-mbstring/Mbstring.php @@ -80,7 +80,7 @@ final class Mbstring public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) { - if (\is_array($fromEncoding) || false !== strpos($fromEncoding, ',')) { + if (\is_array($fromEncoding) || ($fromEncoding !== null && false !== strpos($fromEncoding, ','))) { $fromEncoding = self::mb_detect_encoding($s, $fromEncoding); } else { $fromEncoding = self::getEncoding($fromEncoding); @@ -602,6 +602,9 @@ public static function mb_substitute_character($c = null) if (80000 > \PHP_VERSION_ID) { return false; } + if (\is_int($c) || 'long' === $c || 'entity' === $c) { + return false; + } throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint'); } diff --git a/vendor/symfony/polyfill-mbstring/composer.json b/vendor/symfony/polyfill-mbstring/composer.json index 2ed7a74..1fa21ca 100644 --- a/vendor/symfony/polyfill-mbstring/composer.json +++ b/vendor/symfony/polyfill-mbstring/composer.json @@ -18,6 +18,9 @@ "require": { "php": ">=7.1" }, + "provide": { + "ext-mbstring": "*" + }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Mbstring\\": "" }, "files": [ "bootstrap.php" ] diff --git a/vendor/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php b/vendor/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php index 7fb2000..37937cb 100644 --- a/vendor/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php +++ b/vendor/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php @@ -1,5 +1,7 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Polyfill\Php81; + +/** + * @author Nicolas Grekas + * + * @internal + */ +final class Php81 +{ + public static function array_is_list(array $array): bool + { + if ([] === $array || $array === array_values($array)) { + return true; + } + + $nextKey = -1; + + foreach ($array as $k => $v) { + if ($k !== ++$nextKey) { + return false; + } + } + + return true; + } +} diff --git a/vendor/symfony/polyfill-php81/README.md b/vendor/symfony/polyfill-php81/README.md new file mode 100644 index 0000000..5ef61be --- /dev/null +++ b/vendor/symfony/polyfill-php81/README.md @@ -0,0 +1,16 @@ +Symfony Polyfill / Php81 +======================== + +This component provides features added to PHP 8.1 core: + +- [`array_is_list`](https://php.net/array_is_list) +- [`MYSQLI_REFRESH_REPLICA`](https://www.php.net/manual/en/mysqli.constants.php#constantmysqli-refresh-replica) constant +- [`ReturnTypeWillChange`](https://wiki.php.net/rfc/internal_method_return_types) + +More information can be found in the +[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md). + +License +======= + +This library is released under the [MIT license](LICENSE). diff --git a/vendor/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php b/vendor/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php new file mode 100644 index 0000000..f4cad34 --- /dev/null +++ b/vendor/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php @@ -0,0 +1,11 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Php81 as p; + +if (\PHP_VERSION_ID >= 80100) { + return; +} + +if (defined('MYSQLI_REFRESH_SLAVE') && !defined('MYSQLI_REFRESH_REPLICA')) { + define('MYSQLI_REFRESH_REPLICA', 64); +} + +if (!function_exists('array_is_list')) { + function array_is_list(array $array): bool { return p\Php81::array_is_list($array); } +} + +if (!function_exists('enum_exists')) { + function enum_exists(string $enum, bool $autoload = true): bool { return $autoload && class_exists($enum) && false; } +} diff --git a/vendor/symfony/polyfill-php81/composer.json b/vendor/symfony/polyfill-php81/composer.json new file mode 100644 index 0000000..c39ccf4 --- /dev/null +++ b/vendor/symfony/polyfill-php81/composer.json @@ -0,0 +1,36 @@ +{ + "name": "symfony/polyfill-php81", + "type": "library", + "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", + "keywords": ["polyfill", "shim", "compatibility", "portable"], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=7.1" + }, + "autoload": { + "psr-4": { "Symfony\\Polyfill\\Php81\\": "" }, + "files": [ "bootstrap.php" ], + "classmap": [ "Resources/stubs" ] + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + } +} diff --git a/vendor/symfony/service-contracts/.gitignore b/vendor/symfony/service-contracts/.gitignore new file mode 100644 index 0000000..c49a5d8 --- /dev/null +++ b/vendor/symfony/service-contracts/.gitignore @@ -0,0 +1,3 @@ +vendor/ +composer.lock +phpunit.xml diff --git a/vendor/symfony/service-contracts/Attribute/Required.php b/vendor/symfony/service-contracts/Attribute/Required.php new file mode 100644 index 0000000..9df8511 --- /dev/null +++ b/vendor/symfony/service-contracts/Attribute/Required.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\Service\Attribute; + +/** + * A required dependency. + * + * This attribute indicates that a property holds a required dependency. The annotated property or method should be + * considered during the instantiation process of the containing class. + * + * @author Alexander M. Turek + */ +#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)] +final class Required +{ +} diff --git a/vendor/symfony/service-contracts/Attribute/SubscribedService.php b/vendor/symfony/service-contracts/Attribute/SubscribedService.php new file mode 100644 index 0000000..10d1bc3 --- /dev/null +++ b/vendor/symfony/service-contracts/Attribute/SubscribedService.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\Service\Attribute; + +use Symfony\Contracts\Service\ServiceSubscriberTrait; + +/** + * Use with {@see ServiceSubscriberTrait} to mark a method's return type + * as a subscribed service. + * + * @author Kevin Bond + */ +#[\Attribute(\Attribute::TARGET_METHOD)] +final class SubscribedService +{ + /** + * @param string|null $key The key to use for the service + * If null, use "ClassName::methodName" + */ + public function __construct( + public ?string $key = null + ) { + } +} diff --git a/vendor/symfony/service-contracts/CHANGELOG.md b/vendor/symfony/service-contracts/CHANGELOG.md new file mode 100644 index 0000000..7932e26 --- /dev/null +++ b/vendor/symfony/service-contracts/CHANGELOG.md @@ -0,0 +1,5 @@ +CHANGELOG +========= + +The changelog is maintained for all Symfony contracts at the following URL: +https://github.com/symfony/contracts/blob/main/CHANGELOG.md diff --git a/vendor/symfony/service-contracts/LICENSE b/vendor/symfony/service-contracts/LICENSE new file mode 100644 index 0000000..2358414 --- /dev/null +++ b/vendor/symfony/service-contracts/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018-2021 Fabien Potencier + +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/symfony/service-contracts/README.md b/vendor/symfony/service-contracts/README.md new file mode 100644 index 0000000..41e054a --- /dev/null +++ b/vendor/symfony/service-contracts/README.md @@ -0,0 +1,9 @@ +Symfony Service Contracts +========================= + +A set of abstractions extracted out of the Symfony components. + +Can be used to build on semantics that the Symfony components proved useful - and +that already have battle tested implementations. + +See https://github.com/symfony/contracts/blob/main/README.md for more information. diff --git a/vendor/symfony/service-contracts/ResetInterface.php b/vendor/symfony/service-contracts/ResetInterface.php new file mode 100644 index 0000000..1af1075 --- /dev/null +++ b/vendor/symfony/service-contracts/ResetInterface.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\Service; + +/** + * Provides a way to reset an object to its initial state. + * + * When calling the "reset()" method on an object, it should be put back to its + * initial state. This usually means clearing any internal buffers and forwarding + * the call to internal dependencies. All properties of the object should be put + * back to the same state it had when it was first ready to use. + * + * This method could be called, for example, to recycle objects that are used as + * services, so that they can be used to handle several requests in the same + * process loop (note that we advise making your services stateless instead of + * implementing this interface when possible.) + */ +interface ResetInterface +{ + public function reset(); +} diff --git a/vendor/symfony/service-contracts/ServiceLocatorTrait.php b/vendor/symfony/service-contracts/ServiceLocatorTrait.php new file mode 100644 index 0000000..74dfa43 --- /dev/null +++ b/vendor/symfony/service-contracts/ServiceLocatorTrait.php @@ -0,0 +1,128 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\Service; + +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; + +// Help opcache.preload discover always-needed symbols +class_exists(ContainerExceptionInterface::class); +class_exists(NotFoundExceptionInterface::class); + +/** + * A trait to help implement ServiceProviderInterface. + * + * @author Robin Chalas + * @author Nicolas Grekas + */ +trait ServiceLocatorTrait +{ + private $factories; + private $loading = []; + private $providedTypes; + + /** + * @param callable[] $factories + */ + public function __construct(array $factories) + { + $this->factories = $factories; + } + + /** + * {@inheritdoc} + * + * @return bool + */ + public function has(string $id) + { + return isset($this->factories[$id]); + } + + /** + * {@inheritdoc} + * + * @return mixed + */ + public function get(string $id) + { + if (!isset($this->factories[$id])) { + throw $this->createNotFoundException($id); + } + + if (isset($this->loading[$id])) { + $ids = array_values($this->loading); + $ids = \array_slice($this->loading, array_search($id, $ids)); + $ids[] = $id; + + throw $this->createCircularReferenceException($id, $ids); + } + + $this->loading[$id] = $id; + try { + return $this->factories[$id]($this); + } finally { + unset($this->loading[$id]); + } + } + + /** + * {@inheritdoc} + */ + public function getProvidedServices(): array + { + if (null === $this->providedTypes) { + $this->providedTypes = []; + + foreach ($this->factories as $name => $factory) { + if (!\is_callable($factory)) { + $this->providedTypes[$name] = '?'; + } else { + $type = (new \ReflectionFunction($factory))->getReturnType(); + + $this->providedTypes[$name] = $type ? ($type->allowsNull() ? '?' : '').($type instanceof \ReflectionNamedType ? $type->getName() : $type) : '?'; + } + } + } + + return $this->providedTypes; + } + + private function createNotFoundException(string $id): NotFoundExceptionInterface + { + if (!$alternatives = array_keys($this->factories)) { + $message = 'is empty...'; + } else { + $last = array_pop($alternatives); + if ($alternatives) { + $message = sprintf('only knows about the "%s" and "%s" services.', implode('", "', $alternatives), $last); + } else { + $message = sprintf('only knows about the "%s" service.', $last); + } + } + + if ($this->loading) { + $message = sprintf('The service "%s" has a dependency on a non-existent service "%s". This locator %s', end($this->loading), $id, $message); + } else { + $message = sprintf('Service "%s" not found: the current service locator %s', $id, $message); + } + + return new class($message) extends \InvalidArgumentException implements NotFoundExceptionInterface { + }; + } + + private function createCircularReferenceException(string $id, array $path): ContainerExceptionInterface + { + return new class(sprintf('Circular reference detected for service "%s", path: "%s".', $id, implode(' -> ', $path))) extends \RuntimeException implements ContainerExceptionInterface { + }; + } +} diff --git a/vendor/symfony/service-contracts/ServiceProviderInterface.php b/vendor/symfony/service-contracts/ServiceProviderInterface.php new file mode 100644 index 0000000..c60ad0b --- /dev/null +++ b/vendor/symfony/service-contracts/ServiceProviderInterface.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\Service; + +use Psr\Container\ContainerInterface; + +/** + * A ServiceProviderInterface exposes the identifiers and the types of services provided by a container. + * + * @author Nicolas Grekas + * @author Mateusz Sip + */ +interface ServiceProviderInterface extends ContainerInterface +{ + /** + * Returns an associative array of service types keyed by the identifiers provided by the current container. + * + * Examples: + * + * * ['logger' => 'Psr\Log\LoggerInterface'] means the object provides a service named "logger" that implements Psr\Log\LoggerInterface + * * ['foo' => '?'] means the container provides service name "foo" of unspecified type + * * ['bar' => '?Bar\Baz'] means the container provides a service "bar" of type Bar\Baz|null + * + * @return string[] The provided service types, keyed by service names + */ + public function getProvidedServices(): array; +} diff --git a/vendor/symfony/service-contracts/ServiceSubscriberInterface.php b/vendor/symfony/service-contracts/ServiceSubscriberInterface.php new file mode 100644 index 0000000..098ab90 --- /dev/null +++ b/vendor/symfony/service-contracts/ServiceSubscriberInterface.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\Service; + +/** + * A ServiceSubscriber exposes its dependencies via the static {@link getSubscribedServices} method. + * + * The getSubscribedServices method returns an array of service types required by such instances, + * optionally keyed by the service names used internally. Service types that start with an interrogation + * mark "?" are optional, while the other ones are mandatory service dependencies. + * + * The injected service locators SHOULD NOT allow access to any other services not specified by the method. + * + * It is expected that ServiceSubscriber instances consume PSR-11-based service locators internally. + * This interface does not dictate any injection method for these service locators, although constructor + * injection is recommended. + * + * @author Nicolas Grekas + */ +interface ServiceSubscriberInterface +{ + /** + * Returns an array of service types required by such instances, optionally keyed by the service names used internally. + * + * For mandatory dependencies: + * + * * ['logger' => 'Psr\Log\LoggerInterface'] means the objects use the "logger" name + * internally to fetch a service which must implement Psr\Log\LoggerInterface. + * * ['loggers' => 'Psr\Log\LoggerInterface[]'] means the objects use the "loggers" name + * internally to fetch an iterable of Psr\Log\LoggerInterface instances. + * * ['Psr\Log\LoggerInterface'] is a shortcut for + * * ['Psr\Log\LoggerInterface' => 'Psr\Log\LoggerInterface'] + * + * otherwise: + * + * * ['logger' => '?Psr\Log\LoggerInterface'] denotes an optional dependency + * * ['loggers' => '?Psr\Log\LoggerInterface[]'] denotes an optional iterable dependency + * * ['?Psr\Log\LoggerInterface'] is a shortcut for + * * ['Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface'] + * + * @return string[] The required service types, optionally keyed by service names + */ + public static function getSubscribedServices(); +} diff --git a/vendor/symfony/service-contracts/ServiceSubscriberTrait.php b/vendor/symfony/service-contracts/ServiceSubscriberTrait.php new file mode 100644 index 0000000..46cd007 --- /dev/null +++ b/vendor/symfony/service-contracts/ServiceSubscriberTrait.php @@ -0,0 +1,115 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\Service; + +use Psr\Container\ContainerInterface; +use Symfony\Contracts\Service\Attribute\SubscribedService; + +/** + * Implementation of ServiceSubscriberInterface that determines subscribed services from + * method return types. Service ids are available as "ClassName::methodName". + * + * @author Kevin Bond + */ +trait ServiceSubscriberTrait +{ + /** @var ContainerInterface */ + protected $container; + + /** + * {@inheritdoc} + */ + public static function getSubscribedServices(): array + { + static $services; + + if (null !== $services) { + return $services; + } + + $services = \is_callable(['parent', __FUNCTION__]) ? parent::getSubscribedServices() : []; + $attributeOptIn = false; + + if (\PHP_VERSION_ID >= 80000) { + foreach ((new \ReflectionClass(self::class))->getMethods() as $method) { + if (self::class !== $method->getDeclaringClass()->name) { + continue; + } + + if (!$attribute = $method->getAttributes(SubscribedService::class)[0] ?? null) { + continue; + } + + if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) { + throw new \LogicException(sprintf('Cannot use "%s" on method "%s::%s()" (can only be used on non-static, non-abstract methods with no parameters).', SubscribedService::class, self::class, $method->name)); + } + + if (!$returnType = $method->getReturnType()) { + throw new \LogicException(sprintf('Cannot use "%s" on methods without a return type in "%s::%s()".', SubscribedService::class, $method->name, self::class)); + } + + $serviceId = $returnType instanceof \ReflectionNamedType ? $returnType->getName() : (string) $returnType; + + if ($returnType->allowsNull()) { + $serviceId = '?'.$serviceId; + } + + $services[$attribute->newInstance()->key ?? self::class.'::'.$method->name] = $serviceId; + $attributeOptIn = true; + } + } + + if (!$attributeOptIn) { + foreach ((new \ReflectionClass(self::class))->getMethods() as $method) { + if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) { + continue; + } + + if (self::class !== $method->getDeclaringClass()->name) { + continue; + } + + if (!($returnType = $method->getReturnType()) instanceof \ReflectionNamedType) { + continue; + } + + if ($returnType->isBuiltin()) { + continue; + } + + if (\PHP_VERSION_ID >= 80000) { + trigger_deprecation('symfony/service-contracts', '2.5', 'Using "%s" in "%s" without using the "%s" attribute on any method is deprecated.', ServiceSubscriberTrait::class, self::class, SubscribedService::class); + } + + $services[self::class.'::'.$method->name] = '?'.($returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType); + } + } + + return $services; + } + + /** + * @required + * + * @return ContainerInterface|null + */ + public function setContainer(ContainerInterface $container) + { + $this->container = $container; + + if (\is_callable(['parent', __FUNCTION__])) { + return parent::setContainer($container); + } + + return null; + } +} diff --git a/vendor/symfony/service-contracts/Test/ServiceLocatorTest.php b/vendor/symfony/service-contracts/Test/ServiceLocatorTest.php new file mode 100644 index 0000000..2a1b565 --- /dev/null +++ b/vendor/symfony/service-contracts/Test/ServiceLocatorTest.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\Service\Test; + +use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerInterface; +use Symfony\Contracts\Service\ServiceLocatorTrait; + +abstract class ServiceLocatorTest extends TestCase +{ + /** + * @return ContainerInterface + */ + protected function getServiceLocator(array $factories) + { + return new class($factories) implements ContainerInterface { + use ServiceLocatorTrait; + }; + } + + public function testHas() + { + $locator = $this->getServiceLocator([ + 'foo' => function () { return 'bar'; }, + 'bar' => function () { return 'baz'; }, + function () { return 'dummy'; }, + ]); + + $this->assertTrue($locator->has('foo')); + $this->assertTrue($locator->has('bar')); + $this->assertFalse($locator->has('dummy')); + } + + public function testGet() + { + $locator = $this->getServiceLocator([ + 'foo' => function () { return 'bar'; }, + 'bar' => function () { return 'baz'; }, + ]); + + $this->assertSame('bar', $locator->get('foo')); + $this->assertSame('baz', $locator->get('bar')); + } + + public function testGetDoesNotMemoize() + { + $i = 0; + $locator = $this->getServiceLocator([ + 'foo' => function () use (&$i) { + ++$i; + + return 'bar'; + }, + ]); + + $this->assertSame('bar', $locator->get('foo')); + $this->assertSame('bar', $locator->get('foo')); + $this->assertSame(2, $i); + } + + public function testThrowsOnUndefinedInternalService() + { + if (!$this->getExpectedException()) { + $this->expectException(\Psr\Container\NotFoundExceptionInterface::class); + $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); + } + $locator = $this->getServiceLocator([ + 'foo' => function () use (&$locator) { return $locator->get('bar'); }, + ]); + + $locator->get('foo'); + } + + public function testThrowsOnCircularReference() + { + $this->expectException(\Psr\Container\ContainerExceptionInterface::class); + $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); + $locator = $this->getServiceLocator([ + 'foo' => function () use (&$locator) { return $locator->get('bar'); }, + 'bar' => function () use (&$locator) { return $locator->get('baz'); }, + 'baz' => function () use (&$locator) { return $locator->get('bar'); }, + ]); + + $locator->get('foo'); + } +} diff --git a/vendor/symfony/service-contracts/composer.json b/vendor/symfony/service-contracts/composer.json new file mode 100644 index 0000000..e680798 --- /dev/null +++ b/vendor/symfony/service-contracts/composer.json @@ -0,0 +1,42 @@ +{ + "name": "symfony/service-contracts", + "type": "library", + "description": "Generic abstractions related to writing services", + "keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=7.2.5", + "psr/container": "^1.1", + "symfony/deprecation-contracts": "^2.1" + }, + "conflict": { + "ext-psr": "<1.1|>=2" + }, + "suggest": { + "symfony/service-implementation": "" + }, + "autoload": { + "psr-4": { "Symfony\\Contracts\\Service\\": "" } + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-main": "2.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + } +} diff --git a/vendor/symfony/stopwatch/CHANGELOG.md b/vendor/symfony/stopwatch/CHANGELOG.md new file mode 100644 index 0000000..f2fd7d0 --- /dev/null +++ b/vendor/symfony/stopwatch/CHANGELOG.md @@ -0,0 +1,24 @@ +CHANGELOG +========= + +5.2 +--- + + * Add `name` argument to the `StopWatchEvent` constructor, accessible via a new `StopwatchEvent::getName()` + +5.0.0 +----- + + * Removed support for passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead. + +4.4.0 +----- + + * Deprecated passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead. + +3.4.0 +----- + + * added the `Stopwatch::reset()` method + * allowed to measure sub-millisecond times by introducing an argument to the + constructor of `Stopwatch` diff --git a/vendor/symfony/stopwatch/LICENSE b/vendor/symfony/stopwatch/LICENSE new file mode 100644 index 0000000..88bf75b --- /dev/null +++ b/vendor/symfony/stopwatch/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2004-2022 Fabien Potencier + +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/symfony/stopwatch/README.md b/vendor/symfony/stopwatch/README.md new file mode 100644 index 0000000..13a9dfa --- /dev/null +++ b/vendor/symfony/stopwatch/README.md @@ -0,0 +1,42 @@ +Stopwatch Component +=================== + +The Stopwatch component provides a way to profile code. + +Getting Started +--------------- + +``` +$ composer require symfony/stopwatch +``` + +```php +use Symfony\Component\Stopwatch\Stopwatch; + +$stopwatch = new Stopwatch(); + +// optionally group events into sections (e.g. phases of the execution) +$stopwatch->openSection(); + +// starts event named 'eventName' +$stopwatch->start('eventName'); + +// ... run your code here + +// optionally, start a new "lap" time +$stopwatch->lap('foo'); + +// ... run your code here + +$event = $stopwatch->stop('eventName'); + +$stopwatch->stopSection('phase_1'); +``` + +Resources +--------- + + * [Contributing](https://symfony.com/doc/current/contributing/index.html) + * [Report issues](https://github.com/symfony/symfony/issues) and + [send Pull Requests](https://github.com/symfony/symfony/pulls) + in the [main Symfony repository](https://github.com/symfony/symfony) diff --git a/vendor/symfony/stopwatch/Section.php b/vendor/symfony/stopwatch/Section.php new file mode 100644 index 0000000..56cdc6f --- /dev/null +++ b/vendor/symfony/stopwatch/Section.php @@ -0,0 +1,185 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Stopwatch; + +/** + * Stopwatch section. + * + * @author Fabien Potencier + */ +class Section +{ + /** + * @var StopwatchEvent[] + */ + private $events = []; + + /** + * @var float|null + */ + private $origin; + + /** + * @var bool + */ + private $morePrecision; + + /** + * @var string + */ + private $id; + + /** + * @var Section[] + */ + private $children = []; + + /** + * @param float|null $origin Set the origin of the events in this section, use null to set their origin to their start time + * @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision + */ + public function __construct(float $origin = null, bool $morePrecision = false) + { + $this->origin = $origin; + $this->morePrecision = $morePrecision; + } + + /** + * Returns the child section. + * + * @return self|null + */ + public function get(string $id) + { + foreach ($this->children as $child) { + if ($id === $child->getId()) { + return $child; + } + } + + return null; + } + + /** + * Creates or re-opens a child section. + * + * @param string|null $id Null to create a new section, the identifier to re-open an existing one + * + * @return self + */ + public function open(?string $id) + { + if (null === $id || null === $session = $this->get($id)) { + $session = $this->children[] = new self(microtime(true) * 1000, $this->morePrecision); + } + + return $session; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Sets the session identifier. + * + * @return $this + */ + public function setId(string $id) + { + $this->id = $id; + + return $this; + } + + /** + * Starts an event. + * + * @return StopwatchEvent + */ + public function startEvent(string $name, ?string $category) + { + if (!isset($this->events[$name])) { + $this->events[$name] = new StopwatchEvent($this->origin ?: microtime(true) * 1000, $category, $this->morePrecision, $name); + } + + return $this->events[$name]->start(); + } + + /** + * Checks if the event was started. + * + * @return bool + */ + public function isEventStarted(string $name) + { + return isset($this->events[$name]) && $this->events[$name]->isStarted(); + } + + /** + * Stops an event. + * + * @return StopwatchEvent + * + * @throws \LogicException When the event has not been started + */ + public function stopEvent(string $name) + { + if (!isset($this->events[$name])) { + throw new \LogicException(sprintf('Event "%s" is not started.', $name)); + } + + return $this->events[$name]->stop(); + } + + /** + * Stops then restarts an event. + * + * @return StopwatchEvent + * + * @throws \LogicException When the event has not been started + */ + public function lap(string $name) + { + return $this->stopEvent($name)->start(); + } + + /** + * Returns a specific event by name. + * + * @return StopwatchEvent + * + * @throws \LogicException When the event is not known + */ + public function getEvent(string $name) + { + if (!isset($this->events[$name])) { + throw new \LogicException(sprintf('Event "%s" is not known.', $name)); + } + + return $this->events[$name]; + } + + /** + * Returns the events from this section. + * + * @return StopwatchEvent[] + */ + public function getEvents() + { + return $this->events; + } +} diff --git a/vendor/symfony/stopwatch/Stopwatch.php b/vendor/symfony/stopwatch/Stopwatch.php new file mode 100644 index 0000000..2f46c59 --- /dev/null +++ b/vendor/symfony/stopwatch/Stopwatch.php @@ -0,0 +1,166 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Stopwatch; + +use Symfony\Contracts\Service\ResetInterface; + +// Help opcache.preload discover always-needed symbols +class_exists(Section::class); + +/** + * Stopwatch provides a way to profile code. + * + * @author Fabien Potencier + */ +class Stopwatch implements ResetInterface +{ + /** + * @var bool + */ + private $morePrecision; + + /** + * @var Section[] + */ + private $sections; + + /** + * @var Section[] + */ + private $activeSections; + + /** + * @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision + */ + public function __construct(bool $morePrecision = false) + { + $this->morePrecision = $morePrecision; + $this->reset(); + } + + /** + * @return Section[] + */ + public function getSections() + { + return $this->sections; + } + + /** + * Creates a new section or re-opens an existing section. + * + * @param string|null $id The id of the session to re-open, null to create a new one + * + * @throws \LogicException When the section to re-open is not reachable + */ + public function openSection(string $id = null) + { + $current = end($this->activeSections); + + if (null !== $id && null === $current->get($id)) { + throw new \LogicException(sprintf('The section "%s" has been started at an other level and cannot be opened.', $id)); + } + + $this->start('__section__.child', 'section'); + $this->activeSections[] = $current->open($id); + $this->start('__section__'); + } + + /** + * Stops the last started section. + * + * The id parameter is used to retrieve the events from this section. + * + * @see getSectionEvents() + * + * @throws \LogicException When there's no started section to be stopped + */ + public function stopSection(string $id) + { + $this->stop('__section__'); + + if (1 == \count($this->activeSections)) { + throw new \LogicException('There is no started section to stop.'); + } + + $this->sections[$id] = array_pop($this->activeSections)->setId($id); + $this->stop('__section__.child'); + } + + /** + * Starts an event. + * + * @return StopwatchEvent + */ + public function start(string $name, string $category = null) + { + return end($this->activeSections)->startEvent($name, $category); + } + + /** + * Checks if the event was started. + * + * @return bool + */ + public function isStarted(string $name) + { + return end($this->activeSections)->isEventStarted($name); + } + + /** + * Stops an event. + * + * @return StopwatchEvent + */ + public function stop(string $name) + { + return end($this->activeSections)->stopEvent($name); + } + + /** + * Stops then restarts an event. + * + * @return StopwatchEvent + */ + public function lap(string $name) + { + return end($this->activeSections)->stopEvent($name)->start(); + } + + /** + * Returns a specific event by name. + * + * @return StopwatchEvent + */ + public function getEvent(string $name) + { + return end($this->activeSections)->getEvent($name); + } + + /** + * Gets all events for a given section. + * + * @return StopwatchEvent[] + */ + public function getSectionEvents(string $id) + { + return isset($this->sections[$id]) ? $this->sections[$id]->getEvents() : []; + } + + /** + * Resets the stopwatch to its original state. + */ + public function reset() + { + $this->sections = $this->activeSections = ['__root__' => new Section(null, $this->morePrecision)]; + } +} diff --git a/vendor/symfony/stopwatch/StopwatchEvent.php b/vendor/symfony/stopwatch/StopwatchEvent.php new file mode 100644 index 0000000..945bc70 --- /dev/null +++ b/vendor/symfony/stopwatch/StopwatchEvent.php @@ -0,0 +1,258 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Stopwatch; + +/** + * Represents an Event managed by Stopwatch. + * + * @author Fabien Potencier + */ +class StopwatchEvent +{ + /** + * @var StopwatchPeriod[] + */ + private $periods = []; + + /** + * @var float + */ + private $origin; + + /** + * @var string + */ + private $category; + + /** + * @var bool + */ + private $morePrecision; + + /** + * @var float[] + */ + private $started = []; + + /** + * @var string + */ + private $name; + + /** + * @param float $origin The origin time in milliseconds + * @param string|null $category The event category or null to use the default + * @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision + * @param string|null $name The event name or null to define the name as default + * + * @throws \InvalidArgumentException When the raw time is not valid + */ + public function __construct(float $origin, string $category = null, bool $morePrecision = false, string $name = null) + { + $this->origin = $this->formatTime($origin); + $this->category = \is_string($category) ? $category : 'default'; + $this->morePrecision = $morePrecision; + $this->name = $name ?? 'default'; + } + + /** + * Gets the category. + * + * @return string + */ + public function getCategory() + { + return $this->category; + } + + /** + * Gets the origin in milliseconds. + * + * @return float + */ + public function getOrigin() + { + return $this->origin; + } + + /** + * Starts a new event period. + * + * @return $this + */ + public function start() + { + $this->started[] = $this->getNow(); + + return $this; + } + + /** + * Stops the last started event period. + * + * @return $this + * + * @throws \LogicException When stop() is called without a matching call to start() + */ + public function stop() + { + if (!\count($this->started)) { + throw new \LogicException('stop() called but start() has not been called before.'); + } + + $this->periods[] = new StopwatchPeriod(array_pop($this->started), $this->getNow(), $this->morePrecision); + + return $this; + } + + /** + * Checks if the event was started. + * + * @return bool + */ + public function isStarted() + { + return !empty($this->started); + } + + /** + * Stops the current period and then starts a new one. + * + * @return $this + */ + public function lap() + { + return $this->stop()->start(); + } + + /** + * Stops all non already stopped periods. + */ + public function ensureStopped() + { + while (\count($this->started)) { + $this->stop(); + } + } + + /** + * Gets all event periods. + * + * @return StopwatchPeriod[] + */ + public function getPeriods() + { + return $this->periods; + } + + /** + * Gets the relative time of the start of the first period in milliseconds. + * + * @return int|float + */ + public function getStartTime() + { + if (isset($this->periods[0])) { + return $this->periods[0]->getStartTime(); + } + + if ($this->started) { + return $this->started[0]; + } + + return 0; + } + + /** + * Gets the relative time of the end of the last period in milliseconds. + * + * @return int|float + */ + public function getEndTime() + { + $count = \count($this->periods); + + return $count ? $this->periods[$count - 1]->getEndTime() : 0; + } + + /** + * Gets the duration of the events in milliseconds (including all periods). + * + * @return int|float + */ + public function getDuration() + { + $periods = $this->periods; + $left = \count($this->started); + + for ($i = $left - 1; $i >= 0; --$i) { + $periods[] = new StopwatchPeriod($this->started[$i], $this->getNow(), $this->morePrecision); + } + + $total = 0; + foreach ($periods as $period) { + $total += $period->getDuration(); + } + + return $total; + } + + /** + * Gets the max memory usage of all periods in bytes. + * + * @return int + */ + public function getMemory() + { + $memory = 0; + foreach ($this->periods as $period) { + if ($period->getMemory() > $memory) { + $memory = $period->getMemory(); + } + } + + return $memory; + } + + /** + * Return the current time relative to origin in milliseconds. + * + * @return float + */ + protected function getNow() + { + return $this->formatTime(microtime(true) * 1000 - $this->origin); + } + + /** + * Formats a time. + * + * @throws \InvalidArgumentException When the raw time is not valid + */ + private function formatTime(float $time): float + { + return round($time, 1); + } + + /** + * Gets the event name. + */ + public function getName(): string + { + return $this->name; + } + + public function __toString(): string + { + return sprintf('%s/%s: %.2F MiB - %d ms', $this->getCategory(), $this->getName(), $this->getMemory() / 1024 / 1024, $this->getDuration()); + } +} diff --git a/vendor/symfony/stopwatch/StopwatchPeriod.php b/vendor/symfony/stopwatch/StopwatchPeriod.php new file mode 100644 index 0000000..7a7ae1a --- /dev/null +++ b/vendor/symfony/stopwatch/StopwatchPeriod.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Stopwatch; + +/** + * Represents an Period for an Event. + * + * @author Fabien Potencier + */ +class StopwatchPeriod +{ + private $start; + private $end; + private $memory; + + /** + * @param int|float $start The relative time of the start of the period (in milliseconds) + * @param int|float $end The relative time of the end of the period (in milliseconds) + * @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision + */ + public function __construct($start, $end, bool $morePrecision = false) + { + $this->start = $morePrecision ? (float) $start : (int) $start; + $this->end = $morePrecision ? (float) $end : (int) $end; + $this->memory = memory_get_usage(true); + } + + /** + * Gets the relative time of the start of the period in milliseconds. + * + * @return int|float + */ + public function getStartTime() + { + return $this->start; + } + + /** + * Gets the relative time of the end of the period in milliseconds. + * + * @return int|float + */ + public function getEndTime() + { + return $this->end; + } + + /** + * Gets the time spent in this period in milliseconds. + * + * @return int|float + */ + public function getDuration() + { + return $this->end - $this->start; + } + + /** + * Gets the memory usage in bytes. + * + * @return int + */ + public function getMemory() + { + return $this->memory; + } + + public function __toString(): string + { + return sprintf('%.2F MiB - %d ms', $this->getMemory() / 1024 / 1024, $this->getDuration()); + } +} diff --git a/vendor/symfony/stopwatch/composer.json b/vendor/symfony/stopwatch/composer.json new file mode 100644 index 0000000..ed918d3 --- /dev/null +++ b/vendor/symfony/stopwatch/composer.json @@ -0,0 +1,29 @@ +{ + "name": "symfony/stopwatch", + "type": "library", + "description": "Provides a way to profile code", + "keywords": [], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=7.2.5", + "symfony/service-contracts": "^1|^2|^3" + }, + "autoload": { + "psr-4": { "Symfony\\Component\\Stopwatch\\": "" }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "minimum-stability": "dev" +} diff --git a/vendor/symfony/var-dumper/Dumper/ContextProvider/ContextProviderInterface.php b/vendor/symfony/var-dumper/Dumper/ContextProvider/ContextProviderInterface.php index 6a5a006..532aa0f 100644 --- a/vendor/symfony/var-dumper/Dumper/ContextProvider/ContextProviderInterface.php +++ b/vendor/symfony/var-dumper/Dumper/ContextProvider/ContextProviderInterface.php @@ -18,8 +18,5 @@ */ interface ContextProviderInterface { - /** - * @return array|null - */ public function getContext(): ?array; } diff --git a/vendor/symfony/var-dumper/LICENSE b/vendor/symfony/var-dumper/LICENSE index c1f0aac..a843ec1 100644 --- a/vendor/symfony/var-dumper/LICENSE +++ b/vendor/symfony/var-dumper/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2021 Fabien Potencier +Copyright (c) 2014-2022 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vendor/tightenco/collect/.github/workflows/run-tests.yml b/vendor/tightenco/collect/.github/workflows/run-tests.yml index 8e6c244..2a0d42f 100644 --- a/vendor/tightenco/collect/.github/workflows/run-tests.yml +++ b/vendor/tightenco/collect/.github/workflows/run-tests.yml @@ -1,13 +1,16 @@ name: Run tests -on: [push, pull_request] +on: + push: + branches: [laravel-9-ongoing, laravel-8-ongoing] + pull_request: jobs: tests: strategy: matrix: os: [Ubuntu, macOS] - php: [7.2, 7.3, 7.4, 8.0, 8.1] + php: [7.3, 7.4, 8.0, 8.1] include: - os: Ubuntu diff --git a/vendor/tightenco/collect/composer.json b/vendor/tightenco/collect/composer.json index fffeed4..88ebb77 100644 --- a/vendor/tightenco/collect/composer.json +++ b/vendor/tightenco/collect/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "^7.2|^8.0", + "php": "^7.3|^8.0", "symfony/var-dumper": "^3.4 || ^4.0 || ^5.0 || ^6.0" }, "require-dev": { diff --git a/vendor/tightenco/collect/src/Collect/Support/Collection.php b/vendor/tightenco/collect/src/Collect/Support/Collection.php index 5f73d55..577e351 100644 --- a/vendor/tightenco/collect/src/Collect/Support/Collection.php +++ b/vendor/tightenco/collect/src/Collect/Support/Collection.php @@ -176,6 +176,19 @@ public function contains($key, $operator = null, $value = null) return $this->contains($this->operatorForWhere(...func_get_args())); } + /** + * Determine if an item is not contained in the collection. + * + * @param mixed $key + * @param mixed $operator + * @param mixed $value + * @return bool + */ + public function doesntContain($key, $operator = null, $value = null) + { + return ! $this->contains(...func_get_args()); + } + /** * Cross join with the given lists, returning all possible permutations. * @@ -384,7 +397,7 @@ public function flip() /** * Remove an item from the collection by key. * - * @param string|array $keys + * @param string|int|array $keys * @return $this */ public function forget($keys) @@ -412,6 +425,24 @@ public function get($key, $default = null) return value($default); } + /** + * Get an item from the collection by key or add it to collection if it does not exist. + * + * @param mixed $key + * @param mixed $value + * @return mixed + */ + public function getOrPut($key, $value) + { + if (array_key_exists($key, $this->items)) { + return $this->items[$key]; + } + + $this->offsetSet($key, $value = value($value)); + + return $value; + } + /** * Group an associative array by a field or using a callback. * @@ -1267,7 +1298,7 @@ public function sortBy($callback, $options = SORT_REGULAR, $descending = false) // First we will loop through the items and get the comparator from a callback // function which we were given. Then, we will sort the returned values and - // and grab the corresponding values for the sorted keys from this array. + // grab all the corresponding values for the sorted keys from this array. foreach ($this->items as $key => $value) { $results[$key] = $callback($value, $key); } @@ -1306,7 +1337,7 @@ protected function sortByMany(array $comparisons = []) $result = 0; - if (is_callable($prop)) { + if (! is_string($prop) && is_callable($prop)) { $result = $prop($a, $b); } else { $values = [data_get($a, $prop), data_get($b, $prop)]; @@ -1368,6 +1399,21 @@ public function sortKeysDesc($options = SORT_REGULAR) return $this->sortKeys($options, true); } + /** + * Sort the collection keys using a callback. + * + * @param callable $callback + * @return static + */ + public function sortKeysUsing(callable $callback) + { + $items = $this->items; + + uksort($items, $callback); + + return new static($items); + } + /** * Splice a portion of the underlying collection array. * @@ -1615,7 +1661,7 @@ public function offsetSet($key, $value) /** * Unset the item at a given offset. * - * @param string $key + * @param mixed $key * @return void */ #[\ReturnTypeWillChange] diff --git a/vendor/tightenco/collect/src/Collect/Support/LazyCollection.php b/vendor/tightenco/collect/src/Collect/Support/LazyCollection.php index 17cdf2a..464cee1 100644 --- a/vendor/tightenco/collect/src/Collect/Support/LazyCollection.php +++ b/vendor/tightenco/collect/src/Collect/Support/LazyCollection.php @@ -205,6 +205,19 @@ public function contains($key, $operator = null, $value = null) return $this->contains($this->operatorForWhere(...func_get_args())); } + /** + * Determine if an item is not contained in the enumerable. + * + * @param mixed $key + * @param mixed $operator + * @param mixed $value + * @return bool + */ + public function doesntContain($key, $operator = null, $value = null) + { + return ! $this->contains(...func_get_args()); + } + /** * Cross join the given iterables, returning all possible permutations. * @@ -1275,6 +1288,17 @@ public function sortKeysDesc($options = SORT_REGULAR) return $this->passthru('sortKeysDesc', func_get_args()); } + /** + * Sort the collection keys using a callback. + * + * @param callable $callback + * @return static + */ + public function sortKeysUsing(callable $callback) + { + return $this->passthru('sortKeysUsing', func_get_args()); + } + /** * Take the first or last {$limit} items. * diff --git a/vendor/tightenco/collect/src/Collect/Support/Traits/EnumeratesValues.php b/vendor/tightenco/collect/src/Collect/Support/Traits/EnumeratesValues.php index facb5ea..955641b 100644 --- a/vendor/tightenco/collect/src/Collect/Support/Traits/EnumeratesValues.php +++ b/vendor/tightenco/collect/src/Collect/Support/Traits/EnumeratesValues.php @@ -721,6 +721,22 @@ public function pipeInto($class) return new $class($this); } + /** + * Pass the collection through a series of callable pipes and return the result. + * + * @param array $pipes + * @return mixed + */ + public function pipeThrough($pipes) + { + return static::make($pipes)->reduce( + function ($carry, $pipe) { + return $pipe($carry); + }, + $this, + ); + } + /** * Pass the collection to the given callback and then return it. * diff --git a/vendor/tightenco/collect/src/Collect/Support/helpers.php b/vendor/tightenco/collect/src/Collect/Support/helpers.php index aa0270c..886a141 100644 --- a/vendor/tightenco/collect/src/Collect/Support/helpers.php +++ b/vendor/tightenco/collect/src/Collect/Support/helpers.php @@ -6,19 +6,6 @@ use Symfony\Component\VarDumper\VarDumper; if (! class_exists(Illuminate\Support\Collection::class)) { - if (! function_exists('array_wrap')) { - /** - * If the given value is not an array, wrap it in one. - * - * @param mixed $value - * @return array - */ - function array_wrap($value) - { - return ! is_array($value) ? [$value] : $value; - } - } - if (! function_exists('collect')) { /** * Create a collection from the given value. @@ -39,9 +26,9 @@ function collect($value = null) * @param mixed $value * @return mixed */ - function value($value) + function value($value, ...$args) { - return $value instanceof Closure ? $value() : $value; + return $value instanceof Closure ? $value(...$args) : $value; } } @@ -49,9 +36,9 @@ function value($value) /** * Get an item from an array or object using "dot" notation. * - * @param mixed $target - * @param string|array $key - * @param mixed $default + * @param mixed $target + * @param string|array|int|null $key + * @param mixed $default * @return mixed */ function data_get($target, $key, $default = null) @@ -62,7 +49,13 @@ function data_get($target, $key, $default = null) $key = is_array($key) ? $key : explode('.', $key); - while (($segment = array_shift($key)) !== null) { + foreach ($key as $i => $segment) { + unset($key[$i]); + + if (is_null($segment)) { + return $target; + } + if ($segment === '*') { if ($target instanceof Collection) { $target = $target->all(); @@ -70,7 +63,11 @@ function data_get($target, $key, $default = null) return value($default); } - $result = Arr::pluck($target, $key); + $result = []; + + foreach ($target as $item) { + $result[] = data_get($item, $key); + } return in_array('*', $key) ? Arr::collapse($result) : $result; } @@ -108,35 +105,6 @@ function tap($value, $callback = null) } } - if (! function_exists('with')) { - /** - * Return the given object. Useful for chaining. - * - * @param mixed $object - * @return mixed - */ - function with($object) - { - return $object; - } - } - - if (! function_exists('dd')) { - /** - * Dump the passed variables and end the script. - * - * @param mixed - * @return void - */ - function dd(...$args) - { - foreach ($args as $x) { - VarDumper::dump($x); - } - die(1); - } - } - if (! function_exists('class_basename')) { /** * Get the class "basename" of the given object / class.