Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
debug.php
1<?php
2
3namespace Bitrix\Main\Diag;
4
5class Debug
6{
7 protected static $timeLabels = [];
8
9 public static function startTimeLabel($name)
10 {
11 if (!isset(static::$timeLabels[$name]))
12 {
13 static::$timeLabels[$name] = [];
14 }
15 static::$timeLabels[$name]['start'] = microtime(true);
16 }
17
18 public static function endTimeLabel($name)
19 {
20 if (!isset(static::$timeLabels[$name]))
21 {
22 static::$timeLabels[$name] = [];
23 }
24 static::$timeLabels[$name]['time'] += microtime(true) - static::$timeLabels[$name]['start'];
25 }
26
27 public static function getTimeLabels()
28 {
29 return static::$timeLabels;
30 }
31
32 public static function dump($var, $varName = "", $return = false)
33 {
34 if ($return)
35 {
36 ob_start();
37 }
38
39 $flComplex = (is_array($var) || is_object($var));
40
41 if ($varName != "")
42 {
43 echo $varName;
44
45 if ($flComplex)
46 {
47 echo ":" . ($return ? "\n" : "<br />");
48 }
49 else
50 {
51 echo "=";
52 }
53 }
54
55 if ($flComplex && !$return)
56 {
57 echo "<pre>";
58 }
59
60 var_dump($var);
61
62 if ($flComplex && !$return)
63 {
64 echo "</pre>";
65 }
66 echo ($return ? "\n" : "<br />");
67
68 if ($return)
69 {
70 return ob_get_clean();
71 }
72
73 return null;
74 }
75
76 public static function dumpToFile($var, $varName = "", $fileName = "")
77 {
78 if (empty($fileName))
79 {
80 $fileName = "__bx_log.log";
81 }
82
83 $data = self::dump($var, $varName, true);
84
85 file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/" . $fileName, $data . "\n", FILE_APPEND);
86 }
87
88 public static function writeToFile($var, $varName = "", $fileName = "")
89 {
90 if (empty($fileName))
91 {
92 $fileName = "__bx_log.log";
93 }
94
95 $data = "";
96 if ($varName != "")
97 {
98 $data .= $varName . ":\n";
99 }
100
101 if (is_array($var))
102 {
103 $data .= print_r($var, true) . "\n";
104 }
105 else
106 {
107 $data .= $var . "\n";
108 }
109
110 file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/" . $fileName, $data . "\n", FILE_APPEND);
111 }
112}
static dump($var, $varName="", $return=false)
Definition debug.php:32
static startTimeLabel($name)
Definition debug.php:9
static getTimeLabels()
Definition debug.php:27
static writeToFile($var, $varName="", $fileName="")
Definition debug.php:88
static dumpToFile($var, $varName="", $fileName="")
Definition debug.php:76
static endTimeLabel($name)
Definition debug.php:18