1: <?php
2:
3: namespace Deimos\Flow;
4:
5: class DefaultConfig
6: {
7:
8: 9: 10:
11: protected $configStorage = [
12: 'substr' => 'mb_substr',
13: 'strlen' => 'mb_strlen',
14: 'count' => 'count',
15: 'var_dump' => 'var_dump',
16: 'date' => 'date',
17: ];
18:
19: 20: 21:
22: public function __construct()
23: {
24: $this->registerCallback('length', function ($storage)
25: {
26: if (is_string($storage))
27: {
28: return mb_strlen($storage);
29: }
30:
31: if ($storage instanceof \ArrayObject)
32: {
33: return $storage->count();
34: }
35:
36: return count($storage);
37: });
38:
39: $this->registerCallback('escape', function ($string)
40: {
41: return htmlentities($string, ENT_QUOTES | ENT_IGNORE, 'UTF-8');
42: });
43: }
44:
45: 46: 47:
48: public function configStorage()
49: {
50: return $this->configStorage;
51: }
52:
53: 54: 55: 56:
57: public function registerCallback($name, $callable)
58: {
59: $this->configStorage[$name] = $callable;
60: }
61:
62: }