1
|
|
|
<?php |
2
|
|
|
namespace HtImgModule\Options; |
3
|
|
|
|
4
|
|
|
use HtImgModule\Exception; |
5
|
|
|
use Zend\Stdlib\AbstractOptions; |
6
|
|
|
|
7
|
|
|
class ModuleOptions extends AbstractOptions implements CacheOptionsInterface, FilterOptionsInterface |
8
|
|
|
{ |
9
|
|
|
protected $__strictMode__ = false; |
10
|
|
|
|
11
|
|
|
protected $enableCache = true; |
12
|
|
|
|
13
|
|
|
protected $imgSourcePathStack = []; |
14
|
|
|
|
15
|
|
|
protected $imgSourceMap = []; |
16
|
|
|
|
17
|
|
|
protected $driver = 'gd'; |
18
|
|
|
|
19
|
|
|
protected $filters = []; |
20
|
|
|
|
21
|
|
|
protected $webRoot = 'public'; |
22
|
|
|
|
23
|
|
|
protected $imageResolvers = []; |
24
|
|
|
|
25
|
|
|
protected $allowedDrivers = [ |
26
|
|
|
'gd', |
27
|
|
|
'imagick', |
28
|
|
|
'gmagick', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
protected $filterLoaders = []; |
32
|
|
|
|
33
|
|
|
protected $cachePath = 'htimg'; |
34
|
|
|
|
35
|
|
|
protected $cacheExpiry = 86400; |
36
|
|
|
|
37
|
|
|
protected $defaultImageLoader = 'FileSystem'; |
38
|
|
|
|
39
|
1 |
|
public function setEnableCache($enableCache) |
40
|
|
|
{ |
41
|
1 |
|
$this->enableCache = (bool) $enableCache; |
42
|
|
|
|
43
|
1 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
public function getEnableCache() |
47
|
|
|
{ |
48
|
1 |
|
return $this->enableCache; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function setImgSourcePathStack(array $imgSourcePathStack) |
52
|
|
|
{ |
53
|
1 |
|
$this->imgSourcePathStack = $imgSourcePathStack; |
54
|
|
|
|
55
|
1 |
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
public function getImgSourcePathStack() |
59
|
|
|
{ |
60
|
3 |
|
return $this->imgSourcePathStack; |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
public function setImgSourceMap($imgSourceMap) |
64
|
|
|
{ |
65
|
1 |
|
$this->imgSourceMap = $imgSourceMap; |
66
|
|
|
|
67
|
1 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
public function getImgSourceMap() |
71
|
|
|
{ |
72
|
2 |
|
return $this->imgSourceMap; |
73
|
|
|
} |
74
|
|
|
|
75
|
2 |
|
public function setDriver($driver) |
76
|
|
|
{ |
77
|
2 |
|
$driver = strtolower($driver); |
78
|
2 |
|
if (!in_array($driver, $this->allowedDrivers)) { |
79
|
1 |
|
throw new Exception\InvalidArgumentException( |
80
|
1 |
|
sprintf( |
81
|
1 |
|
'%s expects parameter 1 to one of %s, %s provided instead', |
82
|
1 |
|
__METHOD__, |
83
|
1 |
|
implode(', ', $this->allowedDrivers), |
84
|
|
|
$driver |
85
|
1 |
|
) |
86
|
1 |
|
); |
87
|
|
|
} |
88
|
1 |
|
$this->driver = $driver; |
89
|
|
|
|
90
|
1 |
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
2 |
|
public function getDriver() |
94
|
|
|
{ |
95
|
2 |
|
return $this->driver; |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
public function setFilters(array $filters) |
99
|
|
|
{ |
100
|
1 |
|
$this->filters = $filters; |
101
|
|
|
|
102
|
1 |
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
6 |
|
public function addFilter($filterName, array $filterOptions) |
106
|
|
|
{ |
107
|
6 |
|
$this->filters[$filterName] = $filterOptions; |
108
|
|
|
|
109
|
6 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
8 |
|
public function getFilters() |
113
|
|
|
{ |
114
|
8 |
|
return $this->filters; |
115
|
|
|
} |
116
|
|
|
|
117
|
1 |
|
public function setWebRoot($webRoot) |
118
|
|
|
{ |
119
|
1 |
|
$this->webRoot = $webRoot; |
120
|
|
|
|
121
|
1 |
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
1 |
|
public function getWebRoot() |
125
|
|
|
{ |
126
|
1 |
|
return $this->webRoot; |
127
|
|
|
} |
128
|
|
|
|
129
|
1 |
|
public function setFilterLoaders(array $filterLoaders) |
130
|
|
|
{ |
131
|
1 |
|
$this->filterLoaders = $filterLoaders; |
132
|
|
|
|
133
|
1 |
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
2 |
|
public function getFilterLoaders() |
137
|
|
|
{ |
138
|
2 |
|
return $this->filterLoaders; |
139
|
|
|
} |
140
|
|
|
|
141
|
1 |
|
public function setCachePath($cachePath) |
142
|
|
|
{ |
143
|
1 |
|
$this->cachePath = $cachePath; |
144
|
|
|
|
145
|
1 |
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
1 |
|
public function getCachePath() |
149
|
|
|
{ |
150
|
1 |
|
return $this->cachePath; |
151
|
|
|
} |
152
|
|
|
|
153
|
1 |
|
public function setCacheExpiry($cacheExpiry) |
154
|
|
|
{ |
155
|
1 |
|
$this->cacheExpiry = (int) $cacheExpiry; |
156
|
|
|
|
157
|
1 |
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
1 |
|
public function getCacheExpiry() |
161
|
|
|
{ |
162
|
1 |
|
return $this->cacheExpiry; |
163
|
|
|
} |
164
|
|
|
|
165
|
2 |
|
public function setImageResolvers(array $imageResolvers) |
166
|
|
|
{ |
167
|
2 |
|
$this->imageResolvers = $imageResolvers; |
168
|
2 |
|
} |
169
|
|
|
|
170
|
3 |
|
public function getImageResolvers() |
171
|
|
|
{ |
172
|
3 |
|
return $this->imageResolvers; |
173
|
|
|
} |
174
|
|
|
|
175
|
1 |
|
public function setDefaultImageLoader($defaultImageLoader) |
176
|
|
|
{ |
177
|
1 |
|
$this->defaultImageLoader = $defaultImageLoader; |
178
|
1 |
|
} |
179
|
|
|
|
180
|
1 |
|
public function getDefaultImageLoader() |
181
|
|
|
{ |
182
|
1 |
|
return $this->defaultImageLoader; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|