-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionHandler.php
More file actions
32 lines (26 loc) · 930 Bytes
/
FunctionHandler.php
File metadata and controls
32 lines (26 loc) · 930 Bytes
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
<?php
abstract class FunctionHandler {
static private $functions = array();
static private $containers = array();
static function addFunction($tag, $function) {
self::$functions[$tag] = $function;
}
static function addContainer($tag, $arrayOfFunctions) {
self::$containers[$tag] = $arrayOfFunctions;
}
static function handle($data, $container) {
$x = function ($x) use ($container) {
if (empty(self::$containers[$container])) return false;
foreach (self::$containers[$container] as $function) {
if (empty(self::$functions[$function])) continue;
$x = call_user_func(self::$functions[$function], $x);
}
return $x;
};
if (!is_array($data)) return $x($data);
foreach ($data as $key => $value) {
$data[$key] = $x($value);
}
return $data;
}
}