Str::random()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace tinymeng\OAuth2\Helper;
3
4
class Str
5
{
6
    public static function uFirst($str)
7
    {
8
        return ucfirst(strtolower($str));
9
    }
10
11
    public static function buildParams($params, $urlencode = false, $except = ['sign'])
12
    {
13
        $param_str = '';
14
        foreach ($params as $k => $v) {
15
            if (in_array($k, $except)) {
16
                continue;
17
            }
18
            $param_str .= $k . '=';
19
            $param_str .= $urlencode ? rawurlencode($v) : $v;
20
            $param_str .= '&';
21
        }
22
        return rtrim($param_str, '&');
23
    }
24
25
    public static function random($length = 16)
26
    {
27
        $str_pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
28
        return substr(str_shuffle($str_pol), 0, $length);
29
    }
30
31
    public static function getClientIP()
32
    {
33
        $ip = '127.0.0.1';
34
        if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR']) {
35
            $ip = $_SERVER['REMOTE_ADDR'];
36
        } else if (getenv('REMOTE_ADDR')) {
37
            $ip = getenv('REMOTE_ADDR');
38
        }
39
        return $ip;
40
    }
41
}
42