1: <?php
2:
3: namespace Deimos\Flow;
4:
5: use Deimos\Builder\Builder;
6: use Deimos\DI\DI;
7: use Deimos\Helper\Helper;
8:
9: class DefaultContainer extends DI
10: {
11:
12: 13: 14:
15: protected $helper;
16:
17: 18: 19:
20: protected $config;
21:
22: 23: 24: 25: 26: 27:
28: public function __construct(DefaultConfig $config = null, Helper $helper = null)
29: {
30: if (!$helper)
31: {
32: $builder = new Builder();
33: $this->helper = new Helper($builder);
34: }
35: else
36: {
37: $this->helper = $helper;
38: }
39:
40: $this->config = $config ?: new DefaultConfig();
41:
42: parent::__construct();
43: }
44:
45: 46: 47:
48: protected function configure()
49: {
50: foreach ($this->config->configStorage() as $callbackName => $callable)
51: {
52: $this->addCallback($callbackName, $callable);
53: }
54:
55: $this->addCallback('json_encode', function (array $storage = null)
56: {
57: if (!$storage)
58: {
59: $storage = [];
60: }
61:
62: return $this->json()->encode($storage);
63: });
64:
65: $this->build('arr', function ()
66: {
67: return $this->helper->arr();
68: });
69:
70: $this->build('str', function ()
71: {
72: return $this->helper->str();
73: });
74:
75: $this->build('json', function ()
76: {
77: return $this->helper->json();
78: });
79: }
80:
81: }