Test Failed
Push — master ( f82b48...e7e248 )
by Maximo
03:08
created

library/Core/functions.php (1 issue)

1
<?php
0 ignored issues
show
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
3
namespace Gewaer\Core;
4
5
use function function_exists;
6
use function getenv;
7
8
if (true !== function_exists('Gewaer\Core\appPath')) {
9
    /**
10
     * Get the application path.
11
     *
12
     * @param  string $path
13
     *
14
     * @return string
15
     */
16
    function appPath(string $path = ''): string
17
    {
18
        return dirname(dirname(__DIR__)) . ($path ? DIRECTORY_SEPARATOR . $path : $path);
19
    }
20
}
21
22
if (true !== function_exists('Gewaer\Core\envValue')) {
23
    /**
24
     * Gets a variable from the environment, returns it properly formatted or the
25
     * default if it does not exist
26
     *
27
     * @param string     $variable
28
     * @param mixed|null $default
29
     *
30
     * @return mixed
31
     */
32
    function envValue(string $variable, $default = null)
33
    {
34
        $return = $default;
35
        $value = getenv($variable);
36
        $values = [
37
            'false' => false,
38
            'true' => true,
39
            'null' => null,
40
        ];
41
42
        if (false !== $value) {
43
            $return = $values[$value] ?? $value;
44
        }
45
46
        return $return;
47
    }
48
}
49
50
if (true !== function_exists('Gewaer\Core\appUrl')) {
51
    /**
52
     * Constructs a URL for links with resource and id
53
     *
54
     * @param string $resource
55
     * @param int    $recordId
56
     *
57
     * @return array|false|mixed|string
58
     */
59
    function appUrl(string $resource, int $recordId)
60
    {
61
        return sprintf(
62
            '%s/%s/%s',
63
            envValue('APP_URL'),
64
            $resource,
65
            $recordId
66
        );
67
    }
68
}
69