annotate vendor/sabre/vobject/lib/UUIDUtil.php @ 38:ac106d4c8961 default tip

flip /etc/roundcube to point here
author Charlie Root
date Sat, 29 Dec 2018 05:39:53 -0500
parents 430dbd5346f7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 * UUID Utility
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 * This class has static methods to generate and validate UUID's.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 * UUIDs are used a decent amount within various *DAV standards, so it made
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 * sense to include it.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 class UUIDUtil {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 * Returns a pseudo-random v4 UUID
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 * This function is based on a comment by Andrew Moore on php.net
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 * @see http://www.php.net/manual/en/function.uniqid.php#94959
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 static public function getUUID() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 return sprintf(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 // 32 bits for "time_low"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 // 16 bits for "time_mid"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 mt_rand( 0, 0xffff ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 // 16 bits for "time_hi_and_version",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 // four most significant bits holds version number 4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 mt_rand( 0, 0x0fff ) | 0x4000,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 // 16 bits, 8 bits for "clk_seq_hi_res",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 // 8 bits for "clk_seq_low",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 // two most significant bits holds zero and one for variant DCE1.1
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 mt_rand( 0, 0x3fff ) | 0x8000,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 // 48 bits for "node"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 * Checks if a string is a valid UUID.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 * @param string $uuid
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 * @return bool
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 static public function validateUUID($uuid) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 return preg_match(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 $uuid
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 ) == true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 }