1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Form; |
4
|
|
|
|
5
|
|
|
use Nip\Container\ServiceProviders\Providers\AbstractServiceProvider; |
6
|
|
|
use Nip\Container\ServiceProviders\Providers\BootableServiceProviderInterface; |
7
|
|
|
use Symfony\Component\Form\FormRegistry; |
8
|
|
|
use Symfony\Component\Form\ResolvedFormTypeFactory; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class FilesystemServiceProvider |
12
|
|
|
* @package Nip\Filesystem |
13
|
|
|
* |
14
|
|
|
* @inspiration https://github.com/laravel/framework/blob/5.4/src/Illuminate/Filesystem/FilesystemServiceProvider.php |
15
|
|
|
* |
16
|
|
|
*/ |
17
|
|
|
class FormServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface |
18
|
|
|
{ |
19
|
|
|
const FORM_REGISTRY = 'form.registry'; |
20
|
|
|
const FORM_EXTENSIONS = 'form.extensions'; |
21
|
|
|
const FORM_FACTORY = 'form.factory'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
|
|
public function provides(): array |
27
|
|
|
{ |
28
|
|
|
return [ |
29
|
|
|
static::FORM_REGISTRY, |
30
|
|
|
static::FORM_EXTENSIONS, |
31
|
|
|
static::FORM_FACTORY, |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritdoc |
37
|
|
|
*/ |
38
|
|
|
public function register() |
39
|
|
|
{ |
40
|
|
|
$this->registerFormRegistry(); |
41
|
|
|
$this->registerFormExtensions(); |
42
|
|
|
$this->registerFormFactory(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function boot() |
46
|
|
|
{ |
47
|
|
|
// $this->mergeDefaultFilesystem(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Register the native filesystem implementation. |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
protected function registerFormRegistry() |
56
|
|
|
{ |
57
|
|
|
$this->getContainer()->share( |
58
|
|
|
static::FORM_REGISTRY, |
59
|
|
|
function () { |
60
|
|
|
return new FormRegistry( |
61
|
|
|
$this->getContainer()->get(static::FORM_EXTENSIONS), |
62
|
|
|
new ResolvedFormTypeFactory() |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Register the native filesystem implementation. |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
protected function registerFormExtensions() |
74
|
|
|
{ |
75
|
|
|
$this->getContainer()->share( |
76
|
|
|
static::FORM_EXTENSIONS, |
77
|
|
|
function () { |
78
|
|
|
return [ |
79
|
|
|
|
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Register the native filesystem implementation. |
87
|
|
|
* |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
protected function registerFormFactory() |
91
|
|
|
{ |
92
|
|
|
$this->getContainer()->share( |
93
|
|
|
static::FORM_FACTORY, |
94
|
|
|
function () { |
95
|
|
|
return new \Symfony\Component\Form\FormFactory( |
96
|
|
|
$this->getContainer()->get(static::FORM_REGISTRY) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|