-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
118 lines (109 loc) · 4.02 KB
/
Copy pathfunctions.php
File metadata and controls
118 lines (109 loc) · 4.02 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
use Infocyph\ArrayKit\Collection\Collection;
use Infocyph\ArrayKit\Collection\Pipeline;
use Infocyph\ArrayKit\Facade\ModuleProxy;
use function Infocyph\ArrayKit\array_get as arraykit_array_get;
use function Infocyph\ArrayKit\array_set as arraykit_array_set;
use function Infocyph\ArrayKit\chain as arraykit_chain;
use function Infocyph\ArrayKit\collect as arraykit_collect;
use function Infocyph\ArrayKit\compare as arraykit_compare;
use function Infocyph\ArrayKit\dotenv as arraykit_dotenv;
use function Infocyph\ArrayKit\env as arraykit_env;
// Optional global helpers:
// this file is intentionally not autoloaded by default to avoid global symbol pressure.
if (!function_exists('compare')) {
/**
* Compare two values using a specified operator.
*
* @param mixed $retrieved The value to compare
* @param mixed $value The reference value
* @param string|null $operator Supported operators:
* '!=', '<>', 'ne', '<', 'lt', '>', 'gt',
* '<=', 'lte', '>=', 'gte', '===', '!=='
* or null/default for '=='.
* @return bool True if comparison holds, false otherwise
*/
function compare(mixed $retrieved, mixed $value, ?string $operator = null): bool
{
return arraykit_compare($retrieved, $value, $operator);
}
}
if (!function_exists('array_get')) {
/**
* Retrieve one or multiple items from the array using dot notation.
*
* The following cases are handled:
* - If no key is provided, the entire array is returned.
* - If an array of keys is provided, all values are returned in an array.
* - If a single key is provided, the value is returned directly.
*
* @param array<array-key, mixed> $array The array to retrieve items from.
* @param int|string|array<int, string|int>|null $key The key(s) to retrieve.
* @param mixed $default The default value to return if the key is not found.
* @return mixed The retrieved value(s).
*/
function array_get(array $array, int|string|array|null $key = null, mixed $default = null): mixed
{
return arraykit_array_get($array, $key, $default);
}
}
if (!function_exists('array_set')) {
/**
* Set one or multiple items in the array using dot notation.
*
* If no key is provided, the entire array is replaced with $value.
* If an array of key-value pairs is provided, each value is set.
* If a single key is provided, the value is set directly.
*
* @param array<array-key, mixed> $array The array to set items in.
* @param string|array<array-key, mixed>|null $key
* @param mixed $value The value to set.
* @param bool $overwrite If true, overwrite existing values. If false, existing values are preserved.
* @return bool True on success
*/
function array_set(array &$array, string|array|null $key, mixed $value = null, bool $overwrite = true): bool
{
return arraykit_array_set($array, $key, $value, $overwrite);
}
}
if (!function_exists('collect')) {
/**
* Wrap the given value in an {@see Collection}.
*
* @param mixed $data Anything “array-able”: array, Traversable, scalar, etc.
*/
function collect(mixed $data = []): Collection
{
return arraykit_collect($data);
}
}
if (!function_exists('chain')) {
/**
* Start a chainable pipeline on any “array-able” value.
*
* @param mixed $data Array, Traversable, scalar, etc.
*/
function chain(mixed $data): Pipeline
{
return arraykit_chain($data);
}
}
if (!function_exists('env')) {
/**
* Read the current environment from $_ENV, $_SERVER, or getenv().
*/
function env(?string $key = null, mixed $default = null): mixed
{
return arraykit_env($key, $default);
}
}
if (!function_exists('dotenv')) {
/**
* Access the ArrayKit .env file parser facade.
*/
function dotenv(): ModuleProxy
{
return arraykit_dotenv();
}
}