1: <?php namespace Knot\Dict\Helpers;
2:
3: use Knot\Dict;
4: use Knot\Dict\HelperManager;
5:
6: class UnderscoreHelper implements HelperInterface {
7:
8: public $ready = false;
9:
10: public $functions = [
11: "each",
12: "map",
13: "reduce",
14: "reduceRight",
15: "find",
16: "filter",
17: "reject",
18: "all",
19: "any",
20: "includ",
21: "invoke",
22: "pluck",
23: "max",
24: "min",
25: "groupBy",
26: "sortBy",
27: "sortedIndex",
28: "shuffle",
29: "toArray",
30: "size",
31: "first",
32: "initial",
33: "rest",
34: "last",
35: "compact",
36: "flatten",
37: "without",
38: "uniq",
39: "union",
40: "intersection",
41: "difference",
42: "zip",
43: "indexOf",
44: "lastIndexOf",
45: "range",
46: "memoize",
47: "throttle",
48: "once",
49: "after",
50: "wrap",
51: "compose",
52: "keys",
53: "values",
54: "functions",
55: "extend",
56: "defaults",
57: "clon",
58: "tap",
59: "has",
60: "isEqual",
61: "isEmpty",
62: "isObject",
63: "isArray",
64: "isFunction",
65: "isString",
66: "isNumber",
67: "isBoolean",
68: "isDate",
69: "isNaN",
70: "isNull",
71: "identity",
72: "times",
73: "mixin",
74: "uniqueId",
75: "escape",
76: "template",
77: "chain",
78: "value"
79: ];
80:
81:
82: public function __construct()
83: {
84: if ( class_exists("__") )
85: {
86: $this->ready = true;
87: }
88: }
89:
90:
91: public function getName()
92: {
93: return 'underscore';
94: }
95:
96:
97: public function addRoutes(HelperManager $helperManager)
98: {
99:
100: if ( $this->ready === true )
101: {
102: foreach ($this->functions as $functionName)
103: {
104: $helperManager->addRoute($functionName, [ __CLASS__, "execute" ]);
105: }
106: }
107: }
108:
109:
110: public function execute(Dict $knot, $arguments, $functionName)
111: {
112: $data = $knot->toArray();
113:
114: $underscoreObject = \__($data);
115: $targetFunction = [ $underscoreObject, $functionName ];
116:
117: return call_user_func_array($targetFunction, $arguments);
118: }
119:
120: }
121: