1: <?php
2:
3: namespace Charcoal\Ui\ServiceProvider;
4:
5: use \Pimple\Container;
6: use \Pimple\ServiceProviderInterface;
7:
8: use \Charcoal\Factory\GenericFactory as Factory;
9:
10: use \Charcoal\Ui\Form\FormBuilder;
11: use \Charcoal\Ui\Form\FormInterface;
12: use \Charcoal\Ui\Form\GenericForm;
13: use \Charcoal\Ui\FormGroup\FormGroupBuilder;
14: use \Charcoal\Ui\FormGroup\FormGroupInterface;
15: use \Charcoal\Ui\FormGroup\GenericFormGroup;
16: use \Charcoal\Ui\FormInput\FormInputBuilder;
17: use \Charcoal\Ui\FormInput\FormInputInterface;
18: use \Charcoal\Ui\FormInput\GenericFormInput;
19:
20: 21: 22:
23: class FormServiceProvider implements ServiceProviderInterface
24: {
25: 26: 27: 28:
29: public function register(Container $container)
30: {
31: $this->registerFormServices($container);
32: $this->registerFormGroupServices($container);
33: $this->registerFormInputServices($container);
34: }
35:
36: 37: 38: 39:
40: public function registerFormServices(Container $container)
41: {
42: 43: 44: 45:
46: $container['form/factory'] = function(Container $container) {
47: return new Factory([
48: 'base_class' => FormInterface::class,
49: 'default_class' => GenericForm::class,
50: 'arguments' => [[
51: 'container' => $container,
52: 'logger' => $container['logger'],
53: 'view' => $container['view'],
54: 'layout_builder' => $container['layout/builder'],
55: 'form_group_factory' => $container['form/group/factory']
56: ]]
57: ]);
58: };
59:
60: 61: 62: 63:
64: $container['form/builder'] = function(Container $container) {
65: $formFactory = $container['form/factory'];
66: $formBuilder = new FormBuilder($formFactory);
67: return $formBuilder;
68: };
69: }
70:
71: 72: 73: 74:
75: public function registerFormGroupServices(Container $container)
76: {
77: 78: 79: 80:
81: $container['form/group/factory'] = function(Container $container) {
82: return new Factory([
83: 'base_class' => FormGroupInterface::class,
84: 'default_class' => GenericFormGroup::class,
85: 'arguments' => [[
86: 'container' => $container,
87: 'logger' => $container['logger'],
88: 'view' => $container['view'],
89: 'layout_builder' => $container['layout/builder'],
90: 'form_input_builder' => $container['form/input/builder']
91: ]],
92: 'resolver_options' => [
93: 'suffix' => 'FormGroup'
94: ]
95: ]);
96: };
97: }
98:
99: 100: 101: 102:
103: public function registerFormInputServices(Container $container)
104: {
105: 106: 107: 108:
109: $container['form/input/factory'] = function(Container $container) {
110: return new Factory([
111: 'base_class' => FormInputInterface::class,
112: 'default_class' => GenericFormInput::class,
113: 'resolver_options' => [
114: 'suffix' => 'FormInput'
115: ]
116: ]);
117: };
118:
119: 120: 121: 122:
123: $container['form/input/builder'] = function(Container $container) {
124: $formInputFactory = $container['form/input/factory'];
125: $formInputBuilder = new FormInputBuilder($formInputFactory, $container);
126: return $formInputBuilder;
127: };
128: }
129: }
130: