[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * This file is part of the DebugBar package. 4 * 5 * (c) 2013 Maxime Bouroumeau-Fuseau 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 namespace DebugBar\DataCollector; 12 13 use DebugBar\DataFormatter\DataFormatter; 14 use DebugBar\DataFormatter\DataFormatterInterface; 15 use DebugBar\DataFormatter\DebugBarVarDumper; 16 17 /** 18 * Abstract class for data collectors 19 */ 20 abstract class DataCollector implements DataCollectorInterface 21 { 22 private static $defaultDataFormatter; 23 private static $defaultVarDumper; 24 25 protected $dataFormater; 26 protected $varDumper; 27 protected $xdebugLinkTemplate = ''; 28 protected $xdebugShouldUseAjax = false; 29 protected $xdebugReplacements = array(); 30 31 /** 32 * Sets the default data formater instance used by all collectors subclassing this class 33 * 34 * @param DataFormatterInterface $formater 35 */ 36 public static function setDefaultDataFormatter(DataFormatterInterface $formater) 37 { 38 self::$defaultDataFormatter = $formater; 39 } 40 41 /** 42 * Returns the default data formater 43 * 44 * @return DataFormatterInterface 45 */ 46 public static function getDefaultDataFormatter() 47 { 48 if (self::$defaultDataFormatter === null) { 49 self::$defaultDataFormatter = new DataFormatter(); 50 } 51 return self::$defaultDataFormatter; 52 } 53 54 /** 55 * Sets the data formater instance used by this collector 56 * 57 * @param DataFormatterInterface $formater 58 * @return $this 59 */ 60 public function setDataFormatter(DataFormatterInterface $formater) 61 { 62 $this->dataFormater = $formater; 63 return $this; 64 } 65 66 /** 67 * @return DataFormatterInterface 68 */ 69 public function getDataFormatter() 70 { 71 if ($this->dataFormater === null) { 72 $this->dataFormater = self::getDefaultDataFormatter(); 73 } 74 return $this->dataFormater; 75 } 76 77 /** 78 * Get an Xdebug Link to a file 79 * 80 * @param string $file 81 * @param int $line 82 * 83 * @return array { 84 * @var string $url 85 * @var bool $ajax should be used to open the url instead of a normal links 86 * } 87 */ 88 public function getXdebugLink($file, $line = 1) 89 { 90 if (count($this->xdebugReplacements)) { 91 $file = strtr($file, $this->xdebugReplacements); 92 } 93 94 $url = strtr($this->getXdebugLinkTemplate(), ['%f' => $file, '%l' => $line]); 95 if ($url) { 96 return ['url' => $url, 'ajax' => $this->getXdebugShouldUseAjax()]; 97 } 98 } 99 100 /** 101 * Sets the default variable dumper used by all collectors subclassing this class 102 * 103 * @param DebugBarVarDumper $varDumper 104 */ 105 public static function setDefaultVarDumper(DebugBarVarDumper $varDumper) 106 { 107 self::$defaultVarDumper = $varDumper; 108 } 109 110 /** 111 * Returns the default variable dumper 112 * 113 * @return DebugBarVarDumper 114 */ 115 public static function getDefaultVarDumper() 116 { 117 if (self::$defaultVarDumper === null) { 118 self::$defaultVarDumper = new DebugBarVarDumper(); 119 } 120 return self::$defaultVarDumper; 121 } 122 123 /** 124 * Sets the variable dumper instance used by this collector 125 * 126 * @param DebugBarVarDumper $varDumper 127 * @return $this 128 */ 129 public function setVarDumper(DebugBarVarDumper $varDumper) 130 { 131 $this->varDumper = $varDumper; 132 return $this; 133 } 134 135 /** 136 * Gets the variable dumper instance used by this collector; note that collectors using this 137 * instance need to be sure to return the static assets provided by the variable dumper. 138 * 139 * @return DebugBarVarDumper 140 */ 141 public function getVarDumper() 142 { 143 if ($this->varDumper === null) { 144 $this->varDumper = self::getDefaultVarDumper(); 145 } 146 return $this->varDumper; 147 } 148 149 /** 150 * @deprecated 151 */ 152 public function formatVar($var) 153 { 154 return $this->getDataFormatter()->formatVar($var); 155 } 156 157 /** 158 * @deprecated 159 */ 160 public function formatDuration($seconds) 161 { 162 return $this->getDataFormatter()->formatDuration($seconds); 163 } 164 165 /** 166 * @deprecated 167 */ 168 public function formatBytes($size, $precision = 2) 169 { 170 return $this->getDataFormatter()->formatBytes($size, $precision); 171 } 172 173 /** 174 * @return string 175 */ 176 public function getXdebugLinkTemplate() 177 { 178 if (empty($this->xdebugLinkTemplate) && !empty(ini_get('xdebug.file_link_format'))) { 179 $this->xdebugLinkTemplate = ini_get('xdebug.file_link_format'); 180 } 181 182 return $this->xdebugLinkTemplate; 183 } 184 185 /** 186 * @param string $xdebugLinkTemplate 187 * @param bool $shouldUseAjax 188 */ 189 public function setXdebugLinkTemplate($xdebugLinkTemplate, $shouldUseAjax = false) 190 { 191 if ($xdebugLinkTemplate === 'idea') { 192 $this->xdebugLinkTemplate = 'http://localhost:63342/api/file/?file=%f&line=%l'; 193 $this->xdebugShouldUseAjax = true; 194 } else { 195 $this->xdebugLinkTemplate = $xdebugLinkTemplate; 196 $this->xdebugShouldUseAjax = $shouldUseAjax; 197 } 198 } 199 200 /** 201 * @return bool 202 */ 203 public function getXdebugShouldUseAjax() 204 { 205 return $this->xdebugShouldUseAjax; 206 } 207 208 /** 209 * returns an array of filename-replacements 210 * 211 * this is useful f.e. when using vagrant or remote servers, 212 * where the path of the file is different between server and 213 * development environment 214 * 215 * @return array key-value-pairs of replacements, key = path on server, value = replacement 216 */ 217 public function getXdebugReplacements() 218 { 219 return $this->xdebugReplacements; 220 } 221 222 /** 223 * @param array $xdebugReplacements 224 */ 225 public function setXdebugReplacements($xdebugReplacements) 226 { 227 $this->xdebugReplacements = $xdebugReplacements; 228 } 229 230 public function setXdebugReplacement($serverPath, $replacement) 231 { 232 $this->xdebugReplacements[$serverPath] = $replacement; 233 } 234 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |