Settings.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet;
  3. require_once DOL_DOCUMENT_ROOT . '/includes/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Collection/Memory.php';
  4. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  5. use PhpOffice\PhpSpreadsheet\Chart\Renderer\IRenderer;
  6. use PhpOffice\PhpSpreadsheet\Collection\Memory;
  7. use Psr\SimpleCache\CacheInterface;
  8. class Settings
  9. {
  10. /**
  11. * Class name of the chart renderer used for rendering charts
  12. * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph.
  13. *
  14. * @var string
  15. */
  16. private static $chartRenderer;
  17. /**
  18. * Default options for libxml loader.
  19. *
  20. * @var int
  21. */
  22. private static $libXmlLoaderOptions = null;
  23. /**
  24. * Allow/disallow libxml_disable_entity_loader() call when not thread safe.
  25. * Default behaviour is to do the check, but if you're running PHP versions
  26. * 7.2 < 7.2.1
  27. * 7.1 < 7.1.13
  28. * 7.0 < 7.0.27
  29. * 5.6 ANY
  30. * then you may need to disable this check to prevent unwanted behaviour in other threads
  31. * SECURITY WARNING: Changing this flag is not recommended.
  32. *
  33. * @var bool
  34. */
  35. private static $libXmlDisableEntityLoader = true;
  36. /**
  37. * The cache implementation to be used for cell collection.
  38. *
  39. * @var CacheInterface
  40. */
  41. private static $cache;
  42. /**
  43. * Set the locale code to use for formula translations and any special formatting.
  44. *
  45. * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk")
  46. *
  47. * @return bool Success or failure
  48. */
  49. public static function setLocale($locale)
  50. {
  51. return Calculation::getInstance()->setLocale($locale);
  52. }
  53. /**
  54. * Identify to PhpSpreadsheet the external library to use for rendering charts.
  55. *
  56. * @param string $rendererClass Class name of the chart renderer
  57. * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph
  58. *
  59. * @throws Exception
  60. */
  61. public static function setChartRenderer($rendererClass)
  62. {
  63. if (!is_a($rendererClass, IRenderer::class, true)) {
  64. throw new Exception('Chart renderer must implement ' . IRenderer::class);
  65. }
  66. self::$chartRenderer = $rendererClass;
  67. }
  68. /**
  69. * Return the Chart Rendering Library that PhpSpreadsheet is currently configured to use.
  70. *
  71. * @return null|string Class name of the chart renderer
  72. * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph
  73. */
  74. public static function getChartRenderer()
  75. {
  76. return self::$chartRenderer;
  77. }
  78. /**
  79. * Set default options for libxml loader.
  80. *
  81. * @param int $options Default options for libxml loader
  82. */
  83. public static function setLibXmlLoaderOptions($options)
  84. {
  85. if ($options === null && defined('LIBXML_DTDLOAD')) {
  86. $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
  87. }
  88. self::$libXmlLoaderOptions = $options;
  89. }
  90. /**
  91. * Get default options for libxml loader.
  92. * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
  93. *
  94. * @return int Default options for libxml loader
  95. */
  96. public static function getLibXmlLoaderOptions()
  97. {
  98. if (self::$libXmlLoaderOptions === null && defined('LIBXML_DTDLOAD')) {
  99. self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
  100. } elseif (self::$libXmlLoaderOptions === null) {
  101. self::$libXmlLoaderOptions = true;
  102. }
  103. return self::$libXmlLoaderOptions;
  104. }
  105. /**
  106. * Enable/Disable the entity loader for libxml loader.
  107. * Allow/disallow libxml_disable_entity_loader() call when not thread safe.
  108. * Default behaviour is to do the check, but if you're running PHP versions
  109. * 7.2 < 7.2.1
  110. * 7.1 < 7.1.13
  111. * 7.0 < 7.0.27
  112. * 5.6 ANY
  113. * then you may need to disable this check to prevent unwanted behaviour in other threads
  114. * SECURITY WARNING: Changing this flag to false is not recommended.
  115. *
  116. * @param bool $state
  117. */
  118. public static function setLibXmlDisableEntityLoader($state)
  119. {
  120. self::$libXmlDisableEntityLoader = (bool) $state;
  121. }
  122. /**
  123. * Return the state of the entity loader (disabled/enabled) for libxml loader.
  124. *
  125. * @return bool $state
  126. */
  127. public static function getLibXmlDisableEntityLoader()
  128. {
  129. return self::$libXmlDisableEntityLoader;
  130. }
  131. /**
  132. * Sets the implementation of cache that should be used for cell collection.
  133. *
  134. * @param CacheInterface $cache
  135. */
  136. public static function setCache(CacheInterface $cache)
  137. {
  138. self::$cache = $cache;
  139. }
  140. /**
  141. * Gets the implementation of cache that should be used for cell collection.
  142. *
  143. * @return CacheInterface
  144. */
  145. public static function getCache()
  146. {
  147. if (!self::$cache) {
  148. self::$cache = new Memory();
  149. }
  150. return self::$cache;
  151. }
  152. }