PageRenderTime 91ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/PHPExcel/Classes/PHPExcel/Settings.php

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