Logger.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. class PHPExcel_CalcEngine_Logger
  8. {
  9. /**
  10. * Flag to determine whether a debug log should be generated by the calculation engine
  11. * If true, then a debug log will be generated
  12. * If false, then a debug log will not be generated
  13. *
  14. * @var boolean
  15. */
  16. private $writeDebugLog = false;
  17. /**
  18. * Flag to determine whether a debug log should be echoed by the calculation engine
  19. * If true, then a debug log will be echoed
  20. * If false, then a debug log will not be echoed
  21. * A debug log can only be echoed if it is generated
  22. *
  23. * @var boolean
  24. */
  25. private $echoDebugLog = false;
  26. /**
  27. * The debug log generated by the calculation engine
  28. *
  29. * @var string[]
  30. */
  31. private $debugLog = array();
  32. /**
  33. * The calculation engine cell reference stack
  34. *
  35. * @var PHPExcel_CalcEngine_CyclicReferenceStack
  36. */
  37. private $cellStack;
  38. /**
  39. * Instantiate a Calculation engine logger
  40. *
  41. * @param PHPExcel_CalcEngine_CyclicReferenceStack $stack
  42. */
  43. public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack)
  44. {
  45. $this->cellStack = $stack;
  46. }
  47. /**
  48. * Enable/Disable Calculation engine logging
  49. *
  50. * @param boolean $pValue
  51. */
  52. public function setWriteDebugLog($pValue = false)
  53. {
  54. $this->writeDebugLog = $pValue;
  55. }
  56. /**
  57. * Return whether calculation engine logging is enabled or disabled
  58. *
  59. * @return boolean
  60. */
  61. public function getWriteDebugLog()
  62. {
  63. return $this->writeDebugLog;
  64. }
  65. /**
  66. * Enable/Disable echoing of debug log information
  67. *
  68. * @param boolean $pValue
  69. */
  70. public function setEchoDebugLog($pValue = false)
  71. {
  72. $this->echoDebugLog = $pValue;
  73. }
  74. /**
  75. * Return whether echoing of debug log information is enabled or disabled
  76. *
  77. * @return boolean
  78. */
  79. public function getEchoDebugLog()
  80. {
  81. return $this->echoDebugLog;
  82. }
  83. /**
  84. * Write an entry to the calculation engine debug log
  85. */
  86. public function writeDebugLog()
  87. {
  88. // Only write the debug log if logging is enabled
  89. if ($this->writeDebugLog) {
  90. $message = implode(func_get_args());
  91. $cellReference = implode(' -> ', $this->cellStack->showStack());
  92. if ($this->echoDebugLog) {
  93. echo $cellReference,
  94. ($this->cellStack->count() > 0 ? ' => ' : ''),
  95. $message,
  96. PHP_EOL;
  97. }
  98. $this->debugLog[] = $cellReference .
  99. ($this->cellStack->count() > 0 ? ' => ' : '') .
  100. $message;
  101. }
  102. }
  103. /**
  104. * Clear the calculation engine debug log
  105. */
  106. public function clearLog()
  107. {
  108. $this->debugLog = array();
  109. }
  110. /**
  111. * Return the calculation engine debug log
  112. *
  113. * @return string[]
  114. */
  115. public function getLog()
  116. {
  117. return $this->debugLog;
  118. }
  119. }