[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2022 The s9e authors 6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 7 */ 8 namespace s9e\TextFormatter\Parser; 9 10 use InvalidArgumentException; 11 use s9e\TextFormatter\Parser; 12 13 class Logger 14 { 15 /** 16 * @var string Name of the attribute being processed 17 */ 18 protected $attrName; 19 20 /** 21 * @var array Log entries in the form [[<type>,<msg>,<context>]] 22 */ 23 protected $logs = []; 24 25 /** 26 * @var Tag Tag being processed 27 */ 28 protected $tag; 29 30 /** 31 * Add a log entry 32 * 33 * @param string $type 34 * @param string $msg 35 * @param array $context 36 * @return void 37 */ 38 protected function add($type, $msg, array $context) 39 { 40 if (!isset($context['attrName']) && isset($this->attrName)) 41 { 42 $context['attrName'] = $this->attrName; 43 } 44 45 if (!isset($context['tag']) && isset($this->tag)) 46 { 47 $context['tag'] = $this->tag; 48 } 49 50 $this->logs[] = [$type, $msg, $context]; 51 } 52 53 /** 54 * Clear the log 55 * 56 * @return void 57 */ 58 public function clear() 59 { 60 $this->logs = []; 61 $this->unsetAttribute(); 62 $this->unsetTag(); 63 } 64 65 /** 66 * Return the logs 67 * 68 * @return array 69 */ 70 public function getLogs() 71 { 72 return $this->logs; 73 } 74 75 /** 76 * Record the name of the attribute being processed 77 * 78 * @param string $attrName 79 * @return void 80 */ 81 public function setAttribute($attrName) 82 { 83 $this->attrName = $attrName; 84 } 85 86 /** 87 * Record the tag being processed 88 * 89 * @param Tag $tag 90 * @return void 91 */ 92 public function setTag(Tag $tag) 93 { 94 $this->tag = $tag; 95 } 96 97 /** 98 * Unset the name of the attribute being processed 99 * 100 * @return void 101 */ 102 public function unsetAttribute() 103 { 104 unset($this->attrName); 105 } 106 107 /** 108 * Unset the tag being processed 109 * 110 * @return void 111 */ 112 public function unsetTag() 113 { 114 unset($this->tag); 115 } 116 117 //========================================================================== 118 // Log levels 119 //========================================================================== 120 121 /** 122 * Add a "debug" type log entry 123 * 124 * @param string $msg Log message 125 * @param array $context 126 * @return void 127 */ 128 public function debug($msg, array $context = []) 129 { 130 $this->add('debug', $msg, $context); 131 } 132 133 /** 134 * Add an "err" type log entry 135 * 136 * @param string $msg Log message 137 * @param array $context 138 * @return void 139 */ 140 public function err($msg, array $context = []) 141 { 142 $this->add('err', $msg, $context); 143 } 144 145 /** 146 * Add an "info" type log entry 147 * 148 * @param string $msg Log message 149 * @param array $context 150 * @return void 151 */ 152 public function info($msg, array $context = []) 153 { 154 $this->add('info', $msg, $context); 155 } 156 157 /** 158 * Add a "warn" type log entry 159 * 160 * @param string $msg Log message 161 * @param array $context 162 * @return void 163 */ 164 public function warn($msg, array $context = []) 165 { 166 $this->add('warn', $msg, $context); 167 } 168 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |