1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApacheSolrForTypo3\Tika\Service\Tika; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
* This file is part of the TYPO3 CMS project. |
9
|
|
|
* |
10
|
|
|
* It is free software; you can redistribute it and/or modify it under |
11
|
|
|
* the terms of the GNU General Public License, either version 2 |
12
|
|
|
* of the License, or any later version. |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please read the |
15
|
|
|
* LICENSE.txt file that was distributed with this source code. |
16
|
|
|
* |
17
|
|
|
* The TYPO3 project - inspiring people to share! |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
use ApacheSolrForTypo3\Tika\Util; |
21
|
|
|
use InvalidArgumentException; |
22
|
|
|
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; |
23
|
|
|
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; |
24
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Provides a Tika service depending on the extension's configuration |
28
|
|
|
* |
29
|
|
|
* @author Ingo Renner <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class ServiceFactory |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Creates an instance of a Tika service |
35
|
|
|
* |
36
|
|
|
* @param string $tikaServiceType Tika Service type, one of jar, server, or solr (or tika for BC, same as jar) |
37
|
|
|
* @param array|null $configuration EXT:tika EM configuration (initialized by this factory, parameter exists for tests) |
38
|
|
|
* @return AppService|ServerService|SolrCellService |
39
|
|
|
* |
40
|
|
|
* @throws ExtensionConfigurationExtensionNotConfiguredException |
41
|
|
|
* @throws ExtensionConfigurationPathDoesNotExistException |
42
|
|
|
*/ |
43
|
5 |
|
public static function getTika(string $tikaServiceType, array $configuration = null) |
44
|
|
|
{ |
45
|
5 |
|
if (empty($configuration)) { |
46
|
|
|
$configuration = Util::getTikaExtensionConfiguration(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
switch ($tikaServiceType) { |
50
|
5 |
|
case 'jar': |
51
|
4 |
|
case 'tika': // backwards compatibility only |
52
|
2 |
|
return GeneralUtility::makeInstance(AppService::class, $configuration); |
53
|
3 |
|
case 'server': |
54
|
1 |
|
return GeneralUtility::makeInstance(ServerService::class, $configuration); |
55
|
2 |
|
case 'solr': |
56
|
1 |
|
return GeneralUtility::makeInstance(SolrCellService::class, $configuration); |
57
|
|
|
default: |
58
|
1 |
|
throw new InvalidArgumentException( |
59
|
1 |
|
'Unknown Tika service type "' . $tikaServiceType . '". Must be one of jar, server, or solr.', |
60
|
1 |
|
1423035119 |
61
|
1 |
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Creates a tika service instance from the extension configuration. |
67
|
|
|
* |
68
|
|
|
* @return AppService|ServerService|SolrCellService |
69
|
|
|
*/ |
70
|
|
|
public static function getConfiguredTika(): AbstractService |
71
|
|
|
{ |
72
|
|
|
$tikaConfiguration = Util::getTikaExtensionConfiguration(); |
73
|
|
|
return static::getTika($tikaConfiguration['extractor'], Util::getTikaExtensionConfiguration()); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|