Logger.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.8.0, 2014-03-02
  26. */
  27. /**
  28. * PHPExcel_CalcEngine_Logger
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Calculation
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_CalcEngine_Logger {
  35. /**
  36. * Flag to determine whether a debug log should be generated by the calculation engine
  37. * If true, then a debug log will be generated
  38. * If false, then a debug log will not be generated
  39. *
  40. * @var boolean
  41. */
  42. private $_writeDebugLog = FALSE;
  43. /**
  44. * Flag to determine whether a debug log should be echoed by the calculation engine
  45. * If true, then a debug log will be echoed
  46. * If false, then a debug log will not be echoed
  47. * A debug log can only be echoed if it is generated
  48. *
  49. * @var boolean
  50. */
  51. private $_echoDebugLog = FALSE;
  52. /**
  53. * The debug log generated by the calculation engine
  54. *
  55. * @var string[]
  56. */
  57. private $_debugLog = array();
  58. /**
  59. * The calculation engine cell reference stack
  60. *
  61. * @var PHPExcel_CalcEngine_CyclicReferenceStack
  62. */
  63. private $_cellStack;
  64. /**
  65. * Instantiate a Calculation engine logger
  66. *
  67. * @param PHPExcel_CalcEngine_CyclicReferenceStack $stack
  68. */
  69. public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack) {
  70. $this->_cellStack = $stack;
  71. }
  72. /**
  73. * Enable/Disable Calculation engine logging
  74. *
  75. * @param boolean $pValue
  76. */
  77. public function setWriteDebugLog($pValue = FALSE) {
  78. $this->_writeDebugLog = $pValue;
  79. }
  80. /**
  81. * Return whether calculation engine logging is enabled or disabled
  82. *
  83. * @return boolean
  84. */
  85. public function getWriteDebugLog() {
  86. return $this->_writeDebugLog;
  87. }
  88. /**
  89. * Enable/Disable echoing of debug log information
  90. *
  91. * @param boolean $pValue
  92. */
  93. public function setEchoDebugLog($pValue = FALSE) {
  94. $this->_echoDebugLog = $pValue;
  95. }
  96. /**
  97. * Return whether echoing of debug log information is enabled or disabled
  98. *
  99. * @return boolean
  100. */
  101. public function getEchoDebugLog() {
  102. return $this->_echoDebugLog;
  103. }
  104. /**
  105. * Write an entry to the calculation engine debug log
  106. */
  107. public function writeDebugLog() {
  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. } // function _writeDebug()
  123. /**
  124. * Clear the calculation engine debug log
  125. */
  126. public function clearLog() {
  127. $this->_debugLog = array();
  128. } // function flushLogger()
  129. /**
  130. * Return the calculation engine debug log
  131. *
  132. * @return string[]
  133. */
  134. public function getLog() {
  135. return $this->_debugLog;
  136. } // function flushLogger()
  137. } // class PHPExcel_CalcEngine_Logger