1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if (! function_exists('hashid')) { |
4
|
|
|
/** |
5
|
|
|
* Get a hashid connection instance. |
6
|
|
|
* |
7
|
|
|
* @param string|null $name |
8
|
|
|
* @return mixed |
9
|
|
|
*/ |
10
|
|
|
function hashid($name = null) |
11
|
|
|
{ |
12
|
|
|
return app('hashid')->connection($name); |
13
|
|
|
} |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
if (! function_exists('hashid_encode')) { |
17
|
|
|
/** |
18
|
|
|
* Encode the given data using hashid. |
19
|
|
|
* |
20
|
|
|
* @param mixed $data |
21
|
|
|
* @param string|null $name |
22
|
|
|
* @return mixed |
23
|
|
|
*/ |
24
|
|
|
function hashid_encode($data, $name = null) |
25
|
|
|
{ |
26
|
|
|
return hashid($name)->encode($data); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if (! function_exists('hashid_decode')) { |
31
|
|
|
/** |
32
|
|
|
* Decode the given data using hashid. |
33
|
|
|
* |
34
|
|
|
* @param mixed $data |
35
|
|
|
* @param string|null $name |
36
|
|
|
* @return mixed |
37
|
|
|
*/ |
38
|
|
|
function hashid_decode($data, $name = null) |
39
|
|
|
{ |
40
|
|
|
return hashid($name)->decode($data); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if (! function_exists('urlsafe_base64_encode')) { |
45
|
|
|
/** |
46
|
|
|
* Encodes the given data with base64, and returns an URL-safe string. |
47
|
|
|
* |
48
|
|
|
* @see https://github.com/ElfSundae/laravel-helper |
49
|
|
|
* |
50
|
|
|
* @param string $data |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
function urlsafe_base64_encode($data) |
54
|
|
|
{ |
55
|
|
|
return strtr(base64_encode($data), ['+' => '-', '/' => '_', '=' => '']); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (! function_exists('urlsafe_base64_decode')) { |
60
|
|
|
/** |
61
|
|
|
* Decodes a base64 encoded data. |
62
|
|
|
* |
63
|
|
|
* @see https://github.com/ElfSundae/laravel-helper |
64
|
|
|
* |
65
|
|
|
* @param string $data |
66
|
|
|
* @param bool $strict |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
function urlsafe_base64_decode($data, $strict = false) |
70
|
|
|
{ |
71
|
|
|
return base64_decode(strtr($data.str_repeat('=', (4 - strlen($data) % 4)), '-_', '+/'), $strict); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if (! function_exists('config_path')) { |
76
|
|
|
/** |
77
|
|
|
* Get the configuration path. |
78
|
|
|
* For Lumen compatible. |
79
|
|
|
* |
80
|
|
|
* @param string $path |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
function config_path($path = '') |
84
|
|
|
{ |
85
|
|
|
return app()->basePath().DIRECTORY_SEPARATOR.'config'.($path ? DIRECTORY_SEPARATOR.$path : $path); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|