For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
4.1 KiB

  1. <?php
  2. /**
  3. * PHPExcel_CalcEngine_Logger
  4. *
  5. * Copyright (c) 2006 - 2015 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_Calculation
  23. * @copyright Copyright (c) 2006 - 2015 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. class PHPExcel_CalcEngine_Logger
  28. {
  29. /**
  30. * Flag to determine whether a debug log should be generated by the calculation engine
  31. * If true, then a debug log will be generated
  32. * If false, then a debug log will not be generated
  33. *
  34. * @var boolean
  35. */
  36. private $writeDebugLog = false;
  37. /**
  38. * Flag to determine whether a debug log should be echoed by the calculation engine
  39. * If true, then a debug log will be echoed
  40. * If false, then a debug log will not be echoed
  41. * A debug log can only be echoed if it is generated
  42. *
  43. * @var boolean
  44. */
  45. private $echoDebugLog = false;
  46. /**
  47. * The debug log generated by the calculation engine
  48. *
  49. * @var string[]
  50. */
  51. private $debugLog = array();
  52. /**
  53. * The calculation engine cell reference stack
  54. *
  55. * @var PHPExcel_CalcEngine_CyclicReferenceStack
  56. */
  57. private $cellStack;
  58. /**
  59. * Instantiate a Calculation engine logger
  60. *
  61. * @param PHPExcel_CalcEngine_CyclicReferenceStack $stack
  62. */
  63. public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack)
  64. {
  65. $this->cellStack = $stack;
  66. }
  67. /**
  68. * Enable/Disable Calculation engine logging
  69. *
  70. * @param boolean $pValue
  71. */
  72. public function setWriteDebugLog($pValue = false)
  73. {
  74. $this->writeDebugLog = $pValue;
  75. }
  76. /**
  77. * Return whether calculation engine logging is enabled or disabled
  78. *
  79. * @return boolean
  80. */
  81. public function getWriteDebugLog()
  82. {
  83. return $this->writeDebugLog;
  84. }
  85. /**
  86. * Enable/Disable echoing of debug log information
  87. *
  88. * @param boolean $pValue
  89. */
  90. public function setEchoDebugLog($pValue = false)
  91. {
  92. $this->echoDebugLog = $pValue;
  93. }
  94. /**
  95. * Return whether echoing of debug log information is enabled or disabled
  96. *
  97. * @return boolean
  98. */
  99. public function getEchoDebugLog()
  100. {
  101. return $this->echoDebugLog;
  102. }
  103. /**
  104. * Write an entry to the calculation engine debug log
  105. */
  106. public function writeDebugLog()
  107. {
  108. // Only write the debug log if logging is enabled
  109. if ($this->writeDebugLog) {
  110. $message = implode(func_get_args());
  111. $cellReference = implode(' -> ', $this->cellStack->showStack());
  112. if ($this->echoDebugLog) {
  113. echo $cellReference,
  114. ($this->cellStack->count() > 0 ? ' => ' : ''),
  115. $message,
  116. PHP_EOL;
  117. }
  118. $this->debugLog[] = $cellReference .
  119. ($this->cellStack->count() > 0 ? ' => ' : '') .
  120. $message;
  121. }
  122. }
  123. /**
  124. * Clear the calculation engine debug log
  125. */
  126. public function clearLog()
  127. {
  128. $this->debugLog = array();
  129. }
  130. /**
  131. * Return the calculation engine debug log
  132. *
  133. * @return string[]
  134. */
  135. public function getLog()
  136. {
  137. return $this->debugLog;
  138. }
  139. }