ConfigForm::addDropbox()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 1
eloc 15
c 3
b 1
f 0
nc 1
nop 0
dl 0
loc 21
rs 9.7666
1
<?php
2
3
namespace AnyCloud\Form;
4
5
use Laminas\Form\Element;
0 ignored issues
show
Bug introduced by
The type Laminas\Form\Element was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Laminas\Form\Fieldset;
0 ignored issues
show
Bug introduced by
The type Laminas\Form\Fieldset was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Laminas\Form\Form;
0 ignored issues
show
Bug introduced by
The type Laminas\Form\Form was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class ConfigForm extends Form
10
{
11
    protected $globalSettings;
12
13
    /**
14
     * Initialize the configuration form.
15
     */
16
    public function init(): void
17
    {
18
        $this->addAdapter();
19
        $this->addS3('aws', 'Amazon S3 Storage');
20
        $this->addAzure();
21
        $this->addGoogle();
22
        $this->addS3('wasabi', 'Wasabi Cloud Storage', 'Wasabi');
23
        $this->addS3('digital_ocean', 'DigitalOcean Spaces', 'DigitalOcean');
24
        $this->addS3('scaleway', 'Scaleway Object Storage', 'Scaleway');
25
        $this->addDropbox();
26
    }
27
28
    /**
29
     * Set configuration settings.
30
     */
31
    public function setGlobalSettings($globalSettings): void
32
    {
33
        $this->globalSettings = $globalSettings;
34
    }
35
36
    /**
37
     * Add adapter drop-down options to configuration form.
38
     */
39
    private function addAdapter(): void
40
    {
41
        $this->add([
42
            'name'    => 'anycloud_adapter',
43
            'type'    => Fieldset::class,
44
            'options' => [
45
                'label' => 'Any Cloud Adapter',
46
            ],
47
            'attributes' => [
48
                'id' => 'adapter-fieldset',
49
            ],
50
        ]);
51
        $adapterFieldset = $this->get('anycloud_adapter');
52
        $adapterFieldset->add([
53
            'name'    => 'adapter',
54
            'type'    => Element\Select::class,
0 ignored issues
show
Bug introduced by
The type Laminas\Form\Element\Select was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
55
            'options' => [
56
                'label'         => 'Cloud Service Adapter: ',
57
                'value_options' => [
58
                    'default'       => 'Omeka Default (local server)',
59
                    'aws'           => 'Amazon S3 Storage',
60
                    'azure'         => 'Microsoft Azure Storage',
61
                    'google'        => 'Google Cloud Storage',
62
                    'wasabi'        => 'Wasabi Cloud Storage',
63
                    'digital_ocean' => 'DigitalOcean Spaces',
64
                    'scaleway'      => 'Scaleway Object Storage',
65
                    'dropbox'       => 'Dropbox',
66
                ],
67
            ],
68
            'attributes' => [
69
                'id' => 'adapter',
70
            ],
71
        ]);
72
    }
73
74
    /**
75
     * Add any Amazon S3-based storage adapter.
76
     *
77
     * @param string      $id    ID used to identify adapter
78
     * @param string      $name  Full name of adapter
79
     * @param string|null $label Abbreviated name used for form labels
80
     */
81
    private function addS3($id, $name, $label = null): void
82
    {
83
        $label = $label === null ? $label : $label.' ';
84
        $this->add([
85
            'name'    => 'anycloud_'.$id,
86
            'type'    => Fieldset::class,
87
            'options' => [
88
                'label' => $name,
89
            ],
90
            'attributes' => [
91
                'class' => $id.' fieldset',
92
            ],
93
        ]);
94
        $awsFieldset = $this->get('anycloud_'.$id);
95
        $awsFieldset->add([
96
            'name'    => $id.'_key',
97
            'type'    => Element\Text::class,
0 ignored issues
show
Bug introduced by
The type Laminas\Form\Element\Text was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
98
            'options' => [
99
                'label' => $label.'AWS Key',
100
            ],
101
            'attributes' => [
102
                'id' => $id.'_key',
103
            ],
104
        ]);
105
        $awsFieldset->add([
106
            'name'    => $id.'_secret_key',
107
            'type'    => Element\Text::class,
108
            'options' => [
109
                'label' => $label.'AWS Secret Key',
110
            ],
111
            'attributes' => [
112
                'id'   => $id.'_secret_key',
113
                'cols' => '100',
114
            ],
115
        ]);
116
        $awsFieldset->add([
117
            'name'    => $id.'_bucket',
118
            'type'    => Element\Text::class,
119
            'options' => [
120
                'label' => $label.'AWS Bucket',
121
            ],
122
            'attributes' => [
123
                'id' => $id.'_bucket',
124
            ],
125
        ]);
126
        $awsFieldset->add([
127
            'name'    => $id.'_region',
128
            'type'    => Element\Text::class,
129
            'options' => [
130
                'label' => $label.'AWS Region',
131
            ],
132
            'attributes' => [
133
                'id' => $id.'_region',
134
            ],
135
        ]);
136
        $awsFieldset->add([
137
            'name'    => $id.'_endpoint',
138
            'type'    => Element\Text::class,
139
            'options' => [
140
                'label' => $label.'AWS Endpoint',
141
                'info'  => 'Can usually leave blank unless you have a custom endpoint set up. See https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region',
142
            ],
143
            'attributes' => [
144
                'id' => $id.'_endpoint',
145
            ],
146
        ]);
147
    }
148
149
    /**
150
     * Add Microsoft Azure Storage options to configuration form.
151
     */
152
    private function addAzure(): void
153
    {
154
        $this->add([
155
            'name'    => 'anycloud_azure',
156
            'type'    => Fieldset::class,
157
            'options' => [
158
                'label' => 'Microsoft Azure Storage',
159
            ],
160
            'attributes' => [
161
                'class' => 'azure fieldset',
162
            ],
163
        ]);
164
        $azureFieldset = $this->get('anycloud_azure');
165
        $azureFieldset->add([
166
            'name'    => 'azure_account_name',
167
            'type'    => Element\Text::class,
168
            'options' => [
169
                'label' => 'Azure Account Name',
170
            ],
171
            'attributes' => [
172
                'id' => 'azure_account_name',
173
            ],
174
        ]);
175
        $azureFieldset->add([
176
            'name'    => 'azure_account_key',
177
            'type'    => Element\Text::class,
178
            'options' => [
179
                'label' => 'Azure Account Key',
180
            ],
181
            'attributes' => [
182
                'id' => 'azure_account_key',
183
            ],
184
        ]);
185
        $azureFieldset->add([
186
            'name'    => 'azure_container_name',
187
            'type'    => Element\Text::class,
188
            'options' => [
189
                'label' => 'Azure Container Name',
190
            ],
191
            'attributes' => [
192
                'id' => 'azure_container_name',
193
            ],
194
        ]);
195
        $azureFieldset->add([
196
            'name'    => 'azure_endpoint',
197
            'type'    => Element\Text::class,
198
            'options' => [
199
                'label' => 'Azure Endpoint',
200
                'info'  => 'Can usually leave blank unless you have a custom endpoint set up',
201
            ],
202
            'attributes' => [
203
                'id' => 'azure_endpoint',
204
            ],
205
        ]);
206
    }
207
208
    /**
209
     * Add Google Cloud Storage options to configuration form.
210
     */
211
    private function addGoogle(): void
212
    {
213
        $this->add([
214
            'name'    => 'anycloud_google',
215
            'type'    => Fieldset::class,
216
            'options' => [
217
                'label' => 'Google Cloud Storage',
218
            ],
219
            'attributes' => [
220
                'class' => 'google fieldset',
221
            ],
222
        ]);
223
        $googleFieldset = $this->get('anycloud_google');
224
        $googleFieldset->add([
225
            'name'    => 'google_project_id',
226
            'type'    => Element\Text::class,
227
            'options' => [
228
                'label' => 'Google Project ID',
229
            ],
230
            'attributes' => [
231
                'id' => 'google_project_id',
232
            ],
233
        ]);
234
        $googleFieldset->add([
235
            'name'    => 'google_bucket_name',
236
            'type'    => Element\Text::class,
237
            'options' => [
238
                'label' => 'Google Bucket Name',
239
            ],
240
            'attributes' => [
241
                'id' => 'google_bucket_name',
242
            ],
243
        ]);
244
        $googleFieldset->add([
245
            'name'    => 'google_credentials_path',
246
            'type'    => Element\Text::class,
247
            'options' => [
248
                'label' => 'Google Credentials Path',
249
                'info'  => 'Replace {CONFIG} with the name of your Google credentials file stored at the listed path',
250
                'value' => '/src/Service/File/Adapter/Google/{CONFIG}.json',
251
            ],
252
            'attributes' => [
253
                'id' => 'google_credentials_path',
254
            ],
255
        ]);
256
        $googleFieldset->add([
257
            'name'    => 'google_storage_uri',
258
            'type'    => Element\Text::class,
259
            'options' => [
260
                'label' => 'Google Storage URI',
261
                'info'  => 'You can usually leave this as the default unless you have tweaked other settings',
262
                'value' => 'https://storage.googleapis.com',
263
            ],
264
            'attributes' => [
265
                'id' => 'google_storage_uri',
266
            ],
267
        ]);
268
    }
269
270
    /**
271
     * Add Dropbox options to configuration form.
272
     */
273
    private function addDropbox(): void
274
    {
275
        $this->add([
276
            'name'    => 'anycloud_dropbox',
277
            'type'    => Fieldset::class,
278
            'options' => [
279
                'label' => 'Dropbox',
280
            ],
281
            'attributes' => [
282
                'class' => 'dropbox fieldset',
283
            ],
284
        ]);
285
        $dropboxFieldset = $this->get('anycloud_dropbox');
286
        $dropboxFieldset->add([
287
            'name'    => 'dropbox_access_token',
288
            'type'    => Element\Text::class,
289
            'options' => [
290
                'label' => 'Dropbox Access Token',
291
            ],
292
            'attributes' => [
293
                'id' => 'dropbox_access_token',
294
            ],
295
        ]);
296
    }
297
}
298