1
|
|
|
<?php |
2
|
|
|
namespace Aoe\Imgix\TYPO3; |
3
|
|
|
|
4
|
|
|
use Aoe\Imgix\Utils\ArrayUtils; |
5
|
|
|
use Aoe\Imgix\Utils\TypeUtils; |
6
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; |
7
|
|
|
|
8
|
|
|
class Configuration |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var array |
12
|
|
|
*/ |
13
|
|
|
protected static $imgixFluidOptionsTypeMap = [ |
14
|
|
|
'fluidClass' => TypeUtils::TYPE_STRING, |
15
|
|
|
'updateOnResize' => TypeUtils::TYPE_BOOLEAN, |
16
|
|
|
'updateOnResizeDown' => TypeUtils::TYPE_BOOLEAN, |
17
|
|
|
'updateOnPinchZoom' => TypeUtils::TYPE_BOOLEAN, |
18
|
|
|
'highDPRAutoScaleQuality' => TypeUtils::TYPE_BOOLEAN, |
19
|
|
|
'autoInsertCSSBestPractices' => TypeUtils::TYPE_BOOLEAN, |
20
|
|
|
'fitImgTagToContainerWidth' => TypeUtils::TYPE_BOOLEAN, |
21
|
|
|
'fitImgTagToContainerHeight' => TypeUtils::TYPE_BOOLEAN, |
22
|
|
|
'pixelStep' => TypeUtils::TYPE_INTEGER, |
23
|
|
|
'ignoreDPR' => TypeUtils::TYPE_BOOLEAN, |
24
|
|
|
'debounce' => TypeUtils::TYPE_INTEGER, |
25
|
|
|
'lazyLoad' => TypeUtils::TYPE_BOOLEAN, |
26
|
|
|
'lazyLoadOffsetVertical' => TypeUtils::TYPE_INTEGER, |
27
|
|
|
'lazyLoadOffsetHorizontal' => TypeUtils::TYPE_INTEGER, |
28
|
|
|
'throttle' => TypeUtils::TYPE_INTEGER, |
29
|
|
|
'maxWidth' => TypeUtils::TYPE_INTEGER, |
30
|
|
|
'maxHeight' => TypeUtils::TYPE_INTEGER, |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
private $configuration = array(); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
private $settings; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param ConfigurationManagerInterface $configurationManager |
45
|
|
|
*/ |
46
|
12 |
|
public function __construct(ConfigurationManagerInterface $configurationManager) |
47
|
|
|
{ |
48
|
12 |
|
$this->settings = $configurationManager->getConfiguration( |
49
|
12 |
|
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, |
50
|
|
|
'imgix' |
51
|
12 |
|
); |
52
|
12 |
|
$this->configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['imgix']); |
53
|
12 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
2 |
|
public function isEnabled() |
59
|
|
|
{ |
60
|
2 |
|
if (isset($this->settings['enabled']) && '' !== $this->settings['enabled']) { |
61
|
1 |
|
return (boolean)$this->settings['enabled']; |
62
|
|
|
} |
63
|
1 |
|
return (boolean)$this->configuration['enabled']; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
2 |
|
public function isFluidEnabled() |
70
|
|
|
{ |
71
|
2 |
|
if (isset($this->settings['enableFluid']) && '' !== $this->settings['enableFluid']) { |
72
|
1 |
|
return (boolean)$this->settings['enableFluid']; |
73
|
|
|
} |
74
|
1 |
|
return (boolean)$this->configuration['enableFluid']; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
2 |
|
public function isObservationEnabled() |
81
|
|
|
{ |
82
|
2 |
|
if (isset($this->settings['enableObservation']) && '' !== $this->settings['enableObservation']) { |
83
|
1 |
|
return (boolean)$this->settings['enableObservation']; |
84
|
|
|
} |
85
|
1 |
|
return (boolean)$this->configuration['enableObservation']; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
2 |
|
public function getHost() |
92
|
|
|
{ |
93
|
2 |
|
if (isset($this->settings['host']) && '' !== $this->settings['host']) { |
94
|
1 |
|
return (string)$this->settings['host']; |
95
|
|
|
} |
96
|
1 |
|
return (string)$this->configuration['host']; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
2 |
|
public function getImgixFluidOptions() |
103
|
|
|
{ |
104
|
2 |
|
if (isset($this->configuration['imgix.']['fluid.'])) { |
105
|
1 |
|
$options = ArrayUtils::filterEmptyValues($this->configuration['imgix.']['fluid.']); |
106
|
1 |
|
$options = TypeUtils::castTypesByMap(self::$imgixFluidOptionsTypeMap, $options); |
107
|
1 |
|
return $options; |
108
|
|
|
} |
109
|
1 |
|
return []; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
2 |
|
public function getImgixDefaultUrlParameters() |
116
|
|
|
{ |
117
|
2 |
|
if (isset($this->configuration['imgix.']['defaultUrlParameters'])) { |
118
|
1 |
|
parse_str($this->configuration['imgix.']['defaultUrlParameters'], $defaultUrlParameters); |
119
|
1 |
|
return $defaultUrlParameters; |
120
|
|
|
} |
121
|
1 |
|
return []; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|