-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclass.jbdump.php
4870 lines (4131 loc) · 165 KB
/
class.jbdump.php
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Library for dump variables and profiling PHP code
* The idea and the look was taken from Krumo project
* PHP version 5.3 or higher
* *
* Example:<br/>
* jbdump($myLoveVariable);<br/>
* jbdump($myLoveVariable, false, 'Var name');<br/>
* jbdump::mark('Profiler mark');<br/>
* jbdump::log('Message to log file');<br/>
* jbdump::i()->dump($myLoveVariable);<br/>
* jbdump::i()->post()->get()->mark('Profiler mark');<br/>
* *
* Simple include in project on index.php file
* if (file_exists( dirname(__FILE__) . '/class.jbdump.php')) { require_once dirname(__FILE__) . '/class.jbdump.php'; }
* *
* @package JBDump
* @copyright Copyright (c) 2009-2015 JBDump.org
* @license http://www.gnu.org/licenses/gpl.html GNU/GPL
* @author SmetDenis <[email protected]>, <[email protected]>
* @link http://joomla-book.ru/projects/jbdump
* @link http://JBDump.org/
* @link http://code.google.com/intl/ru-RU/apis/chart/index.html
*/
/**
* Class JBDump
*/
class JBDump
{
/**
* Default configurations
* @var array
*/
protected static $_config = array
(
'root' => null, // project root directory
'showArgs' => 0, // show Args in backtrace
'showCall' => 1,
// // // file logger
'log' => array(
'path' => null, // absolute log path
'file' => 'jbdump', // log filename
'format' => "{DATETIME}\t{CLIENT_IP}\t\t{FILE}\t\t{NAME}\t\t{JBDUMP_MESSAGE}", // fields in log file
'serialize' => 'print_r', // (none|json|serialize|print_r|var_dump|format|php_array)
),
// // // profiler
'profiler' => array(
'auto' => 1, // Result call automatically on destructor
'render' => 20, // Profiler render (bit mask). See constants jbdump::PROFILER_RENDER_*
'showStart' => 0, // Set auto mark after jbdump init
'showEnd' => 0, // Set auto mark before jbdump destruction
'showOnAjax' => 0, // Show profiler information on ajax calls
'traceLimit' => 3, // Limit for function JBDump::incTrace();
),
// // // sorting (ASC)
'sort' => array(
'array' => 0, // by keys
'object' => 1, // by properties name
'methods' => 1, // by methods name
),
// // // personal dump
'personal' => array(
'ip' => array(), // IP address for which to work debugging
'requestParam' => 0, // $_REQUEST key for which to work debugging
'requestValue' => 0, // $_REQUEST value for which to work debugging
),
// // // error handlers
'errors' => array(
'reporting' => 0, // set error reporting level while construct
'errorHandler' => 0, // register own handler for PHP errors
'errorBacktrace' => 0, // show backtrace for errors
'exceptionHandler' => 0, // register own handler for all exeptions
'exceptionBacktrace' => 0, // show backtrace for exceptions
'context' => 0, // show context for errors
'logHidden' => 0, // if error message not show, log it
'logAll' => 0, // log all error in syslog
),
// // // mail send
'mail' => array(
'to' => '[email protected]', // mail to
'subject' => 'JBDump debug', // mail subject
'log' => 0, // log all mail messages
),
// // // dump config
'dump' => array(
'render' => 'html', // (lite|log|mail|print_r|var_dump|html)
'stringLength' => 80, // cutting long string
'maxDepth' => 4, // the maximum depth of the dump
'showMethods' => 1, // show object methods
'die' => 0, // die after dumping variable
'expandLevel' => 1, // expand the list to the specified depth
),
);
/**
* Flag enable or disable the debugger
* @var bool
*/
public static $enabled = true;
/**
* Counters of calling
* @var array
*/
protected static $_counters = array(
'mode_0' => array(),
'mode_1' => array(),
'trace' => array(),
);
/**
* Counteins of pairs calling
* @var array
*/
protected static $_profilerPairs = array();
/**
* Library version
* @var string
*/
const VERSION = '1.5.2';
/**
* Library version
* @var string
*/
const DATE_FORMAT = 'Y-m-d H:i:s';
/**
* Render type bit
*/
const PROFILER_RENDER_NONE = 0;
const PROFILER_RENDER_FILE = 1;
const PROFILER_RENDER_ECHO = 2;
const PROFILER_RENDER_TABLE = 4;
const PROFILER_RENDER_CHART = 8;
const PROFILER_RENDER_TOTAL = 16;
/**
* Directory separator
*/
const DS = '/';
/**
* Site url
* @var string
*/
protected $_site = 'https://github.com/JBZoo/JBDump';
/**
* Last backtrace
* @var array
*/
protected $_trace = array();
/**
* Absolute path current log file
* @var string|resource
*/
protected $_logfile = null;
/**
* Absolute path for all log files
* @var string
*/
protected $_logPath = null;
/**
* Current depth in current dumped object or array
* @var integer
*/
protected $_currentDepth = 0;
/**
* Profiler buffer info
* @var array
*/
protected $_bufferInfo = array();
/**
* Start microtime
* @var float
*/
protected $_start = 0.0;
/**
* Previous microtime for profiler
* @var float
*/
protected $_prevTime = 0.0;
/**
* Previous memory value for profiler
* @var float
*/
protected $_prevMemory = 0.0;
/**
* Fix bug anti cycling destructor
* @var bool
*/
protected static $_isDie = false;
/**
* Constructor, set internal variables and self configuration
* @param array $options Initialization parameters
*/
protected function __construct(array $options = array())
{
$this->setParams($options);
if (self::$_config['errors']['errorHandler']) {
set_error_handler(array($this, '_errorHandler'));
}
if (self::$_config['errors']['exceptionHandler']) {
set_exception_handler(array($this, '_exceptionHandler'));
}
$this->_start = $this->_microtime();
$this->_bufferInfo[] = array(
'time' => 0,
'timeDiff' => 0,
'memory' => self::_getMemory(),
'memoryDiff' => 0,
'label' => 'jbdump::init',
'trace' => '',
);
return $this;
}
/**
* Destructor, call _shutdown method
*/
function __destruct()
{
if (!self::$_isDie) {
self::$_isDie = true;
if (self::$_config['profiler']['showEnd']) {
self::mark('jbdump::end');
}
$this->profiler(self::$_config['profiler']['render']);
}
if (!self::$_config['profiler']['showOnAjax'] && self::isAjax()) {
return;
}
// JBDump incriment output
if (!empty(self::$_counters['mode_0'])) {
arsort(self::$_counters['mode_0']);
foreach (self::$_counters['mode_0'] as $counterName => $count) {
echo '<pre>JBDump Increment / "' . $counterName . '" = ' . $count . '</pre>';
}
}
// JBDump trace incriment output
if (!empty(self::$_counters['trace'])) {
uasort(self::$_counters['trace'], function ($a, $b) {
if ($a['count'] == $b['count']) {
return 0;
}
return ($a['count'] < $b['count']) ? 1 : -1;
});
foreach (self::$_counters['trace'] as $counterHash => $traceInfo) {
self::i()->dump($traceInfo['trace'], $traceInfo['label'] . ' = ' . $traceInfo['count']);
}
}
// JBDump pairs profiler
if (!empty(self::$_profilerPairs)) {
foreach (self::$_profilerPairs as $label => $pairs) {
$timeDelta = $memDelta = $count = 0;
$memDiffs = $timeDiffs = array();
foreach ($pairs as $key => $pair) {
if (!isset($pair['stop']) || !isset($pair['start'])) {
continue;
}
$count++;
$tD = $pair['stop'][0] - $pair['start'][0];
$mD = $pair['stop'][1] - $pair['start'][1];
$timeDiffs[] = $tD;
$memDiffs[] = $mD;
$timeDelta += $tD;
$memDelta += $mD;
}
if ($count > 0) {
$timeAvg = array_sum($timeDiffs) / $count;
$memoAvg = array_sum($memDiffs) / $count;
$timeStd = $memoStd = '';
if ($count > 1) {
$timeStdValue = $this->_stdDev($timeDiffs);
$memoStdValue = $this->_stdDev($memDiffs);
$timeStd = ' <span title="' . round(($timeStdValue / $timeAvg) * 100) . '%">(±'
. self::_profilerFormatTime($timeStdValue, true, 2) . ')</span>';
$memoStd = ' <span title="' . round(($memoStdValue / $memoAvg) * 100) . '%">(±'
. self::_profilerFormatMemory($memoStdValue, true) . ')</span>';
}
$output = array(
'<pre>JBDump ProfilerPairs / "' . $label . '"',
'Count = ' . $count,
'Time = ' . implode(";\t\t", array(
'ave: ' . self::_profilerFormatTime($timeAvg, true, 2) . $timeStd,
'sum: ' . self::_profilerFormatTime(array_sum($timeDiffs), true, 2),
'min(' . (array_search(min($timeDiffs), $timeDiffs) + 1) . '):' . self::_profilerFormatTime(min($timeDiffs), true, 2),
'max(' . (array_search(max($timeDiffs), $timeDiffs) + 1) . '): ' . self::_profilerFormatTime(max($timeDiffs), true, 2),
)),
'Memory = ' . implode(";\t\t", array(
'ave: ' . self::_profilerFormatMemory($memoAvg, true) . $memoStd,
'sum: ' . self::_profilerFormatMemory(array_sum($memDiffs), true),
'min(' . (array_search(min($memDiffs), $memDiffs) + 1) . '): ' . self::_profilerFormatMemory(min($memDiffs), true),
'max(' . (array_search(max($memDiffs), $memDiffs) + 1) . '): ' . self::_profilerFormatMemory(max($memDiffs), true),
)),
'</pre>'
);
} else {
$output = array(
'<pre>JBDump ProfilerPairs / "' . $label . '"',
'Count = ' . $count,
'</pre>'
);
}
echo implode(PHP_EOL, $output);
}
}
}
/**
* Returns the global JBDump object, only creating it
* if it doesn't already exist
* @param array $options Initialization parameters
* @return JBDump
*/
public static function i($options = array())
{
static $instance;
if (!isset($instance)) {
$instance = new self($options);
if (self::$_config['profiler']['showStart']) {
self::mark('jbdump::start');
}
}
return $instance;
}
/**
* Include css and js files in document
* @param bool $force
* @return void
*/
protected function _initAssets($force = true)
{
static $loaded;
if (!isset($loaded) || $force) {
$loaded = true;
echo
'<script type="text/javascript">
function jbdump() {}
jbdump.reclass = function (el, className) {if (el.className.indexOf(className) < 0) {el.className += " " + className;}};
jbdump.unclass = function (el, className) {if (el.className.indexOf(className) > -1) {el.className = el.className.replace(" " + className, "");}};
jbdump.toggle = function (el) {var ul = el.parentNode.getElementsByTagName("ul");for (var i = 0; i < ul.length; i++) {
if (ul[i].parentNode.parentNode == el.parentNode) {ul[i].parentNode.style.display = ul[i].parentNode.style.display == "none" ? "block" : "none";}}
if (ul[0].parentNode.style.display == "block") {jbdump.reclass(el, "jbopened");} else {jbdump.unclass(el, "jbopened");}};
</script>
<style>
#jbdump{border:solid 1px #333;border-radius:6px;position:relative;z-index:10101;min-width:400px;max-width:1280px;margin:6px auto;padding:6px;clear:both;background:#fff;opacity:1;filter:alpha(opacity=100);font-size:12px !important;line-height:16px !important;text-align:left!important;}
#jbdump ::selection {background: #89cac9;color: #333;text-shadow: none;}
#jbdump *{opacity:1;filter:alpha(opacity=100);font-size:12px !important;line-height:16px!important;font-family:monospace, Verdana, Helvetica;margin:0;padding:0;color:#333;}
#jbdump li{list-style:none !important;}
#jbdump .jbnode{margin: 0;padding: 0;}
#jbdump .jbchild{margin: 0;padding: 0;}
#jbdump .jbnode .jbnode{margin-left:20px;}
#jbdump .jbnode .jbpreview{font-family:"Courier New";font-size:12px!important;overflow-wrap:normal;flex-direction:row;display:block;word-wrap:normal;white-space:pre;background:#f9f9b5;border:solid 1px #808000;border-radius:6px;overflow:auto;margin:12px 0;padding:6px;min-height:58px;height:300px;text-align:left !important;width:97%;color:#333;min-width:300px;}
#jbdump .jbnode .jbpreview * {font-family:"Courier New";font-size:12px!important;}
#jbdump .jbchild{overflow:hidden;}
#jbdump .jbvalue{font-weight:bold;font-family:monospace, Verdana, Helvetica;font-size:12px;}
#jbdump .jbfooter{border-top:1px dotted #ccc;padding-top:4px;}
#jbdump .jbfooter .jbversion{float:right;}
#jbdump .jbfooter .jbversion a{color:#ddd;font-size:10px !important;text-decoration:none;}
#jbdump .jbfooter .jbversion a:hover{color:#333;text-decoration:underline;}
#jbdump .jbfooter .jbpath{font-family:"Courier New";}
#jbdump .jbelement{padding:3px 3px 3px 20px;background-repeat:no-repeat;background-color:#fff;background-position:5px 6px;background-image:url(\'data:image/gif;base64,R0lGODlhCQAJALMAAP////8AAICAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAJAAkAAAQSEAAhq6VWUpx3n+AVVl42ilkEADs=\');}
#jbdump .jbelement:hover{background-color:#c6e5ff;}
#jbdump .jbelement.jbexpand{background-image:url(\'data:image/gif;base64,R0lGODlhCQAJALMAAP///wAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAJAAkAAAQTEIAna33USpwt79vncRpZgpcGRAA7\');cursor:pointer;}
#jbdump .jbelement.jbexpand.jbopened{background-image:url(\'data:image/gif;base64,R0lGODlhCQAJALMAAP///wAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAJAAkAAAQQEMhJ63w4Z6C37JUXWmQJRAA7\');}
#jbdump .jbelement .jbname{color:#a00;font-weight:bold;}
#jbdump .jbelement .jbtype-integer{color:#00d;}
#jbdump .jbelement .jbtype-float{color:#099;}
#jbdump .jbelement .jbtype-boolean{color:#990;}
#jbdump .jbelement .jbtype-string{color:#090;}
#jbdump .jbelement .jbtype-array{color:#990;}
#jbdump .jbelement .jbtype-null{color:#999;}
#jbdump .jbelement .jbtype-max-depth{color:#900;}
#jbdump .jbelement .jbtype-object{color:#c0c;}
#jbdump .jbelement .jbtype-closure{color:#c0c;}
#jbdump_profile_chart_table td img{height:12px !important;}
#jbdump_profile_chart_table{color:#333 !important;}
.google-visualization-table-table td img{height:12px !important;}
</style>';
}
}
/**
* Check permissions for show all debug messages
* - check ip, it if set in config
* - check requestParam, if it set in config
* - else return self::$enabled
* @return bool
*/
public static function isDebug()
{
$result = self::$enabled;
if ($result) {
if (self::$_config['personal']['ip']) {
if (is_array(self::$_config['personal']['ip'])) {
$result = in_array(self::getClientIP(), self::$_config['personal']['ip']);
} else {
$result = self::getClientIP() == self::$_config['personal']['ip'];
}
}
if (self::$_config['personal']['requestParam'] && $result) {
if (isset($_REQUEST[self::$_config['personal']['requestParam']])
&&
$_REQUEST[self::$_config['personal']['requestParam']] == self::$_config['personal']['requestValue']
) {
$result = true;
} else {
$result = false;
}
}
}
return $result;
}
/**
* Force show PHP error messages
* @param $reportLevel error_reporting level
* @return bool
*/
public static function showErrors($reportLevel = -1)
{
if (!self::isDebug()) {
return false;
}
if ($reportLevel === null || $reportLevel === false) {
return false;
}
if ($reportLevel != 0) {
error_reporting($reportLevel);
ini_set('error_reporting', $reportLevel);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
} else {
error_reporting(0);
ini_set('error_reporting', 0);
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
}
return true;
}
/**
* Set max execution time
* @param integer $time Time limit in seconds
* @return JBDump
*/
public static function maxTime($time = 600)
{
if (!self::isDebug()) {
return false;
}
ini_set('max_execution_time', $time);
set_time_limit($time);
return self::i();
}
/**
* Enable debug
* @return JBDump
*/
public static function on()
{
self::$enabled = true;
return self::i();
}
/**
* Disable debug
* @return JBDump
*/
public static function off()
{
self::$enabled = false;
return self::i();
}
/**
* Set debug parameters
* @param array $data Params for debug, see self::$_config vars
* @param string $section
* @return JBDump
*/
public function setParams($data, $section = null)
{
if ($section) {
$newData = array($section => $data);
$data = $newData;
unset($newData);
}
if (isset($data['errors']['reporting'])) {
$this->showErrors($data['errors']['reporting']);
}
// set root directory
if (!isset($data['root']) && !self::$_config['root']) {
$data['root'] = $_SERVER['DOCUMENT_ROOT'];
}
// set log path
if (isset($data['log']['path']) && $data['log']['path']) {
$this->_logPath = $data['log']['path'];
} elseif (!self::$_config['log']['path'] || !$this->_logPath) {
$this->_logPath = dirname(__FILE__) . self::DS . 'logs';
}
// set log filename
$logFile = 'jbdump';
if (isset($data['log']['file']) && $data['log']['file']) {
$logFile = $data['log']['file'];
} elseif (!self::$_config['log']['file'] || !$this->_logfile) {
$logFile = 'jbdump';
}
$this->_logfile = $this->_logPath . self::DS . $logFile . '_' . date('Y.m.d') . '.log.php';
// merge new params with of config
foreach ($data as $key => $value) {
if (is_array($value)) {
foreach ($value as $keyInner => $valueInner) {
if (!isset(self::$_config[$key])) {
self::$_config[$key] = array();
}
self::$_config[$key][$keyInner] = $valueInner;
}
} else {
self::$_config[$key] = $value;
}
}
return $this;
}
/**
* Show client IP
* @return JBDump
*/
public static function ip()
{
if (!self::isDebug()) {
return false;
}
$ip = self::getClientIP();
$data = array(
'ip' => $ip,
'host' => gethostbyaddr($ip),
'source' => '$_SERVER["' . self::getClientIP(true) . '"]',
'inet_pton' => inet_pton($ip),
'ip2long' => ip2long($ip),
);
return self::i()->dump($data, '! my IP = ' . $ip . ' !');
}
/**
* Show $_GET array
* @return JBDump
*/
public static function get()
{
if (!self::isDebug()) {
return false;
}
return self::i()->dump($_GET, '! $_GET !');
}
/**
* Add message to log file
* @param mixed $entry Text to log file
* @param string $markName Name of log record
* @param array $params Additional params
* @return JBDump
*/
public static function log($entry, $markName = '...', $params = array())
{
if (!self::isDebug()) {
return false;
}
// emulate normal class
$_this = self::i();
// check var type
if (is_bool($entry)) {
$entry = ($entry) ? 'TRUE' : 'FALSE';
} elseif (is_null($entry)) {
$entry = 'NULL';
} elseif (is_resource($entry)) {
$entry = 'resource of "' . get_resource_type($entry) . '"';
}
// serialize type
if (self::$_config['log']['serialize'] == 'formats') {
// don't change log entry
} elseif (self::$_config['log']['serialize'] == 'none') {
$entry = array('jbdump_message' => $entry);
} elseif (self::$_config['log']['serialize'] == 'json') {
$entry = array('jbdump_message' => @json_encode($entry));
} elseif (self::$_config['log']['serialize'] == 'serialize') {
$entry = array('jbdump_message' => serialize($entry));
} elseif (self::$_config['log']['serialize'] == 'print_r') {
$entry = array('jbdump_message' => print_r($entry, true));
} elseif (self::$_config['log']['serialize'] == 'php_array') {
$markName = (empty($markName) || $markName == '...') ? 'dumpVar' : $markName;
$entry = array('jbdump_message' => JBDump_array2php::toString($entry, $markName));
} elseif (self::$_config['log']['serialize'] == 'var_dump') {
ob_start();
var_dump($entry);
$entry = ob_get_clean();
$entry = array('jbdump_message' => var_dump($entry, true));
}
if (isset($params['trace'])) {
$_this->_trace = $params['trace'];
} else {
$_this->_trace = debug_backtrace();
}
$entry['name'] = $markName;
$entry['datetime'] = date(self::DATE_FORMAT);
$entry['client_ip'] = self::getClientIP();
$entry['file'] = $_this->_getSourcePath($_this->_trace, true);
$entry = array_change_key_case($entry, CASE_UPPER);
$fields = array();
$format = isset($params['format']) ? $params['format'] : self::$_config['log']['format'];
preg_match_all("/{(.*?)}/i", $format, $fields);
// Fill in the field data
$line = $format;
for ($i = 0; $i < count($fields[0]); $i++) {
$line = str_replace($fields[0][$i], (isset ($entry[$fields[1][$i]])) ? $entry[$fields[1][$i]] : "-", $line);
}
// Write the log entry line
if ($_this->_openLog()) {
error_log($line . PHP_EOL, 3, $_this->_logfile);
}
return $_this;
}
/**
* Open log file
* @return bool
*/
function _openLog()
{
if (!@file_exists($this->_logfile)) {
if (!is_dir($this->_logPath) && $this->_logPath) {
mkdir($this->_logPath, 0777, true);
}
$header[] = "#<?php die('Direct Access To Log Files Not Permitted'); ?>";
$header[] = "#Date: " . date(DATE_RFC822, time());
$header[] = "#Software: JBDump v" . self::VERSION . ' by Joomla-book.ru';
$fields = str_replace("{", "", self::$_config['log']['format']);
$fields = str_replace("}", "", $fields);
$fields = strtolower($fields);
$header[] = '#' . str_replace("\t", "\t", $fields);
$head = implode(PHP_EOL, $header);
} else {
$head = false;
}
if ($head) {
error_log($head . PHP_EOL, 3, $this->_logfile);
}
return true;
}
/**
* Show $_FILES array
* @return JBDump
*/
public static function files()
{
if (!self::isDebug()) {
return false;
}
return self::i()->dump($_FILES, '! $_FILES !');
}
/**
* Show current usage memory in filesize format
* @return JBDump
*/
public static function memory($formated = true)
{
if (!self::isDebug()) {
return false;
}
$memory = self::i()->_getMemory();
if ($formated) {
$memory = self::i()->_formatSize($memory);
}
return self::i()->dump($memory, '! memory !');
}
/**
* Show declared interfaces
* @return JBDump
*/
public static function interfaces()
{
if (!self::isDebug()) {
return false;
}
return self::i()->dump(get_declared_interfaces(), '! interfaces !');
}
/**
* Parse url
* @param string $url URL string
* @param string $varname URL name
* @return JBDump
*/
public static function url($url, $varname = '...')
{
if (!self::isDebug()) {
return false;
}
$parsed = parse_url($url);
if (isset($parsed['query'])) {
parse_str($parsed['query'], $parsed['query_parsed']);
}
return self::i()->dump($parsed, $varname);
}
/**
* Show included files
* @return JBDump
*/
public static function includes()
{
if (!self::isDebug()) {
return false;
}
return self::i()->dump(get_included_files(), '! includes files !');
}
/**
* Show defined functions
* @param bool $showInternal Get only internal functions
* @return JBDump
*/
public static function functions($showInternal = false)
{
if (!self::isDebug()) {
return false;
}
$functions = get_defined_functions();
if ($showInternal) {
$functions = $functions['internal'];
$type = 'internal';
} else {
$functions = $functions['user'];
$type = 'user';
}
return self::i()->dump($functions, '! functions (' . $type . ') !');
}
/**
* Show defined constants
* @param bool $showAll Get only user defined functions
* @return bool|JBDump
*/
public static function defines($showAll = false)
{
if (!self::isDebug()) {
return false;
}
$defines = get_defined_constants(true);
if (!$showAll) {
$defines = (isset($defines['user'])) ? $defines['user'] : array();
}
return self::i()->dump($defines, '! defines !');
}
/**
* Show loaded PHP extensions
* @param bool $zend Get only Zend extensions
* @return JBDump
*/
public static function extensions($zend = false)
{
if (!self::isDebug()) {
return false;
}
return self::i()->dump(get_loaded_extensions($zend), '! extensions ' . ($zend ? '(Zend)' : '') . ' !');
}
/**
* Show HTTP headers
* @return JBDump
*/
public static function headers()
{
if (!self::isDebug()) {
return false;
}
if (function_exists('apache_request_headers')) {
$data = array(
'Request' => apache_request_headers(),
'Response' => apache_response_headers(),
'List' => headers_list()
);
} else {
$data = array(
'List' => headers_list()
);
}
if (headers_sent($filename, $linenum)) {
$data['Sent'] = 'Headers already sent in ' . self::i()->_getRalativePath($filename) . ':' . $linenum;
} else {
$data['Sent'] = false;
}
return self::i()->dump($data, '! headers !');
}
/**
* Show php.ini content (open php.ini file)
* @return JBDump
*/
public static function phpini()
{
if (!self::isDebug()) {
return false;
}
$data = get_cfg_var('cfg_file_path');
if (!@file($data)) {
return false;
}
$ini = parse_ini_file($data, true);
return self::i()->dump($ini, '! php.ini !');
}
/**
* Show php.ini content (PHP API)
* @param string $extension Extension name
* @param bool $details Retrieve details settings or only the current value for each setting
* @return bool|JBDump
*/
public static function conf($extension = '', $details = true)
{
if (!self::isDebug()) {
return false;
}
if ($extension == '') {
$label = '';
$data = ini_get_all();
} else {
$label = ' (' . $extension . ') ';
$data = ini_get_all($extension, $details);
}
return self::i()->dump($data, '! configuration settings' . $label . ' !');
}
/**
* Show included and system paths
* @return JBDump
*/
public static function path()
{
if (!self::isDebug()) {
return false;
}
$result = array(
'get_include_path' => explode(PATH_SEPARATOR, trim(get_include_path(), PATH_SEPARATOR)),
'$_SERVER[PATH]' => explode(PATH_SEPARATOR, trim($_SERVER['PATH'], PATH_SEPARATOR))
);
return self::i()->dump($result, '! paths !');
}
/**
* Show $_REQUEST array or dump $_GET, $_POST, $_COOKIE
* @param bool $notReal Get real $_REQUEST array
* @return bool|JBDump
*/
public static function request($notReal = false)
{
if (!self::isDebug()) {
return false;
}
if ($notReal) {
self::get();
self::post();
self::cookie();
return self::files();
} else {
return self::i()->dump($_REQUEST, '! $_REQUEST !');
}
}
/**