Completed
Push — master ( 467919...036b8f )
by Elf
01:58
created

helpers.php ➔ hashid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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('urlsafe_base64_encode')) {
17
    /**
18
     * Encodes the given data with base64, and returns an URL-safe string.
19
     *
20
     * @param  string  $data
21
     * @return string
22
     */
23
    function urlsafe_base64_encode($data)
24
    {
25
        return strtr(base64_encode($data), ['+' => '-', '/' => '_', '=' => '']);
26
    }
27
}
28
29
if (! function_exists('urlsafe_base64_decode')) {
30
    /**
31
     * Decodes a base64 encoded data.
32
     *
33
     * @param  string  $data
34
     * @param  bool  $strict
35
     * @return string
36
     */
37
    function urlsafe_base64_decode($data, $strict = false)
38
    {
39
        return base64_decode(strtr($data.str_repeat('=', (4 - strlen($data) % 4)), '-_', '+/'), $strict);
40
    }
41
}
42
43
if (! function_exists('config_path')) {
44
    /**
45
     * Get the configuration path.
46
     *
47
     * @param  string  $path
48
     * @return string
49
     */
50
    function config_path($path = '')
51
    {
52
        return app()->basePath().DIRECTORY_SEPARATOR.'config'.($path ? DIRECTORY_SEPARATOR.$path : $path);
53
    }
54
}
55