PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpoffice/phpexcel/Classes/PHPExcel/Settings.php

https://gitlab.com/techniconline/kmc
PHP | 392 lines | 141 code | 55 blank | 196 comment | 18 complexity | b2746d7b3bd935f6b898fadccc913cbc MD5 | raw file
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Settings
  23. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /** PHPExcel root directory */
  28. if (!defined('PHPEXCEL_ROOT')) {
  29. /**
  30. * @ignore
  31. */
  32. define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
  33. require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  34. }
  35. class PHPExcel_Settings
  36. {
  37. /** constants */
  38. /** Available Zip library classes */
  39. const PCLZIP = 'PHPExcel_Shared_ZipArchive';
  40. const ZIPARCHIVE = 'ZipArchive';
  41. /** Optional Chart Rendering libraries */
  42. const CHART_RENDERER_JPGRAPH = 'jpgraph';
  43. /** Optional PDF Rendering libraries */
  44. const PDF_RENDERER_TCPDF = 'tcPDF';
  45. const PDF_RENDERER_DOMPDF = 'DomPDF';
  46. const PDF_RENDERER_MPDF = 'mPDF';
  47. private static $_chartRenderers = array(
  48. self::CHART_RENDERER_JPGRAPH,
  49. );
  50. private static $_pdfRenderers = array(
  51. self::PDF_RENDERER_TCPDF,
  52. self::PDF_RENDERER_DOMPDF,
  53. self::PDF_RENDERER_MPDF,
  54. );
  55. /**
  56. * Name of the class used for Zip file management
  57. * e.g.
  58. * ZipArchive
  59. *
  60. * @var string
  61. */
  62. private static $_zipClass = self::ZIPARCHIVE;
  63. /**
  64. * Name of the external Library used for rendering charts
  65. * e.g.
  66. * jpgraph
  67. *
  68. * @var string
  69. */
  70. private static $_chartRendererName = NULL;
  71. /**
  72. * Directory Path to the external Library used for rendering charts
  73. *
  74. * @var string
  75. */
  76. private static $_chartRendererPath = NULL;
  77. /**
  78. * Name of the external Library used for rendering PDF files
  79. * e.g.
  80. * mPDF
  81. *
  82. * @var string
  83. */
  84. private static $_pdfRendererName = NULL;
  85. /**
  86. * Directory Path to the external Library used for rendering PDF files
  87. *
  88. * @var string
  89. */
  90. private static $_pdfRendererPath = NULL;
  91. /**
  92. * Default options for libxml loader
  93. *
  94. * @var int
  95. */
  96. private static $_libXmlLoaderOptions = null;
  97. /**
  98. * Set the Zip handler Class that PHPExcel should use for Zip file management (PCLZip or ZipArchive)
  99. *
  100. * @param string $zipClass The Zip handler class that PHPExcel should use for Zip file management
  101. * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
  102. * @return boolean Success or failure
  103. */
  104. public static function setZipClass($zipClass)
  105. {
  106. if (($zipClass === self::PCLZIP) ||
  107. ($zipClass === self::ZIPARCHIVE)
  108. ) {
  109. self::$_zipClass = $zipClass;
  110. return TRUE;
  111. }
  112. return FALSE;
  113. } // function setZipClass()
  114. /**
  115. * Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive)
  116. * or Zip file management
  117. *
  118. * @return string Name of the Zip handler Class that PHPExcel is configured to use
  119. * for Zip file management
  120. * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
  121. */
  122. public static function getZipClass()
  123. {
  124. return self::$_zipClass;
  125. } // function getZipClass()
  126. /**
  127. * Return the name of the method that is currently configured for cell cacheing
  128. *
  129. * @return string Name of the cacheing method
  130. */
  131. public static function getCacheStorageMethod()
  132. {
  133. return PHPExcel_CachedObjectStorageFactory::getCacheStorageMethod();
  134. } // function getCacheStorageMethod()
  135. /**
  136. * Return the name of the class that is currently being used for cell cacheing
  137. *
  138. * @return string Name of the class currently being used for cacheing
  139. */
  140. public static function getCacheStorageClass()
  141. {
  142. return PHPExcel_CachedObjectStorageFactory::getCacheStorageClass();
  143. } // function getCacheStorageClass()
  144. /**
  145. * Set the method that should be used for cell cacheing
  146. *
  147. * @param string $method Name of the cacheing method
  148. * @param array $arguments Optional configuration arguments for the cacheing method
  149. * @return boolean Success or failure
  150. */
  151. public static function setCacheStorageMethod(
  152. $method = PHPExcel_CachedObjectStorageFactory::cache_in_memory,
  153. $arguments = array()
  154. )
  155. {
  156. return PHPExcel_CachedObjectStorageFactory::initialize($method, $arguments);
  157. } // function setCacheStorageMethod()
  158. /**
  159. * Set the locale code to use for formula translations and any special formatting
  160. *
  161. * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk")
  162. * @return boolean Success or failure
  163. */
  164. public static function setLocale($locale = 'en_us')
  165. {
  166. return PHPExcel_Calculation::getInstance()->setLocale($locale);
  167. } // function setLocale()
  168. /**
  169. * Set details of the external library that PHPExcel should use for rendering charts
  170. *
  171. * @param string $libraryName Internal reference name of the library
  172. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  173. * @param string $libraryBaseDir Directory path to the library's base folder
  174. *
  175. * @return boolean Success or failure
  176. */
  177. public static function setChartRenderer($libraryName, $libraryBaseDir)
  178. {
  179. if (!self::setChartRendererName($libraryName))
  180. return FALSE;
  181. return self::setChartRendererPath($libraryBaseDir);
  182. } // function setChartRenderer()
  183. /**
  184. * Identify to PHPExcel the external library to use for rendering charts
  185. *
  186. * @param string $libraryName Internal reference name of the library
  187. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  188. *
  189. * @return boolean Success or failure
  190. */
  191. public static function setChartRendererName($libraryName)
  192. {
  193. if (!in_array($libraryName, self::$_chartRenderers)) {
  194. return FALSE;
  195. }
  196. self::$_chartRendererName = $libraryName;
  197. return TRUE;
  198. } // function setChartRendererName()
  199. /**
  200. * Tell PHPExcel where to find the external library to use for rendering charts
  201. *
  202. * @param string $libraryBaseDir Directory path to the library's base folder
  203. * @return boolean Success or failure
  204. */
  205. public static function setChartRendererPath($libraryBaseDir)
  206. {
  207. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  208. return FALSE;
  209. }
  210. self::$_chartRendererPath = $libraryBaseDir;
  211. return TRUE;
  212. } // function setChartRendererPath()
  213. /**
  214. * Return the Chart Rendering Library that PHPExcel is currently configured to use (e.g. jpgraph)
  215. *
  216. * @return string|NULL Internal reference name of the Chart Rendering Library that PHPExcel is
  217. * currently configured to use
  218. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  219. */
  220. public static function getChartRendererName()
  221. {
  222. return self::$_chartRendererName;
  223. } // function getChartRendererName()
  224. /**
  225. * Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use
  226. *
  227. * @return string|NULL Directory Path to the Chart Rendering Library that PHPExcel is
  228. * currently configured to use
  229. */
  230. public static function getChartRendererPath()
  231. {
  232. return self::$_chartRendererPath;
  233. } // function getChartRendererPath()
  234. /**
  235. * Set details of the external library that PHPExcel should use for rendering PDF files
  236. *
  237. * @param string $libraryName Internal reference name of the library
  238. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  239. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  240. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  241. * @param string $libraryBaseDir Directory path to the library's base folder
  242. *
  243. * @return boolean Success or failure
  244. */
  245. public static function setPdfRenderer($libraryName, $libraryBaseDir)
  246. {
  247. if (!self::setPdfRendererName($libraryName))
  248. return FALSE;
  249. return self::setPdfRendererPath($libraryBaseDir);
  250. } // function setPdfRenderer()
  251. /**
  252. * Identify to PHPExcel the external library to use for rendering PDF files
  253. *
  254. * @param string $libraryName Internal reference name of the library
  255. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  256. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  257. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  258. *
  259. * @return boolean Success or failure
  260. */
  261. public static function setPdfRendererName($libraryName)
  262. {
  263. if (!in_array($libraryName, self::$_pdfRenderers)) {
  264. return FALSE;
  265. }
  266. self::$_pdfRendererName = $libraryName;
  267. return TRUE;
  268. } // function setPdfRendererName()
  269. /**
  270. * Tell PHPExcel where to find the external library to use for rendering PDF files
  271. *
  272. * @param string $libraryBaseDir Directory path to the library's base folder
  273. * @return boolean Success or failure
  274. */
  275. public static function setPdfRendererPath($libraryBaseDir)
  276. {
  277. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  278. return FALSE;
  279. }
  280. self::$_pdfRendererPath = $libraryBaseDir;
  281. return TRUE;
  282. } // function setPdfRendererPath()
  283. /**
  284. * Return the PDF Rendering Library that PHPExcel is currently configured to use (e.g. dompdf)
  285. *
  286. * @return string|NULL Internal reference name of the PDF Rendering Library that PHPExcel is
  287. * currently configured to use
  288. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  289. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  290. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  291. */
  292. public static function getPdfRendererName()
  293. {
  294. return self::$_pdfRendererName;
  295. } // function getPdfRendererName()
  296. /**
  297. * Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use
  298. *
  299. * @return string|NULL Directory Path to the PDF Rendering Library that PHPExcel is
  300. * currently configured to use
  301. */
  302. public static function getPdfRendererPath()
  303. {
  304. return self::$_pdfRendererPath;
  305. } // function getPdfRendererPath()
  306. /**
  307. * Set default options for libxml loader
  308. *
  309. * @param int $options Default options for libxml loader
  310. */
  311. public static function setLibXmlLoaderOptions($options = null)
  312. {
  313. if (is_null($options) && defined(LIBXML_DTDLOAD)) {
  314. $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
  315. }
  316. if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
  317. @libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
  318. }
  319. self::$_libXmlLoaderOptions = $options;
  320. } // function setLibXmlLoaderOptions
  321. /**
  322. * Get default options for libxml loader.
  323. * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
  324. *
  325. * @return int Default options for libxml loader
  326. */
  327. public static function getLibXmlLoaderOptions()
  328. {
  329. if (is_null(self::$_libXmlLoaderOptions) && defined(LIBXML_DTDLOAD)) {
  330. self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
  331. }
  332. if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
  333. @libxml_disable_entity_loader(self::$_libXmlLoaderOptions == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
  334. }
  335. return self::$_libXmlLoaderOptions;
  336. } // function getLibXmlLoaderOptions
  337. }