Passed
Pull Request — master (#21)
by
unknown
02:36
created

ConfigForm::addDropbox()   A

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->addRackspace();
26
        $this->addDropbox();
27
    }
28
29
    /**
30
     * Set configuration settings.
31
     */
32
    public function setGlobalSettings($globalSettings): void
33
    {
34
        $this->globalSettings = $globalSettings;
35
    }
36
37
    /**
38
     * Add adapter drop-down options to configuration form.
39
     */
40
    private function addAdapter(): void
41
    {
42
        $this->add([
43
            'name'    => 'anycloud_adapter',
44
            'type'    => Fieldset::class,
45
            'options' => [
46
                'label' => 'Any Cloud Adapter',
47
            ],
48
            'attributes' => [
49
                'id' => 'adapter-fieldset',
50
            ],
51
        ]);
52
        $adapterFieldset = $this->get('anycloud_adapter');
53
        $adapterFieldset->add([
54
            'name'    => 'adapter',
55
            '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...
56
            'options' => [
57
                'label'         => 'Cloud Service Adapter: ',
58
                'value_options' => [
59
                    'default'       => 'Omeka Default (local server)',
60
                    'aws'           => 'Amazon S3 Storage',
61
                    'azure'         => 'Microsoft Azure Storage',
62
                    'google'        => 'Google Cloud Storage',
63
                    'wasabi'        => 'Wasabi Cloud Storage',
64
                    'digital_ocean' => 'DigitalOcean Spaces',
65
                    'scaleway'      => 'Scaleway Object Storage',
66
                    'rackspace'     => 'Rackspace Files',
67
                    'dropbox'       => 'Dropbox',
68
                ],
69
            ],
70
            'attributes' => [
71
                'id' => 'adapter',
72
            ],
73
        ]);
74
    }
75
76
    /**
77
     * Add any Amazon S3-based storage adapter.
78
     *
79
     * @param string      $id    ID used to identify adapter
80
     * @param string      $name  Full name of adapter
81
     * @param string|null $label Abbreviated name used for form labels
82
     */
83
    private function addS3($id, $name, $label = null): void
84
    {
85
        $label = $label === null ? $label : $label.' ';
86
        $this->add([
87
            'name'    => 'anycloud_'.$id,
88
            'type'    => Fieldset::class,
89
            'options' => [
90
                'label' => $name,
91
            ],
92
            'attributes' => [
93
                'class' => $id.' fieldset',
94
            ],
95
        ]);
96
        $awsFieldset = $this->get('anycloud_'.$id);
97
        $awsFieldset->add([
98
            'name'    => $id.'_key',
99
            '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...
100
            'options' => [
101
                'label' => $label.'AWS Key',
102
            ],
103
            'attributes' => [
104
                'id' => $id.'_key',
105
            ],
106
        ]);
107
        $awsFieldset->add([
108
            'name'    => $id.'_secret_key',
109
            'type'    => Element\Text::class,
110
            'options' => [
111
                'label' => $label.'AWS Secret Key',
112
            ],
113
            'attributes' => [
114
                'id'   => $id.'_secret_key',
115
                'cols' => '100',
116
            ],
117
        ]);
118
        $awsFieldset->add([
119
            'name'    => $id.'_bucket',
120
            'type'    => Element\Text::class,
121
            'options' => [
122
                'label' => $label.'AWS Bucket',
123
            ],
124
            'attributes' => [
125
                'id' => $id.'_bucket',
126
            ],
127
        ]);
128
        $awsFieldset->add([
129
            'name'    => $id.'_region',
130
            'type'    => Element\Text::class,
131
            'options' => [
132
                'label' => $label.'AWS Region',
133
            ],
134
            'attributes' => [
135
                'id' => $id.'_region',
136
            ],
137
        ]);
138
        $awsFieldset->add([
139
            'name'    => $id.'_endpoint',
140
            'type'    => Element\Text::class,
141
            'options' => [
142
                'label' => $label.'AWS Endpoint',
143
                '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',
144
            ],
145
            'attributes' => [
146
                'id' => $id.'_endpoint',
147
            ],
148
        ]);
149
    }
150
151
    /**
152
     * Add Microsoft Azure Storage options to configuration form.
153
     */
154
    private function addAzure(): void
155
    {
156
        $this->add([
157
            'name'    => 'anycloud_azure',
158
            'type'    => Fieldset::class,
159
            'options' => [
160
                'label' => 'Microsoft Azure Storage',
161
            ],
162
            'attributes' => [
163
                'class' => 'azure fieldset',
164
            ],
165
        ]);
166
        $azureFieldset = $this->get('anycloud_azure');
167
        $azureFieldset->add([
168
            'name'    => 'azure_account_name',
169
            'type'    => Element\Text::class,
170
            'options' => [
171
                'label' => 'Azure Account Name',
172
            ],
173
            'attributes' => [
174
                'id' => 'azure_account_name',
175
            ],
176
        ]);
177
        $azureFieldset->add([
178
            'name'    => 'azure_account_key',
179
            'type'    => Element\Text::class,
180
            'options' => [
181
                'label' => 'Azure Account Key',
182
            ],
183
            'attributes' => [
184
                'id' => 'azure_account_key',
185
            ],
186
        ]);
187
        $azureFieldset->add([
188
            'name'    => 'azure_container_name',
189
            'type'    => Element\Text::class,
190
            'options' => [
191
                'label' => 'Azure Container Name',
192
            ],
193
            'attributes' => [
194
                'id' => 'azure_container_name',
195
            ],
196
        ]);
197
        $azureFieldset->add([
198
            'name'    => 'azure_endpoint',
199
            'type'    => Element\Text::class,
200
            'options' => [
201
                'label' => 'Azure Endpoint',
202
                'info'  => 'Can usually leave blank unless you have a custom endpoint set up',
203
            ],
204
            'attributes' => [
205
                'id' => 'azure_endpoint',
206
            ],
207
        ]);
208
    }
209
210
    /**
211
     * Add Google Cloud Storage options to configuration form.
212
     */
213
    private function addGoogle(): void
214
    {
215
        $this->add([
216
            'name'    => 'anycloud_google',
217
            'type'    => Fieldset::class,
218
            'options' => [
219
                'label' => 'Google Cloud Storage',
220
            ],
221
            'attributes' => [
222
                'class' => 'google fieldset',
223
            ],
224
        ]);
225
        $googleFieldset = $this->get('anycloud_google');
226
        $googleFieldset->add([
227
            'name'    => 'google_project_id',
228
            'type'    => Element\Text::class,
229
            'options' => [
230
                'label' => 'Google Project ID',
231
            ],
232
            'attributes' => [
233
                'id' => 'google_project_id',
234
            ],
235
        ]);
236
        $googleFieldset->add([
237
            'name'    => 'google_bucket_name',
238
            'type'    => Element\Text::class,
239
            'options' => [
240
                'label' => 'Google Bucket Name',
241
            ],
242
            'attributes' => [
243
                'id' => 'google_bucket_name',
244
            ],
245
        ]);
246
        $googleFieldset->add([
247
            'name'    => 'google_credentials_path',
248
            'type'    => Element\Text::class,
249
            'options' => [
250
                'label' => 'Google Credentials Path',
251
                'info'  => 'Replace {CONFIG} with the name of your Google credentials file stored at the listed path',
252
                'value' => '/src/Service/File/Adapter/Google/{CONFIG}.json',
253
            ],
254
            'attributes' => [
255
                'id' => 'google_credentials_path',
256
            ],
257
        ]);
258
        $googleFieldset->add([
259
            'name'    => 'google_storage_uri',
260
            'type'    => Element\Text::class,
261
            'options' => [
262
                'label' => 'Google Storage URI',
263
                'info'  => 'You can usually leave this as the default unless you have tweaked other settings',
264
                'value' => 'https://storage.googleapis.com',
265
            ],
266
            'attributes' => [
267
                'id' => 'google_storage_uri',
268
            ],
269
        ]);
270
    }
271
272
    /**
273
     * Add Rackspace Files options to configuration form.
274
     */
275
    private function addRackspace(): void
276
    {
277
        $this->add([
278
            'name'    => 'anycloud_rackspace',
279
            'type'    => Fieldset::class,
280
            'options' => [
281
                'label' => 'Rackspace Files',
282
            ],
283
            'attributes' => [
284
                'class' => 'rackspace fieldset',
285
            ],
286
        ]);
287
        $rackspaceFieldset = $this->get('anycloud_rackspace');
288
        $rackspaceFieldset->add([
289
            'name'    => 'rackspace_identity_endpoint',
290
            'type'    => Element\Text::class,
291
            'options' => [
292
                'label' => 'Rackspace Identity Endpoint',
293
                'info'  => 'Valid options include “US_IDENTITY_ENDPOINT” and “UK_IDENTITY_ENDPOINT”',
294
            ],
295
            'attributes' => [
296
                'id' => 'rackspace_identity_endpoint',
297
            ],
298
        ]);
299
        $rackspaceFieldset->add([
300
            'name'    => 'rackspace_username',
301
            'type'    => Element\Text::class,
302
            'options' => [
303
                'label' => 'Rackspace Username',
304
            ],
305
            'attributes' => [
306
                'id' => 'rackspace_username',
307
            ],
308
        ]);
309
        $rackspaceFieldset->add([
310
            'name'    => 'rackspace_password',
311
            'type'    => Element\Text::class,
312
            'options' => [
313
                'label' => 'Rackspace Password',
314
            ],
315
            'attributes' => [
316
                'id' => 'rackspace_password',
317
            ],
318
        ]);
319
        $rackspaceFieldset->add([
320
            'name'    => 'rackspace_container',
321
            'type'    => Element\Text::class,
322
            'options' => [
323
                'label' => 'Rackspace Container Name',
324
            ],
325
            'attributes' => [
326
                'id' => 'rackspace_container',
327
            ],
328
        ]);
329
        $rackspaceFieldset->add([
330
            'name'    => 'rackspace_region',
331
            'type'    => Element\Text::class,
332
            'options' => [
333
                'label' => 'Rackspace Region',
334
            ],
335
            'attributes' => [
336
                'id' => 'rackspace_region',
337
            ],
338
        ]);
339
    }
340
341
    /**
342
     * Add Dropbox options to configuration form.
343
     */
344
    private function addDropbox(): void
345
    {
346
        $this->add([
347
            'name'    => 'anycloud_dropbox',
348
            'type'    => Fieldset::class,
349
            'options' => [
350
                'label' => 'Dropbox',
351
            ],
352
            'attributes' => [
353
                'class' => 'dropbox fieldset',
354
            ],
355
        ]);
356
        $dropboxFieldset = $this->get('anycloud_dropbox');
357
        $dropboxFieldset->add([
358
            'name'    => 'dropbox_access_token',
359
            'type'    => Element\Text::class,
360
            'options' => [
361
                'label' => 'Dropbox Access Token',
362
            ],
363
            'attributes' => [
364
                'id' => 'dropbox_access_token',
365
            ],
366
        ]);
367
    }
368
}
369