1
|
|
|
<?php |
2
|
|
|
namespace Aoe\Asdis\System\Configuration; |
3
|
|
|
|
4
|
|
|
use Aoe\Asdis\System\Configuration\Exception\InvalidStructure; |
5
|
|
|
use Aoe\Asdis\System\Configuration\TypoScriptConfiguration; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Provides all configuration settings. |
9
|
|
|
*/ |
10
|
|
|
class Provider |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \Aoe\Asdis\System\Configuration\TypoScriptConfiguration |
14
|
|
|
*/ |
15
|
|
|
private $typoScriptConfiguration; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param \Aoe\Asdis\System\Configuration\TypoScriptConfiguration $typoScriptConfiguration |
19
|
|
|
*/ |
20
|
|
|
public function injectTypoScriptConfiguration(TypoScriptConfiguration $typoScriptConfiguration) |
21
|
|
|
{ |
22
|
|
|
$this->typoScriptConfiguration = $typoScriptConfiguration; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Tells if the assets on the current page should be replaced. |
27
|
|
|
* |
28
|
|
|
* @return boolean |
29
|
|
|
*/ |
30
|
|
|
public function isReplacementEnabled() |
31
|
|
|
{ |
32
|
|
|
return (boolean) ((integer) $this->typoScriptConfiguration->getSetting('enabled')); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* This disables any processing in hook handlers of the asdis extension. |
37
|
|
|
* You can use this, if you have to implement your own hook processing in another extension. |
38
|
|
|
* |
39
|
|
|
* @return boolean |
40
|
|
|
*/ |
41
|
|
|
public function isDefaultHookHandlingDisabled() |
42
|
|
|
{ |
43
|
|
|
return (boolean)((integer)$this->typoScriptConfiguration->getSetting('disableDefaultHookHandling')); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function getDistributionAlgorithmKey() |
50
|
|
|
{ |
51
|
|
|
return (string) $this->typoScriptConfiguration->getSetting('distributionAlgorithm'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the scraper keys for the current page. |
56
|
|
|
* |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function getScraperKeys() |
60
|
|
|
{ |
61
|
|
|
$keyList = $this->typoScriptConfiguration->getSetting('scrapers', 'string'); |
62
|
|
|
$keys = explode(",", $keyList); |
63
|
|
|
if (FALSE === is_array($keys) || sizeof($keys) < 1) { |
64
|
|
|
return []; |
65
|
|
|
} |
66
|
|
|
$scraperKeys = []; |
67
|
|
|
foreach ($keys as $key) { |
68
|
|
|
$scraperKeys[] = trim($key); |
69
|
|
|
} |
70
|
|
|
return $scraperKeys; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns the filter keys for the current page. |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
public function getFilterKeys() |
79
|
|
|
{ |
80
|
|
|
$keyList = $this->typoScriptConfiguration->getSetting('filters', 'string'); |
81
|
|
|
$keys = explode(',', $keyList); |
82
|
|
|
|
83
|
|
|
if (FALSE === is_array($keys) || sizeof($keys) < 1) { |
84
|
|
|
return []; |
85
|
|
|
} |
86
|
|
|
$filterKeys = []; |
87
|
|
|
foreach ($keys as $key) { |
88
|
|
|
$filterKeys[] = trim($key); |
89
|
|
|
} |
90
|
|
|
return $filterKeys; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns an array like this: |
95
|
|
|
* array( |
96
|
|
|
* array( |
97
|
|
|
* 'identifier' => 'media1', |
98
|
|
|
* 'domain' => 'm1.mydomain.com', |
99
|
|
|
* 'protocol' => 'dynamic' |
100
|
|
|
* ), |
101
|
|
|
* array( |
102
|
|
|
* 'identifier' => 'media2', |
103
|
|
|
* 'domain' => 'm2.mydomain.com', |
104
|
|
|
* 'protocol' => 'http' |
105
|
|
|
* ) |
106
|
|
|
* ) |
107
|
|
|
* |
108
|
|
|
* @return array |
109
|
|
|
* @throws \Aoe\Asdis\System\Configuration\Exception\InvalidStructure |
110
|
|
|
*/ |
111
|
|
|
public function getServerDefinitions() |
112
|
|
|
{ |
113
|
|
|
$definitions = array(); |
114
|
|
|
$serverDefinitions = $this->typoScriptConfiguration->getSetting('servers', 'array', true); |
115
|
|
|
foreach($serverDefinitions as $identifier => $serverDefinition) { |
116
|
|
|
if (false === is_array($serverDefinition) || false === isset($serverDefinition['domain'])) { |
117
|
|
|
throw new InvalidStructure( |
118
|
|
|
'Configured server definition for "'.((string) $serverDefinition) . '" is invalid.', |
119
|
|
|
1372159113552 |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
if (false === isset($serverDefinition['protocol'])) { |
123
|
|
|
$serverDefinition['protocol'] = 'marker'; |
124
|
|
|
} |
125
|
|
|
$definitions[] = [ |
126
|
|
|
'identifier' => $identifier, |
127
|
|
|
'domain' => $serverDefinition['domain'], |
128
|
|
|
'protocol' => $serverDefinition['protocol'] |
129
|
|
|
]; |
130
|
|
|
} |
131
|
|
|
return $definitions; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
public function getServerProtocolMarker() |
138
|
|
|
{ |
139
|
|
|
return $this->typoScriptConfiguration->getSetting('serverProtocolMarker', 'string'); |
140
|
|
|
} |
141
|
|
|
} |