Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/**
4
 * This file is part of the ramsey/uuid library
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
10
 * @license http://opensource.org/licenses/MIT MIT
11
 * phpcs:disable Squiz.Functions.GlobalFunction
12
 */
13
 
14
declare(strict_types=1);
15
 
16
namespace Ramsey\Uuid;
17
 
18
use DateTimeInterface;
19
use Ramsey\Uuid\Type\Hexadecimal;
20
use Ramsey\Uuid\Type\Integer as IntegerObject;
21
 
22
/**
23
 * Returns a version 1 (Gregorian time) UUID from a host ID, sequence number,
24
 * and the current time
25
 *
26
 * @param Hexadecimal|int|string|null $node A 48-bit number representing the
27
 *     hardware address; this number may be represented as an integer or a
28
 *     hexadecimal string
29
 * @param int|null $clockSeq A 14-bit number used to help avoid duplicates that
30
 *     could arise when the clock is set backwards in time or if the node ID
31
 *     changes
32
 *
33
 * @return non-empty-string Version 1 UUID as a string
34
 */
35
function v1($node = null, ?int $clockSeq = null): string
36
{
37
    return Uuid::uuid1($node, $clockSeq)->toString();
38
}
39
 
40
/**
41
 * Returns a version 2 (DCE Security) UUID from a local domain, local
42
 * identifier, host ID, clock sequence, and the current time
43
 *
44
 * @param int $localDomain The local domain to use when generating bytes,
45
 *     according to DCE Security
46
 * @param IntegerObject|null $localIdentifier The local identifier for the
47
 *     given domain; this may be a UID or GID on POSIX systems, if the local
48
 *     domain is person or group, or it may be a site-defined identifier
49
 *     if the local domain is org
50
 * @param Hexadecimal|null $node A 48-bit number representing the hardware
51
 *     address
52
 * @param int|null $clockSeq A 14-bit number used to help avoid duplicates
53
 *     that could arise when the clock is set backwards in time or if the
54
 *     node ID changes
55
 *
56
 * @return non-empty-string Version 2 UUID as a string
57
 */
58
function v2(
59
    int $localDomain,
60
    ?IntegerObject $localIdentifier = null,
61
    ?Hexadecimal $node = null,
62
    ?int $clockSeq = null
63
): string {
64
    return Uuid::uuid2($localDomain, $localIdentifier, $node, $clockSeq)->toString();
65
}
66
 
67
/**
68
 * Returns a version 3 (name-based) UUID based on the MD5 hash of a
69
 * namespace ID and a name
70
 *
71
 * @param string|UuidInterface $ns The namespace (must be a valid UUID)
72
 *
73
 * @return non-empty-string Version 3 UUID as a string
74
 *
75
 * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants,
76
 *             but under constant factory setups, this method operates in functionally pure manners
77
 */
78
function v3($ns, string $name): string
79
{
80
    return Uuid::uuid3($ns, $name)->toString();
81
}
82
 
83
/**
84
 * Returns a version 4 (random) UUID
85
 *
86
 * @return non-empty-string Version 4 UUID as a string
87
 */
88
function v4(): string
89
{
90
    return Uuid::uuid4()->toString();
91
}
92
 
93
/**
94
 * Returns a version 5 (name-based) UUID based on the SHA-1 hash of a
95
 * namespace ID and a name
96
 *
97
 * @param string|UuidInterface $ns The namespace (must be a valid UUID)
98
 *
99
 * @return non-empty-string Version 5 UUID as a string
100
 *
101
 * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants,
102
 *             but under constant factory setups, this method operates in functionally pure manners
103
 */
104
function v5($ns, string $name): string
105
{
106
    return Uuid::uuid5($ns, $name)->toString();
107
}
108
 
109
/**
110
 * Returns a version 6 (reordered time) UUID from a host ID, sequence number,
111
 * and the current time
112
 *
113
 * @param Hexadecimal|null $node A 48-bit number representing the hardware
114
 *     address
115
 * @param int|null $clockSeq A 14-bit number used to help avoid duplicates that
116
 *     could arise when the clock is set backwards in time or if the node ID
117
 *     changes
118
 *
119
 * @return non-empty-string Version 6 UUID as a string
120
 */
121
function v6(?Hexadecimal $node = null, ?int $clockSeq = null): string
122
{
123
    return Uuid::uuid6($node, $clockSeq)->toString();
124
}
125
 
126
/**
127
 * Returns a version 7 (Unix Epoch time) UUID
128
 *
129
 * @param DateTimeInterface|null $dateTime An optional date/time from which
130
 *     to create the version 7 UUID. If not provided, the UUID is generated
131
 *     using the current date/time.
132
 *
133
 * @return non-empty-string Version 7 UUID as a string
134
 */
135
function v7(?DateTimeInterface $dateTime = null): string
136
{
137
    return Uuid::uuid7($dateTime)->toString();
138
}
139
 
140
/**
141
 * Returns a version 8 (custom) UUID
142
 *
143
 * The bytes provided may contain any value according to your application's
144
 * needs. Be aware, however, that other applications may not understand the
145
 * semantics of the value.
146
 *
147
 * @param string $bytes A 16-byte octet string. This is an open blob
148
 *     of data that you may fill with 128 bits of information. Be aware,
149
 *     however, bits 48 through 51 will be replaced with the UUID version
150
 *     field, and bits 64 and 65 will be replaced with the UUID variant. You
151
 *     MUST NOT rely on these bits for your application needs.
152
 *
153
 * @return non-empty-string Version 7 UUID as a string
154
 */
155
function v8(string $bytes): string
156
{
157
    return Uuid::uuid8($bytes)->toString();
158
}