Completed
Push — master ( 6e09d9...9728f4 )
by Elf
01:57
created

helpers.php ➔ urlsafe_base64_encode()   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('urlsafe_base64_encode')) {
4
    /**
5
     * Encodes the given data with base64, and returns an URL-safe string.
6
     *
7
     * @param  string  $data
8
     * @return string
9
     */
10
    function urlsafe_base64_encode($data)
11
    {
12
        return strtr(base64_encode($data), ['+' => '-', '/' => '_', '=' => '']);
13
    }
14
}
15
16
if (! function_exists('urlsafe_base64_decode')) {
17
    /**
18
     * Decodes a base64 encoded data.
19
     *
20
     * @param  string  $data
21
     * @param  bool  $strict
22
     * @return string
23
     */
24
    function urlsafe_base64_decode($data, $strict = false)
25
    {
26
        return base64_decode(strtr($data.str_repeat('=', (4 - strlen($data) % 4)), '-_', '+/'), $strict);
27
    }
28
}
29
30
if (! function_exists('config_path')) {
31
    /**
32
     * Get the configuration path.
33
     *
34
     * @param  string  $path
35
     * @return string
36
     */
37
    function config_path($path = '')
38
    {
39
        return app()->basePath().DIRECTORY_SEPARATOR.'config'.($path ? DIRECTORY_SEPARATOR.$path : $path);
40
    }
41
}
42