1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet. |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU Lesser General Public |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16
|
|
|
* Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Lesser General Public |
19
|
|
|
* License along with this library; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21
|
|
|
* |
22
|
|
|
* @category PhpSpreadsheet |
23
|
|
|
* |
24
|
|
|
* @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
25
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
26
|
|
|
*/ |
27
|
|
|
class Settings |
28
|
|
|
{ |
29
|
|
|
/** Optional Chart Rendering libraries */ |
30
|
|
|
const CHART_RENDERER_JPGRAPH = 'JpGraph'; |
31
|
|
|
|
32
|
|
|
/** Optional PDF Rendering libraries */ |
33
|
|
|
const PDF_RENDERER_TCPDF = 'TcPDF'; |
34
|
|
|
const PDF_RENDERER_DOMPDF = 'DomPDF'; |
35
|
|
|
const PDF_RENDERER_MPDF = 'MPDF'; |
36
|
|
|
|
37
|
|
|
private static $chartRenderers = [ |
38
|
|
|
self::CHART_RENDERER_JPGRAPH, |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
private static $pdfRenderers = [ |
42
|
|
|
self::PDF_RENDERER_TCPDF, |
43
|
|
|
self::PDF_RENDERER_DOMPDF, |
44
|
|
|
self::PDF_RENDERER_MPDF, |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Name of the external Library used for rendering charts |
49
|
|
|
* e.g. |
50
|
|
|
* jpgraph. |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private static $chartRendererName; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Directory Path to the external Library used for rendering charts. |
58
|
|
|
* |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
private static $chartRendererPath; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Name of the external Library used for rendering PDF files |
65
|
|
|
* e.g. |
66
|
|
|
* mPDF. |
67
|
|
|
* |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
private static $pdfRendererName; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Default options for libxml loader. |
74
|
|
|
* |
75
|
|
|
* @var int |
76
|
|
|
*/ |
77
|
|
|
private static $libXmlLoaderOptions = null; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Return the name of the method that is currently configured for cell cacheing. |
81
|
|
|
* |
82
|
|
|
* @return string Name of the cacheing method |
83
|
|
|
*/ |
84
|
|
|
public static function getCacheStorageMethod() |
85
|
|
|
{ |
86
|
|
|
return CachedObjectStorageFactory::getCacheStorageMethod(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Return the name of the class that is currently being used for cell cacheing. |
91
|
|
|
* |
92
|
|
|
* @return string Name of the class currently being used for cacheing |
93
|
|
|
*/ |
94
|
|
|
public static function getCacheStorageClass() |
95
|
|
|
{ |
96
|
|
|
return CachedObjectStorageFactory::getCacheStorageClass(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set the method that should be used for cell caching. |
101
|
|
|
* |
102
|
|
|
* @param string $method Name of the caching method |
103
|
|
|
* @param array $arguments Optional configuration arguments for the caching method |
104
|
|
|
* |
105
|
|
|
* @return bool Success or failure |
106
|
|
|
*/ |
107
|
|
|
public static function setCacheStorageMethod($method = CachedObjectStorageFactory::CACHE_IN_MEMORY, $arguments = []) |
108
|
|
|
{ |
109
|
|
|
return CachedObjectStorageFactory::initialize($method, $arguments); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Set the locale code to use for formula translations and any special formatting. |
114
|
|
|
* |
115
|
|
|
* @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk") |
116
|
|
|
* |
117
|
|
|
* @return bool Success or failure |
118
|
|
|
*/ |
119
|
|
|
public static function setLocale($locale = 'en_us') |
120
|
|
|
{ |
121
|
|
|
return Calculation::getInstance()->setLocale($locale); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set details of the external library that PhpSpreadsheet should use for rendering charts. |
126
|
|
|
* |
127
|
|
|
* @param string $libraryName Internal reference name of the library |
128
|
|
|
* e.g. \PhpOffice\PhpSpreadsheet\Settings::CHART_RENDERER_JPGRAPH |
129
|
|
|
* @param string $libraryBaseDir Directory path to the library's base folder |
130
|
|
|
* |
131
|
|
|
* @return bool Success or failure |
132
|
|
|
*/ |
133
|
3 |
|
public static function setChartRenderer($libraryName, $libraryBaseDir) |
134
|
|
|
{ |
135
|
3 |
|
if (!self::setChartRendererName($libraryName)) { |
136
|
|
|
return false; |
137
|
|
|
} |
138
|
|
|
|
139
|
3 |
|
return self::setChartRendererPath($libraryBaseDir); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Identify to PhpSpreadsheet the external library to use for rendering charts. |
144
|
|
|
* |
145
|
|
|
* @param string $libraryName Internal reference name of the library |
146
|
|
|
* e.g. \PhpOffice\PhpSpreadsheet\Settings::CHART_RENDERER_JPGRAPH |
147
|
|
|
* |
148
|
|
|
* @return bool Success or failure |
149
|
|
|
*/ |
150
|
3 |
|
public static function setChartRendererName($libraryName) |
151
|
|
|
{ |
152
|
3 |
|
if (!in_array($libraryName, self::$chartRenderers)) { |
153
|
|
|
return false; |
154
|
|
|
} |
155
|
3 |
|
self::$chartRendererName = $libraryName; |
156
|
|
|
|
157
|
3 |
|
return true; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Tell PhpSpreadsheet where to find the external library to use for rendering charts. |
162
|
|
|
* |
163
|
|
|
* @param string $libraryBaseDir Directory path to the library's base folder |
164
|
|
|
* |
165
|
|
|
* @return bool Success or failure |
166
|
|
|
*/ |
167
|
3 |
|
public static function setChartRendererPath($libraryBaseDir) |
168
|
|
|
{ |
169
|
3 |
|
if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) { |
170
|
3 |
|
return false; |
171
|
|
|
} |
172
|
|
|
self::$chartRendererPath = $libraryBaseDir; |
173
|
|
|
|
174
|
|
|
return true; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Return the Chart Rendering Library that PhpSpreadsheet is currently configured to use (e.g. jpgraph). |
179
|
|
|
* |
180
|
|
|
* @return string|null Internal reference name of the Chart Rendering Library that PhpSpreadsheet is |
181
|
|
|
* currently configured to use |
182
|
|
|
* e.g. \PhpOffice\PhpSpreadsheet\Settings::CHART_RENDERER_JPGRAPH |
183
|
|
|
*/ |
184
|
|
|
public static function getChartRendererName() |
185
|
|
|
{ |
186
|
|
|
return self::$chartRendererName; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Return the directory path to the Chart Rendering Library that PhpSpreadsheet is currently configured to use. |
191
|
|
|
* |
192
|
|
|
* @return string|null Directory Path to the Chart Rendering Library that PhpSpreadsheet is |
193
|
|
|
* currently configured to use |
194
|
|
|
*/ |
195
|
|
|
public static function getChartRendererPath() |
196
|
|
|
{ |
197
|
|
|
return self::$chartRendererPath; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Identify to PhpSpreadsheet the external library to use for rendering PDF files. |
202
|
|
|
* |
203
|
|
|
* @param string $libraryName Internal reference name of the library |
204
|
|
|
* e.g. \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF, |
205
|
|
|
* \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF |
206
|
|
|
* or \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF |
207
|
|
|
*/ |
208
|
5 |
|
public static function setPdfRendererName($libraryName) |
209
|
|
|
{ |
210
|
5 |
|
if (!in_array($libraryName, self::$pdfRenderers)) { |
211
|
|
|
throw new Exception('"' . $libraryName . '" is not a valid PDF library name'); |
212
|
|
|
} |
213
|
5 |
|
self::$pdfRendererName = $libraryName; |
214
|
5 |
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Return the PDF Rendering Library that PhpSpreadsheet is currently configured to use (e.g. dompdf). |
218
|
|
|
* |
219
|
|
|
* @return string|null Internal reference name of the PDF Rendering Library that PhpSpreadsheet is |
220
|
|
|
* currently configured to use |
221
|
|
|
* e.g. \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF, |
222
|
|
|
* \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF |
223
|
|
|
* or \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF |
224
|
|
|
*/ |
225
|
4 |
|
public static function getPdfRendererName() |
226
|
|
|
{ |
227
|
4 |
|
return self::$pdfRendererName; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Set default options for libxml loader. |
232
|
|
|
* |
233
|
|
|
* @param int $options Default options for libxml loader |
234
|
|
|
*/ |
235
|
14 |
|
public static function setLibXmlLoaderOptions($options = null) |
236
|
|
|
{ |
237
|
14 |
|
if (is_null($options) && defined('LIBXML_DTDLOAD')) { |
238
|
|
|
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR; |
239
|
|
|
} |
240
|
14 |
|
@libxml_disable_entity_loader((bool) $options); |
|
|
|
|
241
|
14 |
|
self::$libXmlLoaderOptions = $options; |
242
|
14 |
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Get default options for libxml loader. |
246
|
|
|
* Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly. |
247
|
|
|
* |
248
|
|
|
* @return int Default options for libxml loader |
249
|
|
|
*/ |
250
|
22 |
|
public static function getLibXmlLoaderOptions() |
251
|
|
|
{ |
252
|
22 |
|
if (is_null(self::$libXmlLoaderOptions) && defined('LIBXML_DTDLOAD')) { |
253
|
13 |
|
self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR); |
254
|
19 |
|
} elseif (is_null(self::$libXmlLoaderOptions)) { |
255
|
|
|
self::$libXmlLoaderOptions = true; |
|
|
|
|
256
|
|
|
} |
257
|
22 |
|
@libxml_disable_entity_loader((bool) self::$libXmlLoaderOptions); |
|
|
|
|
258
|
|
|
|
259
|
22 |
|
return self::$libXmlLoaderOptions; |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: