Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Calculation\Engine; 4 5 class Logger 6 { 7 /** 8 * Flag to determine whether a debug log should be generated by the calculation engine 9 * If true, then a debug log will be generated 10 * If false, then a debug log will not be generated. 11 * 12 * @var bool 13 */ 14 private $writeDebugLog = false; 15 16 /** 17 * Flag to determine whether a debug log should be echoed by the calculation engine 18 * If true, then a debug log will be echoed 19 * If false, then a debug log will not be echoed 20 * A debug log can only be echoed if it is generated. 21 * 22 * @var bool 23 */ 24 private $echoDebugLog = false; 25 26 /** 27 * The debug log generated by the calculation engine. 28 * 29 * @var string[] 30 */ 31 private $debugLog = []; 32 33 /** 34 * The calculation engine cell reference stack. 35 * 36 * @var CyclicReferenceStack 37 */ 38 private $cellStack; 39 40 /** 41 * Instantiate a Calculation engine logger. 42 */ 43 public function __construct(CyclicReferenceStack $stack) 44 { 45 $this->cellStack = $stack; 46 } 47 48 /** 49 * Enable/Disable Calculation engine logging. 50 * 51 * @param bool $pValue 52 */ 53 public function setWriteDebugLog($pValue): void 54 { 55 $this->writeDebugLog = $pValue; 56 } 57 58 /** 59 * Return whether calculation engine logging is enabled or disabled. 60 * 61 * @return bool 62 */ 63 public function getWriteDebugLog() 64 { 65 return $this->writeDebugLog; 66 } 67 68 /** 69 * Enable/Disable echoing of debug log information. 70 * 71 * @param bool $pValue 72 */ 73 public function setEchoDebugLog($pValue): void 74 { 75 $this->echoDebugLog = $pValue; 76 } 77 78 /** 79 * Return whether echoing of debug log information is enabled or disabled. 80 * 81 * @return bool 82 */ 83 public function getEchoDebugLog() 84 { 85 return $this->echoDebugLog; 86 } 87 88 /** 89 * Write an entry to the calculation engine debug log. 90 */ 91 public function writeDebugLog(...$args): void 92 { 93 // Only write the debug log if logging is enabled 94 if ($this->writeDebugLog) { 95 $message = implode('', $args); 96 $cellReference = implode(' -> ', $this->cellStack->showStack()); 97 if ($this->echoDebugLog) { 98 echo $cellReference, 99 ($this->cellStack->count() > 0 ? ' => ' : ''), 100 $message, 101 PHP_EOL; 102 } 103 $this->debugLog[] = $cellReference . 104 ($this->cellStack->count() > 0 ? ' => ' : '') . 105 $message; 106 } 107 } 108 109 /** 110 * Write a series of entries to the calculation engine debug log. 111 * 112 * @param string[] $args 113 */ 114 public function mergeDebugLog(array $args): void 115 { 116 if ($this->writeDebugLog) { 117 foreach ($args as $entry) { 118 $this->writeDebugLog($entry); 119 } 120 } 121 } 122 123 /** 124 * Clear the calculation engine debug log. 125 */ 126 public function clearLog(): void 127 { 128 $this->debugLog = []; 129 } 130 131 /** 132 * Return the calculation engine debug log. 133 * 134 * @return string[] 135 */ 136 public function getLog() 137 { 138 return $this->debugLog; 139 } 140 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body