Rev 57 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 57 | Rev 82 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * UUID interpreter for PHP |
4 | * UUID interpreter for PHP |
5 | * Copyright 2017 - 2023 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2017 - 2024 Daniel Marschall, ViaThinkSoft |
6 | * Version 2023-08-02 |
6 | * Version 2024-03-09 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 19... | Line 19... | ||
19 | */ |
19 | */ |
20 | 20 | ||
21 | $uuid = isset($_GET['uuid']) ? trim($_GET['uuid']) : 'CREATE'; |
21 | $uuid = isset($_GET['uuid']) ? trim($_GET['uuid']) : 'CREATE'; |
22 | 22 | ||
23 | $version = $_REQUEST['version'] ?? null; |
23 | $version = $_REQUEST['version'] ?? null; |
- | 24 | $hash_sqlserver_version = null; |
|
- | 25 | $hash_algo = null; |
|
24 | if (!is_null($version)) { |
26 | if (!is_null($version)) { |
25 | if (preg_match('@^(8)_namebased_(.+)$@', $version, $m)) { |
27 | if (preg_match('@^(8)_sqlserver_v(.+)$@', $version, $m)) { |
26 | $version = $m[1]; |
28 | $version = $m[1]; |
27 | $hash_uuid = $m[2]; |
29 | $hash_sqlserver_version = $m[2]; |
- | 30 | } else if (preg_match('@^(8)_namebased_(.+)$@', $version, $m)) { |
|
28 | } else { |
31 | $version = $m[1]; |
29 | $hash_uuid = null; |
32 | $hash_algo = $m[2]; |
30 | } |
33 | } |
31 | } else { |
- | |
32 | $hash_uuid = null; |
- | |
33 | } |
34 | } |
34 | if (!is_numeric($version) || (strlen($version)!=1)) $version = 1; // default: Version 1 / time based |
35 | if (!is_numeric($version) || (strlen($version)!=1)) $version = 1; // default: Version 1 / time based |
35 | 36 | ||
36 | if ($uuid == 'CREATE') { |
37 | if ($uuid == 'CREATE') { |
37 | $title = 'Generate a UUIDv'.$version; |
38 | $title = 'Generate a UUIDv'.$version; |
Line 83... | Line 84... | ||
83 | } else if ($version == '6') { |
84 | } else if ($version == '6') { |
84 | $uuid = gen_uuid_reordered(); |
85 | $uuid = gen_uuid_reordered(); |
85 | } else if ($version == '7') { |
86 | } else if ($version == '7') { |
86 | $uuid = gen_uuid_unix_epoch(); |
87 | $uuid = gen_uuid_unix_epoch(); |
87 | } else if ($version == '8') { |
88 | } else if ($version == '8') { |
- | 89 | if ($hash_sqlserver_version != null) { |
|
- | 90 | $uuid = gen_uuid_v8_sqlserver_sortable(intval($hash_sqlserver_version)); |
|
88 | if ($hash_uuid != null) { |
91 | } else if ($hash_algo != null) { |
89 | $uuid = gen_uuid_v8_namebased($hash_uuid, trim($_REQUEST['nb_ns']??''), trim($_REQUEST['nb_val']??'')); |
92 | $uuid = gen_uuid_v8_namebased($hash_algo, trim($_REQUEST['nb_ns']??''), trim($_REQUEST['nb_val']??'')); |
90 | } else { |
93 | } else { |
91 | $uuid = gen_uuid_custom(trim($_REQUEST['block1']??'0'), trim($_REQUEST['block2']??'0'), trim($_REQUEST['block3']??'0'), trim($_REQUEST['block4']??'0'), trim($_REQUEST['block5']??'0')); |
94 | $uuid = gen_uuid_custom(trim($_REQUEST['block1']??'0'), trim($_REQUEST['block2']??'0'), trim($_REQUEST['block3']??'0'), trim($_REQUEST['block4']??'0'), trim($_REQUEST['block5']??'0')); |
92 | } |
95 | } |
93 | } else { |
96 | } else { |
94 | throw new Exception("Unexpected version number"); |
97 | throw new Exception("Unexpected version number"); |