forked from leocavalcante/siler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSiler.php
More file actions
47 lines (41 loc) · 1.13 KB
/
Copy pathSiler.php
File metadata and controls
47 lines (41 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
/**
* Siler core file.
*/
namespace Siler;
/**
* Get a value from an array checking if the key exists and returning a default value if not.
*
* @param array $array The array to be searched on
* @param mixed $key The key to be searched
* @param mixed $default The default value to be returned when the key don't exists
* @param bool $caseInsensitive Ignore key case, default false
*
* @return mixed
*/
function array_get(array $array, $key = null, $default = null, bool $caseInsensitive = false)
{
if (is_null($key)) {
return $array;
}
if ($caseInsensitive) {
$array = array_change_key_case($array);
$key = strtolower($key);
}
return array_key_exists($key, $array) ? $array[$key] : $default;
}
/**
* Returns a function that requires the given filename.
*
* @param string $filename The file to be required
*
* @return \Closure
*/
function require_fn(string $filename) : \Closure
{
return function ($params = null) use ($filename) {
/** @psalm-suppress UnresolvableInclude */
return require $filename;
};
}