forked from jessedearing/f1api-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
f1_util.php
84 lines (72 loc) · 2.82 KB
/
f1_util.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
*
* Copyright 2009 Fellowship Technologies
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*
* Description of Util
*
* @author Jaskaran Singh (Jas)
*/
class Util {
public static function urlencode_rfc3986($input) {
if (is_array($input)) {
return array_map(array('Util','urlencode_rfc3986'), $input);
} else if (is_scalar($input)) {
return str_replace('+', ' ',
str_replace('%7E', '~', rawurlencode($input)));
} else {
return '';
}
}
/**
* parses the url and rebuilds it to be
* scheme://host/path
*/
/**
* CHANGED: getNormalizedHttpUrl() to static method
*/
public static function getNormalizedHttpUrl($httpUrl) {
$parts = parse_url($httpUrl);
$port = @$parts['port'];
$scheme = $parts['scheme'];
$host = $parts['host'];
$path = @$parts['path'];
$port or $port = ($scheme == 'https') ? '443' : '80';
if (($scheme == 'https' && $port != '443')
|| ($scheme == 'http' && $port != '80')) {
$host = "$host:$port";
}
return "$scheme://$host$path";
}
public static function getPort($httpUrl) {
$parts = parse_url($httpUrl);
$port = @$parts['port'];
$scheme = $parts['scheme'];
$port or $port = ($scheme == 'https') ? '443' : '80';
return $port;
}
public static function getHostName($httpUrl) {
$parts = parse_url($httpUrl);
$host = $parts['host'];
return $host;
}
public static function getGuid() {
// The field names refer to RFC 4122 section 4.1.2
return sprintf('%04x%04x-%04x-%03x4-%04x-%04x%04x%04x',
mt_rand(0, 65535), mt_rand(0, 65535), // 32 bits for "time_low"
mt_rand(0, 65535), // 16 bits for "time_mid"
mt_rand(0, 4095), // 12 bits before the 0100 of (version) 4 for "time_hi_and_version"
bindec(substr_replace(sprintf('%016b', mt_rand(0, 65535)), '01', 6, 2)),
// 8 bits, the last two of which (positions 6 and 7) are 01, for "clk_seq_hi_res"
// (hence, the 2nd hex digit after the 3rd hyphen can only be 1, 5, 9 or d)
// 8 bits for "clk_seq_low"
mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535) // 48 bits for "node"
);
}
}
?>