-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.php
More file actions
154 lines (133 loc) · 3.65 KB
/
Copy pathDebug.php
File metadata and controls
154 lines (133 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php namespace mjolnir\base;
/**
* Whenever possible you should perform a standard debug, see http://xdebug.org/
*
* This class is meant for use in all the situations where you can't. Please use
* the methods here instead of doing things like a `\var_dump` on a live site.
*
* @package mjolnir
* @category Base
* @author Ibidem Team
* @copyright (c) 2013, Ibidem Team
* @license https://github.com/ibidem/ibidem/blob/master/LICENSE.md
*/
class Debug
{
/**
* @return int
*/
static function breadcrum()
{
static $breadcrum = 1;
return $breadcrum++;
}
/**
* Prints out system calls.
*/
static function filetrace()
{
if (\app\CFS::config('mjolnir/base')['development'])
{
$trace_array = [];
$clean_syspath = \str_replace('\\', '/', \app\Env::key('sys.path'));
if (\app\Env::key('www.path') !== null)
{
$clean_wwwpath = \str_replace('\\', '/', \app\Env::key('www.path'));
}
foreach (\debug_backtrace(false) as $trace)
{
$file_path = \str_replace('\\', '/', $trace['file']);
$file_path = \str_replace($clean_syspath, 'sys.path:/', $file_path);
if (\app\Env::key('www.path') !== null)
{
$file_path = \str_replace($clean_wwwpath, 'www.path:/', $file_path);
}
$trace_array[] = $file_path.'['.$trace['line'].'] -> '.(isset($trace['class']) ? $trace['class'].'::' : '').$trace['function'];
}
$trace = \implode("\n", $trace_array);
if (\app\Env::key('www.path') !== null)
{
$clean_wwwpath = \str_replace('\\', '/', \app\Env::key('www.path'));
$trace = \str_replace($clean_wwwpath, 'www.path:/', $trace);
}
return $trace;
}
return null;
}
/**
* Shorthand for performing dump in a path relative to the temporary file
* directory of the project.
*/
static function temp($filename, $variable, $append = false)
{
static::dump(\app\Env::key('tmp.path').$filename, $variable, $append);
}
/**
* Dumps a print_r to a file. You may wish to place the file in location you
* can view online.
*
* eg.
*
* \app\Debug::dump('/www/debug.html', $variable);
*
* If the file contains no slash or backslash the etc.path/tmp will be used.
*/
static function dump($file, $variable, $append = false)
{
if (\is_string($variable))
{
$output = $variable;
}
else # non-string
{
\ob_start();
\var_dump($variable);
$output = \ob_get_clean();
}
if ( ! \preg_match('#[\\/]#', $file))
{
$file = \app\Env::key('tmp.path').$file;
}
if ($append)
{
\file_put_contents($file, "\n\n$output", FILE_APPEND);
}
else # replace contents
{
\file_put_contents($file, $output);
}
}
/**
* Attempts to dump the variable to the screen; will erase all other
* content. Essentially this is similar to var_dump(...); die; but has the
* benefit of being immune to issues such as output going into script tags
* or output going into attributes, etc.
*/
static function livedump($variable)
{
$carrier = new \app\Exception_LiveDump('Stack does not support Debug::livedump');
throw $carrier->variable_is($variable);
}
/**
* Ouputs the debug message to the logs, a request identifier will be
* prepended if possible to help distinguish between different instances of
* the message that can occur when the piece of code is executed by various
* dependencies to the page (javascript, css, etc).
*/
static function log($message)
{
static $id = null;
if ($id === null)
{
$id = \base_convert(\crc32(\uniqid()), 10, 32);
}
\mjolnir\log('Debug', "$id: $message");
}
/**
* @return string usable timestamp for debug files
*/
static function timestamp()
{
return \preg_replace('#[^0-9]#', '', \microtime(true));
}
} # class