Passed
Pull Request — master (#207)
by
unknown
16:03 queued 05:02
created

ClientConfigurationManager::getPrimaryUrnXpath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace EWW\Dpf\Configuration;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
19
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
20
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
21
use TYPO3\CMS\Extbase\Object\ObjectManager;
22
use EWW\Dpf\Domain\Repository\ClientRepository;
23
24
class ClientConfigurationManager
25
{
26
27
    /**
28
     * objectManager
29
     *
30
     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
31
     * @TYPO3\CMS\Extbase\Annotation\Inject
32
     */
33
    protected $objectManager;
34
35
    /**
36
     * clientRepository
37
     *
38
     * @var \EWW\Dpf\Domain\Repository\ClientRepository
39
     * @TYPO3\CMS\Extbase\Annotation\Inject
40
     */
41
    protected $clientRepository;
42
43
    /**
44
     * settings
45
     *
46
     * @var array
47
     */
48
    protected $settings = array();
49
50
51
    /**
52
     * settings
53
     *
54
     * @var \EWW\Dpf\Domain\Model\Client
55
     */
56
    protected $client = null;
57
58
    /**
59
     * extensionConfiguration
60
     *
61
     * @var array
62
     */
63
    protected $extensionConfiguration = array();
64
65
    public function __construct()
66
    {
67
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
68
        $clientRepository = $objectManager->get(ClientRepository::class);
69
70
        if (TYPO3_MODE === 'BE') {
71
            $selectedPageId = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
72
            if ($selectedPageId) {
73
                $this->client = $clientRepository->findAll()->current();
74
75
                $configurationManager = $objectManager->get(BackendConfigurationManager::class);
76
                $settings = $configurationManager->getConfiguration(null, null);
77
                $this->settings = $settings; //['settings'];
78
            }
79
80
        } else {
81
            $this->client = $clientRepository->findAll()->current();
82
83
            $configurationManager = $objectManager->get(ConfigurationManager::class);
84
            $this->settings = $configurationManager->getConfiguration(
85
                \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS
86
            );
87
88
        }
89
90
        $this->extensionConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
91
            \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class
92
        )->get('dpf');
93
94
    }
95
96
    public function setConfigurationPid($pid)
97
    {
98
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
99
        $clientRepository = $objectManager->get(ClientRepository::class);
100
101
        $this->client = $clientRepository->findAllByPid($pid)->current();
102
    }
103
104
105
    /**
106
     * Get setting from client or extension configuration.
107
     *
108
     * @var array
109
     */
110
    public function getSetting($settingName, $extConfig = null)
111
    {
112
        $setting = null;
113
        if ($this->client) {
114
            $setting = trim($this->client->{"get" . ucfirst($settingName)}());
115
        }
116
117
        // use global extConfig if client settings is empty
118
        if (empty($setting) && $extConfig) {
119
            $setting = trim($this->extensionConfiguration[$extConfig]);
120
        }
121
122
        return $setting;
123
    }
124
125
126
    public function getOwnerId()
127
    {
128
        return $this->getSetting("ownerId");
129
    }
130
131
    public function getSwordHost()
132
    {
133
        return $this->getSetting("swordHost", "swordHost");
134
    }
135
136
    public function getSwordUser()
137
    {
138
        return $this->getSetting("swordUser", "swordUser");
139
    }
140
141
    public function getSwordPassword()
142
    {
143
        return $this->getSetting("swordPassword", "swordPassword");
144
    }
145
146
    public function getSwordCollectionNamespace()
147
    {
148
        return $this->getSetting("swordCollectionNamespace", "swordCollectionNamespace");
149
    }
150
151
    public function getFedoraHost()
152
    {
153
        return $this->getSetting("fedoraHost", "fedoraHost");
154
    }
155
156
    public function getFedoraUser()
157
    {
158
        return $this->getSetting("fedoraUser", "fedoraUser");
159
    }
160
161
    public function getFedoraPassword()
162
    {
163
        return $this->getSetting("fedoraPassword", "fedoraPassword");
164
    }
165
166
    public function getElasticSearchHost()
167
    {
168
        return $this->getSetting("elasticSearchHost", "elasticSearchHost");
169
    }
170
171
    public function getElasticSearchPort()
172
    {
173
        return $this->getSetting("elasticSearchPort", "elasticSearchPort");
174
    }
175
176
    public function getUploadDirectory()
177
    {
178
        return $this->getSetting("uploadDirectory", "uploadDirectory");
179
    }
180
181
    public function getUploadDomain()
182
    {
183
        return $this->getSetting("uploadDomain", "uploadDomain");
184
    }
185
186
    public function getSuggestionFlashMessage()
187
    {
188
        return $this->getSetting("suggestionFlashmessage", "suggestionFlashmessage");
189
    }
190
191
    public function getFileXpath()
192
    {
193
        return $this->getSetting("fileXpath", "fileXpath");
194
    }
195
196
    public function getStateXpath()
197
    {
198
        return $this->getSetting("stateXpath", "stateXpath");
199
    }
200
201
    public function getTypeXpath()
202
    {
203
        return $this->getSetting("typeXpath", "typeXpath");
204
    }
205
206
    public function getTypeXpathInput()
207
    {
208
        return $this->getSetting("typeXpathInput", "typeXpathInput");
209
    }
210
211
    public function getUrnXpath()
212
    {
213
        return $this->getSetting("urnXpath", "urnXpath");
214
    }
215
216
    public function getPrimaryUrnXpath()
217
    {
218
        return $this->getSetting("primaryUrnXpath", "primaryUrnXpath");
219
    }
220
221
    public function getDateXpath()
222
    {
223
        return $this->getSetting("dateXpath", "dateXpath");
224
    }
225
226
    public function getPublishingYearXpath()
227
    {
228
        return $this->getSetting("publishingYearXpath", "publishingYearXpath");
229
    }
230
231
    public function getNamespaces()
232
    {
233
        return $this->getSetting("namespaces", "namespaces");
234
    }
235
236
    public function getTitleXpath()
237
    {
238
        return $this->getSetting("titleXpath", "titleXpath");
239
    }
240
241
    public function getOriginalSourceTitleXpath()
242
    {
243
        return $this->getSetting("originalSourceTitleXpath", "originalSourceTitleXpath");
244
    }
245
246
    public function getProcessNumberXpath()
247
    {
248
        return $this->getSetting("processnumberXpath", "processnumberXpath");
249
    }
250
251
    public function getSubmitterNameXpath()
252
    {
253
        return $this->getSetting("submitterNameXpath", "submitterNameXpath");
254
    }
255
256
    public function getSubmitterEmailXpath()
257
    {
258
        return $this->getSetting("submitterEmailXpath", "submitterEmailXpath");
259
    }
260
261
    public function getSubmitterNoticeXpath()
262
    {
263
        return $this->getSetting("submitterNoticeXpath", "submitterNoticeXpath");
264
    }
265
266
    public function getCreatorXpath()
267
    {
268
        return $this->getSetting("creatorXpath", "creatorXpath");
269
    }
270
271
    public function getCreationDateXpath()
272
    {
273
        return $this->getSetting("creationDateXpath", "creationDateXpath");
274
    }
275
276
    public function getRepositoryCreationDateXpath()
277
    {
278
        return $this->getSetting("repositoryCreationDateXpath", "repositoryCreationDateXpath");
279
    }
280
281
    public function getRepositoryLastModDateXpath()
282
    {
283
        return $this->getSetting("repositoryLastModDateXpath", "repositoryLastModDateXpath");
284
    }
285
286
    public function getDepositLicenseXpath()
287
    {
288
        return $this->getSetting("depositLicenseXpath", "depositLicenseXpath");
289
    }
290
291
    public function getAllNotesXpath()
292
    {
293
        return $this->getSetting("allNotesXpath", "allNotesXpath");
294
    }
295
296
    public function getPrivateNotesXpath()
297
    {
298
        return $this->getSetting("privateNotesXpath", "privateNotesXpath");
299
    }
300
301
    public function getInputTransformation()
302
    {
303
        return $this->client->getInputTransformation()->current();
304
    }
305
306
    public function getOutputTransformation()
307
    {
308
        return $this->client->getOutputTransformation()->current();
309
    }
310
311
    public function getPersonXpath()
312
    {
313
        return $this->getSetting("personXpath", "personXpath");
314
    }
315
316
    public function getPersonFamilyXpath()
317
    {
318
        return $this->getSetting("personFamilyXpath", "personFamilyXpath");
319
    }
320
321
    public function getPersonGivenXpath()
322
    {
323
        return $this->getSetting("personGivenXpath", "personGivenXpath");
324
    }
325
326
    public function getPersonRoleXpath()
327
    {
328
        return $this->getSetting("personRoleXpath", "personRoleXpath");
329
    }
330
331
    public function getPersonFisIdentifierXpath()
332
    {
333
        return $this->getSetting("personFisIdentifierXpath", "personFisIdentifierXpath");
334
    }
335
336
    public function getPersonAffiliationXpath()
337
    {
338
        return $this->getSetting("personAffiliationXpath", "personAffiliationXpath");
339
    }
340
341
    public function getPersonAffiliationIdentifierXpath()
342
    {
343
        return $this->getSetting("personAffiliationIdentifierXpath", "personAffiliationIdentifierXpath");
344
    }
345
346
    public function getPersonAuthorRole()
347
    {
348
        return $this->getSetting("personAuthorRole", "personAuthorRole");
349
    }
350
351
    public function getPersonPublisherRole()
352
    {
353
        return $this->getSetting("personPublisherRole", "personPublisherRole");
354
    }
355
356
    public function getValidationXpath()
357
    {
358
        return $this->getSetting("validationXpath", "validationXpath");
359
    }
360
361
    public function fisIdXpath()
362
    {
363
        return $this->getSetting("fisIdXpath", "fisIdXpath");
364
    }
365
366
    public function getSourceDetailsXpaths()
367
    {
368
        return $this->getSetting("sourceDetailsXpaths", "sourceDetailsXpaths");
369
    }
370
371
    public function getFedoraNamespace()
372
    {
373
        $settings = $this->getTypoScriptSettings();
374
        return $settings['fedoraNamespace'];
375
    }
376
377
    public function getTypoScriptSettings()
378
    {
379
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
380
        $configurationManager = $objectManager->get(ConfigurationManager::class);
381
        $settings = $configurationManager->getConfiguration(
382
            ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS
383
        );
384
385
        return $settings;
386
    }
387
388
    public function getFileIdXpath()
389
    {
390
        return $this->trimFileXpath($this->getSetting("fileIdXpath", "fileIdXpath"));
0 ignored issues
show
Bug introduced by
It seems like $this->getSetting('fileIdXpath', 'fileIdXpath') can also be of type null; however, parameter $xpath of EWW\Dpf\Configuration\Cl...anager::trimFileXpath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

390
        return $this->trimFileXpath(/** @scrutinizer ignore-type */ $this->getSetting("fileIdXpath", "fileIdXpath"));
Loading history...
391
    }
392
393
    public function getFileMimetypeXpath()
394
    {
395
        return $this->trimFileXpath($this->getSetting("fileMimetypeXpath", "fileMimetypeXpath"));
0 ignored issues
show
Bug introduced by
It seems like $this->getSetting('fileM...', 'fileMimetypeXpath') can also be of type null; however, parameter $xpath of EWW\Dpf\Configuration\Cl...anager::trimFileXpath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

395
        return $this->trimFileXpath(/** @scrutinizer ignore-type */ $this->getSetting("fileMimetypeXpath", "fileMimetypeXpath"));
Loading history...
396
    }
397
398
    public function getFileHrefXpath()
399
    {
400
        return $this->trimFileXpath($this->getSetting("fileHrefXpath", "fileHrefXpath"));
0 ignored issues
show
Bug introduced by
It seems like $this->getSetting('fileH...path', 'fileHrefXpath') can also be of type null; however, parameter $xpath of EWW\Dpf\Configuration\Cl...anager::trimFileXpath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

400
        return $this->trimFileXpath(/** @scrutinizer ignore-type */ $this->getSetting("fileHrefXpath", "fileHrefXpath"));
Loading history...
401
    }
402
403
    public function getFileDownloadXpath()
404
    {
405
        return $this->trimFileXpath($this->getSetting("fileDownloadXpath", "fileDownloadXpath"));
0 ignored issues
show
Bug introduced by
It seems like $this->getSetting('fileD...', 'fileDownloadXpath') can also be of type null; however, parameter $xpath of EWW\Dpf\Configuration\Cl...anager::trimFileXpath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

405
        return $this->trimFileXpath(/** @scrutinizer ignore-type */ $this->getSetting("fileDownloadXpath", "fileDownloadXpath"));
Loading history...
406
    }
407
408
    public function getFileArchiveXpath()
409
    {
410
        return $this->trimFileXpath($this->getSetting("fileArchiveXpath", "fileArchiveXpath"));
0 ignored issues
show
Bug introduced by
It seems like $this->getSetting('fileA...h', 'fileArchiveXpath') can also be of type null; however, parameter $xpath of EWW\Dpf\Configuration\Cl...anager::trimFileXpath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

410
        return $this->trimFileXpath(/** @scrutinizer ignore-type */ $this->getSetting("fileArchiveXpath", "fileArchiveXpath"));
Loading history...
411
    }
412
413
    public function getFileDeletedXpath()
414
    {
415
        return$this->trimFileXpath($this->getSetting("fileDeletedXpath", "fileDeletedXpath"));
0 ignored issues
show
Bug introduced by
It seems like $this->getSetting('fileD...h', 'fileDeletedXpath') can also be of type null; however, parameter $xpath of EWW\Dpf\Configuration\Cl...anager::trimFileXpath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

415
        return$this->trimFileXpath(/** @scrutinizer ignore-type */ $this->getSetting("fileDeletedXpath", "fileDeletedXpath"));
Loading history...
416
    }
417
418
    public function getFileTitleXpath()
419
    {
420
        return $this->trimFileXpath($this->getSetting("fileTitleXpath", "fileTitleXpath"));
0 ignored issues
show
Bug introduced by
It seems like $this->getSetting('fileT...ath', 'fileTitleXpath') can also be of type null; however, parameter $xpath of EWW\Dpf\Configuration\Cl...anager::trimFileXpath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

420
        return $this->trimFileXpath(/** @scrutinizer ignore-type */ $this->getSetting("fileTitleXpath", "fileTitleXpath"));
Loading history...
421
    }
422
423
    /**
424
     * @param string $xpath
425
     * @return string
426
     */
427
    protected function trimFileXpath(string $xpath): ?string
428
    {
429
        return trim($xpath, "@/ ");
430
    }
431
}
432