Component
6 months ago
ITip
6 months ago
Parser
6 months ago
Property
6 months ago
Recur
6 months ago
Splitter
6 months ago
TimezoneGuesser
6 months ago
timezonedata
1 year ago
BirthdayCalendarGenerator.php
6 months ago
Cli.php
6 months ago
Component.php
6 months ago
DateTimeParser.php
6 months ago
Document.php
6 months ago
ElementList.php
6 months ago
EofException.php
6 months ago
FreeBusyData.php
6 months ago
FreeBusyGenerator.php
6 months ago
InvalidDataException.php
6 months ago
Node.php
6 months ago
PHPUnitAssertions.php
6 months ago
Parameter.php
6 months ago
ParseException.php
6 months ago
Property.php
6 months ago
Reader.php
6 months ago
Settings.php
6 months ago
StringUtil.php
6 months ago
TimeZoneUtil.php
6 months ago
UUIDUtil.php
6 months ago
VCardConverter.php
6 months ago
Version.php
6 months ago
Writer.php
6 months ago
UUIDUtil.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaVendor\Sabre\VObject; |
| 4 | |
| 5 | /** |
| 6 | * UUID Utility. |
| 7 | * |
| 8 | * This class has static methods to generate and validate UUID's. |
| 9 | * UUIDs are used a decent amount within various *DAV standards, so it made |
| 10 | * sense to include it. |
| 11 | * |
| 12 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 13 | * @author Evert Pot (http://evertpot.com/) |
| 14 | * @license http://sabre.io/license/ Modified BSD License |
| 15 | */ |
| 16 | class UUIDUtil |
| 17 | { |
| 18 | /** |
| 19 | * Returns a pseudo-random v4 UUID. |
| 20 | * |
| 21 | * This function is based on a comment by Andrew Moore on php.net |
| 22 | * |
| 23 | * @see http://www.php.net/manual/en/function.uniqid.php#94959 |
| 24 | * |
| 25 | * @return string |
| 26 | */ |
| 27 | public static function getUUID() |
| 28 | { |
| 29 | return sprintf( |
| 30 | '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', |
| 31 | |
| 32 | // 32 bits for "time_low" |
| 33 | mt_rand(0, 0xffff), mt_rand(0, 0xffff), |
| 34 | |
| 35 | // 16 bits for "time_mid" |
| 36 | mt_rand(0, 0xffff), |
| 37 | |
| 38 | // 16 bits for "time_hi_and_version", |
| 39 | // four most significant bits holds version number 4 |
| 40 | mt_rand(0, 0x0fff) | 0x4000, |
| 41 | |
| 42 | // 16 bits, 8 bits for "clk_seq_hi_res", |
| 43 | // 8 bits for "clk_seq_low", |
| 44 | // two most significant bits holds zero and one for variant DCE1.1 |
| 45 | mt_rand(0, 0x3fff) | 0x8000, |
| 46 | |
| 47 | // 48 bits for "node" |
| 48 | mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Checks if a string is a valid UUID. |
| 54 | * |
| 55 | * @param string $uuid |
| 56 | * |
| 57 | * @return bool |
| 58 | */ |
| 59 | public static function validateUUID($uuid) |
| 60 | { |
| 61 | return 0 !== preg_match( |
| 62 | '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i', |
| 63 | $uuid |
| 64 | ); |
| 65 | } |
| 66 | } |
| 67 |