-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironmentFormType.php
More file actions
135 lines (128 loc) · 3.77 KB
/
EnvironmentFormType.php
File metadata and controls
135 lines (128 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace SyncEngine\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use SyncEngine\Service\System;
class EnvironmentFormType extends AbstractType
{
public function __construct( private readonly System $system ) {}
public function buildForm( FormBuilderInterface $builder, array $options ): void
{
$dsnFields = [
'protocol' => [],
'username' => [ 'conditions' => [ 'protocol' => [ 'operator' => '!=' , 'compare' => 'sqlite' ] ] ],
'password' => [ 'conditions' => [ 'protocol' => [ 'operator' => '!=' , 'compare' => 'sqlite' ] ] ],
'host' => [ 'conditions' => [ 'protocol' => [ 'operator' => '!=' , 'compare' => 'sqlite' ] ] ],
'port' => [ 'conditions' => [ 'protocol' => [ 'operator' => '!=' , 'compare' => 'sqlite' ] ] ],
'path' => [],
];
$mode = $this->system->getEnv()->get( 'APP_ENV' );
$builder
->add('APP_ENV', ChoiceType::class, [
'label' => 'Environment',
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'choices' => [
'Production' => 'prod',
'Development' => 'dev',
],
])
->add( 'APP_DEBUG', ChoiceType::class, [
'label' => 'Debug',
'disabled' => 'dev' === $mode,
'required' => false,
'choices' => [
'Disabled' => '0',
'Enabled' => '1',
],
'attr' => [
'placeholder' => 'Change your app secret. Will autogenerate if empty.',
],
'row_attr' => [
'class' => 'form-floating mb-3',
],
] )
->add('APP_SECRET', PasswordType::class, [
'label' => 'Secret',
'required' => false,
'attr' => [
'placeholder' => 'Change your app secret. Will autogenerate if empty.',
],
'row_attr' => [
'class' => 'form-floating mb-3',
],
])
->add('DATABASE_URL', TextType::class, [
'label' => 'Database',
'required' => true,
'attr' => [
'placeholder' => 'sql://user:pass@host:port/database',
'data-controller' => 'react',
'data-type' => 'dsn',
'data-args' => json_encode( [
'fields' => $dsnFields,
] ),
],
'row_attr' => [
'class' => 'form-floating mb-3',
],
])
->add('MAILER_DSN', TextType::class, [
'label' => 'Mailer',
'required' => false,
'attr' => [
'placeholder' => 'smtp://user:pass@smtp.example.com:port',
'data-controller' => 'react',
'data-type' => 'dsn',
'data-args' => json_encode( [
'fields' => $dsnFields,
] ),
],
'row_attr' => [
'class' => 'form-floating mb-3',
],
])
->add('SYNCENGINE_MAILER_SENDER', EmailType::class, [
'label' => 'Email sender',
'required' => false,
'attr' => [
'placeholder' => 'webmaster@yourdomain.com'
],
'row_attr' => [
'class' => 'form-floating mb-3',
],
])
->add('SYNCENGINE_MAILER_EMAIL_ADMIN', EmailType::class, [
'label' => 'Send email logs to',
'required' => false,
'attr' => [
'placeholder' => 'webmaster@yourdomain.com'
],
'row_attr' => [
'class' => 'form-floating mb-3',
],
])
->add('SYNCENGINE_TRUSTED_IPS', TextType::class, [
'label' => 'Restrict everything by IP',
'help' => 'Separate multiple IP addresses by comma, admin IP addresses are included.',
'required' => false,
'attr' => [
'placeholder' => '0.0.0.0, 0.0.0.0'
],
'row_attr' => [
'class' => 'form-floating mb-3',
],
]);
}
public function configureOptions( OptionsResolver $resolver ): void
{
$resolver->setDefaults( [] );
}
}