1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Nip\Container\Container; |
4
|
|
|
|
5
|
|
|
if (!function_exists('app')) { |
6
|
|
|
/** |
7
|
|
|
* Get the available container instance. |
8
|
|
|
* |
9
|
|
|
* @param string $make |
10
|
|
|
* @param array $parameters |
11
|
|
|
* @return mixed|Container |
12
|
|
|
*/ |
13
|
|
|
function app($make = null, $parameters = []) |
14
|
|
|
{ |
15
|
28 |
|
if (is_null($make)) { |
16
|
1 |
|
return Container::getInstance(); |
17
|
|
|
} |
18
|
|
|
|
19
|
28 |
|
return Container::getInstance()->get($make, $parameters); |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
if (!function_exists('env')) { |
24
|
|
|
/** |
25
|
|
|
* Gets the value of an environment variable. |
26
|
|
|
* |
27
|
|
|
* @param string $key |
28
|
|
|
* @param mixed $default |
29
|
|
|
* @return mixed |
30
|
|
|
*/ |
31
|
|
|
function env($key, $default = null) |
32
|
|
|
{ |
33
|
|
|
$value = getenv($key); |
34
|
|
|
if ($value === false) { |
35
|
|
|
return value($default); |
36
|
|
|
} |
37
|
|
|
switch (strtolower($value)) { |
38
|
|
|
case 'true': |
39
|
|
|
case '(true)': |
40
|
|
|
return true; |
41
|
|
|
case 'false': |
42
|
|
|
case '(false)': |
43
|
|
|
return false; |
44
|
|
|
case 'empty': |
45
|
|
|
case '(empty)': |
46
|
|
|
return ''; |
47
|
|
|
case 'null': |
48
|
|
|
case '(null)': |
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
// if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) { |
|
|
|
|
52
|
|
|
// return substr($value, 1, -1); |
53
|
|
|
// } |
54
|
|
|
return $value; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
if (!function_exists('config')) { |
58
|
|
|
/** |
59
|
|
|
* Get / set the specified configuration value. |
60
|
|
|
* |
61
|
|
|
* If an array is passed as the key, we will assume you want to set an array of values. |
62
|
|
|
* |
63
|
|
|
* @param array|string $key |
64
|
|
|
* @param mixed $default |
65
|
|
|
* @return \Nip\Config\Config|mixed |
66
|
|
|
*/ |
67
|
|
|
function config($key = null, $default = null) |
68
|
|
|
{ |
69
|
|
|
if (is_null($key)) { |
70
|
|
|
return app('config'); |
71
|
|
|
} |
72
|
|
|
if (is_array($key)) { |
73
|
|
|
return app('config')->set($key); |
74
|
|
|
} |
75
|
|
|
return app('config')->get($key, $default); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (!function_exists('request')) { |
80
|
|
|
/** |
81
|
|
|
* Get an instance of the current request or an input item from the request. |
82
|
|
|
* |
83
|
|
|
* @param array|string $key |
84
|
|
|
* @param mixed $default |
85
|
|
|
* @return Nip\Request|string|array |
86
|
|
|
*/ |
87
|
|
|
function request($key = null, $default = null) |
88
|
|
|
{ |
89
|
|
|
$request = app('request'); |
90
|
|
|
if (is_null($key)) { |
91
|
|
|
return $request; |
92
|
|
|
} |
93
|
|
|
$value = $request->get($key); |
94
|
|
|
return $value ? $value : $default; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if (!function_exists('asset')) { |
99
|
|
|
/** |
100
|
|
|
* Generate an asset path for the application. |
101
|
|
|
* |
102
|
|
|
* @param string $path |
103
|
|
|
* @param bool $secure |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
function asset($path, $secure = null) |
107
|
|
|
{ |
108
|
|
|
return app('url')->asset($path, $secure); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return \Nip\I18n\Translator |
114
|
|
|
*/ |
115
|
|
|
function translator() |
116
|
|
|
{ |
117
|
|
|
return app('translator'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return Nip\Inflector\Inflector |
122
|
|
|
*/ |
123
|
|
|
function inflector() |
124
|
|
|
{ |
125
|
28 |
|
return app('inflector'); |
126
|
|
|
} |
127
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.