1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Saltwater\Water; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Magic Array Object |
7
|
|
|
* |
8
|
|
|
* @package Saltwater\Water |
9
|
|
|
* |
10
|
|
|
* Same as the above, but as methods for injecting a caller |
11
|
|
|
* |
12
|
|
|
* @method array change_key_case() — Changes the case of all keys in an array |
13
|
|
|
* @method array chunk() — Split an array into chunks |
14
|
|
|
* @method array column() — Return the values from a single column in |
15
|
|
|
* the input array |
16
|
|
|
* @method array combine() — Creates an array by using one array for |
17
|
|
|
* keys and another for its values |
18
|
|
|
* @method int count_values() — Counts all the values of an array |
19
|
|
|
* @method array diff_assoc() — Computes the difference of arrays with |
20
|
|
|
* additional index check |
21
|
|
|
* @method array diff_key() — Computes the difference of arrays using |
22
|
|
|
* keys for comparison |
23
|
|
|
* @method array diff_uassoc() — Computes the difference of arrays with |
24
|
|
|
* additional index check which is performed |
25
|
|
|
* by a user supplied callback function |
26
|
|
|
* @method array diff_ukey() — Computes the difference of arrays using a |
27
|
|
|
* callback function on the keys for |
28
|
|
|
* comparison |
29
|
|
|
* @method array diff() — Computes the difference of arrays |
30
|
|
|
* @method array fill_keys() — Fill an array with values, specifying |
31
|
|
|
* keys |
32
|
|
|
* @method array fill() — Fill an array with values |
33
|
|
|
* @method array filter() — Filters elements of an array using a |
34
|
|
|
* callback function |
35
|
|
|
* @method array flip() — Exchanges all keys with their associated |
36
|
|
|
* values in an array |
37
|
|
|
* @method array intersect_assoc() — Computes the intersection of arrays with |
38
|
|
|
* additional index check |
39
|
|
|
* @method array intersect_key() — Computes the intersection of arrays using |
40
|
|
|
* keys for comparison |
41
|
|
|
* @method array intersect_uassoc() — Computes the intersection of arrays with |
42
|
|
|
* additional index check, compares indexes |
43
|
|
|
* by a callback function |
44
|
|
|
* @method array intersect_ukey() — Computes the intersection of arrays using |
45
|
|
|
* a callback function on the keys for |
46
|
|
|
* comparison |
47
|
|
|
* @method array intersect() — Computes the intersection of arrays |
48
|
|
|
* @method array key_exists() — Checks if the given key or index exists |
49
|
|
|
* in the array |
50
|
|
|
* @method array keys() — Return all the keys or a subset of the |
51
|
|
|
* keys of an array |
52
|
|
|
* @method array map() — Applies the callback to the elements of |
53
|
|
|
* the given arrays |
54
|
|
|
* @method array merge_recursive() — Merge two or more arrays recursively |
55
|
|
|
* @method array merge() — Merge one or more arrays |
56
|
|
|
* @method array multisort() — Sort multiple or multi-dimensional arrays |
57
|
|
|
* @method array pad() — Pad array to the specified length with a |
58
|
|
|
* value |
59
|
|
|
* @method mixed pop() — Pop the element off the end of the array |
60
|
|
|
* @method array product() — Calculate the product of values in an |
61
|
|
|
* array |
62
|
|
|
* @method array push() — Push one or more elements onto the end of |
63
|
|
|
* the array |
64
|
|
|
* @method mixed rand() — Pick one or more random entries out of an |
65
|
|
|
* array |
66
|
|
|
* @method mixed reduce() — Iteratively reduce the array to a single |
67
|
|
|
* value using a callback function |
68
|
|
|
* @method array replace_recursive() — Replaces elements from passed arrays into |
69
|
|
|
* the first array recursively |
70
|
|
|
* @method array replace() — Replaces elements from passed arrays into |
71
|
|
|
* the first array |
72
|
|
|
* @method array reverse() — Return an array with elements in reverse |
73
|
|
|
* order |
74
|
|
|
* @method mixed search() — Searches the array for a given value and |
75
|
|
|
* returns the corresponding key if successful |
76
|
|
|
* @method mixed shift() — Shift an element off the beginning of |
77
|
|
|
* the array |
78
|
|
|
* @method mixed slice() — Extract a slice of the array |
79
|
|
|
* @method array splice() — Remove a portion of the array and replace |
80
|
|
|
* it with something else |
81
|
|
|
* @method mixed sum() — Calculate the sum of values in an array |
82
|
|
|
* @method array udiff_assoc() — Computes the difference of arrays with |
83
|
|
|
* additional index check, compares data by |
84
|
|
|
* a callback function |
85
|
|
|
* @method array udiff_uassoc() — Computes the difference of arrays with |
86
|
|
|
* additional index check, compares data and |
87
|
|
|
* indexes by a callback function |
88
|
|
|
* @method array udiff() — Computes the difference of arrays by |
89
|
|
|
* using a callback function for data |
90
|
|
|
* comparison |
91
|
|
|
* @method array uintersect_assoc() — Computes the intersection of arrays with |
92
|
|
|
* additional index check, compares data by |
93
|
|
|
* a callback function |
94
|
|
|
* @method array uintersect_uassoc() — Computes the intersection of arrays with |
95
|
|
|
* additional index check, compares data and |
96
|
|
|
* indexes by a callback functions |
97
|
|
|
* @method array uintersect() — Computes the intersection of arrays, |
98
|
|
|
* compares data by a callback function |
99
|
|
|
* @method array unique() — Removes duplicate values from an array |
100
|
|
|
* @method array unshift() — Prepend one or more elements to the |
101
|
|
|
* beginning of an array |
102
|
|
|
* @method array values() — Return all the values of an array |
103
|
|
|
* @method array walk_recursive() — Apply a user function recursively to |
104
|
|
|
* every member of an array |
105
|
|
|
* @method array walk() — Apply a user function to every member of |
106
|
|
|
* an array |
107
|
|
|
*/ |
108
|
|
|
class MagicArrayObject extends \ArrayObject |
109
|
|
|
{ |
110
|
|
|
/** |
111
|
|
|
* @param string $func |
112
|
|
|
* @param array $argv |
113
|
|
|
* |
114
|
|
|
* @return mixed |
115
|
|
|
* |
116
|
|
|
* @throws \BadMethodCallException |
117
|
|
|
*/ |
118
|
|
|
public function __call($func, $argv) |
119
|
|
|
{ |
120
|
|
|
$func = 'array_' . $func; |
121
|
|
|
|
122
|
|
|
if (!is_callable($func)) { |
123
|
|
|
throw new \BadMethodCallException(__CLASS__ . '->' . $func); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if ($func == 'array_search') { |
127
|
|
|
return call_user_func_array( |
128
|
|
|
$func, |
129
|
|
|
array_merge($argv, array((array) $this)) |
130
|
|
|
); |
131
|
|
|
} else { |
132
|
|
|
return call_user_func_array( |
133
|
|
|
$func, |
134
|
|
|
array_merge(array((array) $this), $argv) |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|