Settings.Class.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: phperstar
  5. * Date: 2020/8/11
  6. * Time: 10:40 AM
  7. */
  8. namespace Util\PHPExcel;
  9. class Settings
  10. {
  11. /** Available Zip library classes */
  12. const PCLZIP = 'PHPExcel_Shared_ZipArchive';
  13. const ZIPARCHIVE = 'ZipArchive';
  14. /**
  15. * Name of the class used for Zip file management
  16. * e.g.
  17. * ZipArchive
  18. *
  19. * @var string
  20. */
  21. private static $zipClass = self::ZIPARCHIVE;
  22. /**
  23. * Default options for libxml loader
  24. *
  25. * @var int
  26. */
  27. private static $libXmlLoaderOptions = null;
  28. /**
  29. * Set the Zip handler Class that PHPExcel should use for Zip file management (PCLZip or ZipArchive)
  30. *
  31. * @param string $zipClass The Zip handler class that PHPExcel should use for Zip file management
  32. * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
  33. * @return boolean Success or failure
  34. */
  35. public static function setZipClass($zipClass)
  36. {
  37. if (($zipClass === self::PCLZIP) ||
  38. ($zipClass === self::ZIPARCHIVE)) {
  39. self::$zipClass = $zipClass;
  40. return true;
  41. }
  42. return false;
  43. }
  44. /**
  45. * Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive)
  46. * or Zip file management
  47. *
  48. * @return string Name of the Zip handler Class that PHPExcel is configured to use
  49. * for Zip file management
  50. * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
  51. */
  52. public static function getZipClass()
  53. {
  54. return self::$zipClass;
  55. }
  56. /**
  57. * Get defined options for libxml loader.
  58. * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
  59. *
  60. * @return int Default options for libxml loader
  61. */
  62. public static function getLibXmlLoaderOptions()
  63. {
  64. if (is_null(self::$libXmlLoaderOptions) && defined('LIBXML_DTDLOAD')) {
  65. self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
  66. } elseif (is_null(self::$libXmlLoaderOptions)) {
  67. self::$libXmlLoaderOptions = true;
  68. }
  69. if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
  70. @libxml_disable_entity_loader((bool) self::$libXmlLoaderOptions);
  71. }
  72. return self::$libXmlLoaderOptions;
  73. }
  74. /**
  75. * Set options for libxml loader
  76. *
  77. * @param int $options Options for libxml loader
  78. */
  79. public static function setLibXmlLoaderOptions($options = null)
  80. {
  81. if (is_null($options) && defined('LIBXML_DTDLOAD')) {
  82. $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
  83. }
  84. if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
  85. @libxml_disable_entity_loader((bool) $options);
  86. }
  87. self::$libXmlLoaderOptions = $options;
  88. }
  89. }