Skip to content

Commit 2ff8e7f

Browse files
committed
More PHPDebugConsole v3.3 updates
1 parent c092fa1 commit 2ff8e7f

7 files changed

Lines changed: 235 additions & 149 deletions

File tree

src/js/main.js

Lines changed: 117 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@
373373
this.dump = dump;
374374
}
375375

376-
Table.prototype.build = function (rows, meta, onBuildRow) {
376+
Table.prototype.build = function (rows, meta, onBuildRow, info) {
377377
// console.warn('Table.build', meta, classname)
378-
meta = $$1.extend({
378+
var metaDefault = {
379379
attribs: {
380380
class: [
381381
'table-bordered',
@@ -384,25 +384,31 @@
384384
]
385385
},
386386
caption: '',
387-
tableInfo: {}
388-
}, meta);
387+
tableInfo: {
388+
columns: [],
389+
haveObjRow: false,
390+
rows: [],
391+
}
392+
};
393+
meta.tableInfo = $$1.extend(metaDefault.tableInfo, meta.tableInfo);
394+
meta = $$1.extend(metaDefault, meta);
389395
if (meta.caption === null) {
390396
meta.caption = '';
391397
}
392398
$table = $$1('<table>' +
393-
'<caption>' + meta.caption.escapeHtml() + '</caption>' +
399+
(meta.caption.length ? '<caption>' + meta.caption.escapeHtml() + '</caption>' : '')+
394400
'<thead><tr><th>&nbsp;</th></tr></thead>' +
395401
'<tbody></tbody>' +
396402
'</table>'
397403
)
398404
.addClass(meta.attribs.class.join(' '));
399405
this.buildHeader(meta.tableInfo);
400-
this.buildBody(rows, meta.tableInfo, onBuildRow);
406+
this.buildBody(rows, meta.tableInfo, onBuildRow, info);
401407
this.buildFooter(meta.tableInfo);
402408
return $table
403409
};
404410

405-
Table.prototype.buildBody = function (rows, tableInfo, onBuildRow) {
411+
Table.prototype.buildBody = function (rows, tableInfo, onBuildRow, info) {
406412
var i;
407413
var length;
408414
var i2;
@@ -430,7 +436,9 @@
430436
if (typeof rowKey === 'string' && rowKey.match(/^\d+$/) && Number.isSafeInteger(rowKey)) {
431437
rowKey = parseInt(rowKey, 10);
432438
}
433-
parsed = this.dump.parseTag(this.dump.dump(rowKey));
439+
parsed = this.dump.parseTag(this.dump.dump(rowKey, {
440+
requestInfo: info,
441+
}));
434442
$tr = $$1('<tr></tr>', rowInfo.attribs || {})
435443
.append(
436444
$$1('<th scope="row" class="t_key text-right"></th>')
@@ -455,7 +463,10 @@
455463
$('<td />').html(parsed.innerhtml).attr(parsed.attribs)
456464
)
457465
*/
458-
$tr.append(this.dump.dump(row[key], { tagName: 'td' }));
466+
$tr.append(this.dump.dump(row[key], {
467+
requestInfo: info,
468+
tagName: 'td'
469+
}));
459470
}
460471
if (onBuildRow) {
461472
$tr = onBuildRow($tr, row, rowInfo, rowKey);
@@ -2975,7 +2986,7 @@
29752986

29762987
Cases.prototype.dumpInner = function (name, info, cfg) {
29772988
var title = cfg.phpDocOutput
2978-
? info.desc
2989+
? info.phpDoc.summary || info.desc || null
29792990
: null;
29802991
var $element = $$1('<div></div>')
29812992
.html('<span class="t_identifier">' + name + '</span>' +
@@ -2986,6 +2997,7 @@
29862997
)
29872998
);
29882999
if (title && title.length) {
3000+
title = this.valDumper.dumpPhpDocStr(title);
29893001
$element.find('.t_identifier').attr('title', title);
29903002
}
29913003
return $element[0].innerHTML
@@ -3474,10 +3486,13 @@
34743486
property: true,
34753487
setHook: info.hooks.indexOf('set') > -1
34763488
};
3477-
$element.addClass(info.visibility).removeClass('debug');
3478-
$$1.each(classes, function (classname, useClass) {
3489+
var visibility = typeof info.visibility === 'object'
3490+
? info.visibility.join(' ')
3491+
: info.visibility;
3492+
$element.addClass(visibility).removeClass('debug');
3493+
$$1.each(classes, function (className, useClass) {
34793494
if (useClass) {
3480-
$element.addClass(classname);
3495+
$element.addClass(className);
34813496
}
34823497
});
34833498
sectionPrototype.addAttribs($element, info, cfg);
@@ -3520,7 +3535,9 @@
35203535
modifiers.push('static');
35213536
}
35223537
$$1.each(modifiers, function (i, modifier) {
3523-
html += '<span class="t_modifier_' + modifier + '">' + modifier + '</span> ';
3538+
var cssClass = 't_modifier_' + modifier;
3539+
modifier = modifier.replace('-set', '(set)');
3540+
html += '<span class="' + cssClass + '">' + modifier + '</span> ';
35243541
});
35253542
return html
35263543
};
@@ -5049,11 +5066,12 @@
50495066
};
50505067

50515068
Dump.prototype.dumpConst = function (abs) {
5052-
var dumpOpts = this.getDumpOpts();
5053-
dumpOpts.attribs.title = abs.value !== this.UNDEFINED
5054-
? 'value: ' + this.dump(abs.value)
5055-
: null;
5056-
return this.markupIdentifier(abs.name, 'const')
5069+
return this.dumpIdentifier({
5070+
backedValue: abs.value,
5071+
type: 'identifier',
5072+
typeMore: 'const',
5073+
value: abs.name,
5074+
})
50575075
};
50585076

50595077
Dump.prototype.dumpFloat = function (val, abs) {
@@ -5067,6 +5085,14 @@
50675085
return val
50685086
};
50695087

5088+
Dump.prototype.dumpIdentifier = function (abs) {
5089+
var dumpOpts = this.getDumpOpts();
5090+
dumpOpts.attribs.title = [undefined, this.UNDEFINED].indexOf(abs.backedValue) < 0
5091+
? 'value: ' + this.dump(abs.backedValue)
5092+
: null;
5093+
return this.markupIdentifier(abs.value, abs.typeMore)
5094+
};
5095+
50705096
Dump.prototype.dumpInt = function (val, abs) {
50715097
return this.dumpFloat(val, abs)
50725098
};
@@ -5228,7 +5254,7 @@
52285254
}
52295255
if (parts.identifier) {
52305256
parts.identifier = this.dumpPhpDocStr(parts.identifier);
5231-
parts.identifier = '<span class="t_identifier">' + parts.identifier + '</span>';
5257+
parts.identifier = '<span class="t_name">' + parts.identifier + '</span>';
52325258
}
52335259
return [parts.className, parts.identifier].filter(function (val) {
52345260
return val !== ''
@@ -5254,22 +5280,33 @@
52545280
};
52555281

52565282
var dump = new Dump();
5283+
var subRegex = new RegExp('%' +
5284+
'(?:' +
5285+
'[coO]|' + // c: css, o: obj with max info, O: obj w generic info
5286+
'[+-]?' + // sign specifier
5287+
'(?:[ 0]|\'.)?' + // padding specifier
5288+
'-?' + // alignment specifier
5289+
'\\d*' + // width specifier
5290+
'(?:\\.\\d+)?' + // precision specifier
5291+
'[difs]' +
5292+
')', 'g');
52575293
var table = new Table(dump);
52585294

52595295
var methods = {
52605296
alert: function (logEntry, info) {
5261-
var message;
5262-
var level = logEntry.meta.level || logEntry.meta.class;
5263-
var dismissible = logEntry.meta.dismissible;
52645297
var $node = $$1('<div class="m_alert"></div>')
5265-
.addClass('alert-' + level)
5298+
.addClass('alert-' + (logEntry.meta.level || logEntry.meta.class))
52665299
// .html(message)
52675300
.attr('data-channel', logEntry.meta.channel); // using attr so can use [data-channel="xxx"] selector
5268-
if (logEntry.args.length > 1) {
5269-
processSubstitutions(logEntry);
5270-
}
5271-
message = logEntry.args[0];
5272-
$node.html(message);
5301+
var dismissible = logEntry.meta.dismissible;
5302+
var html = logEntry.args.length > 1
5303+
? buildEntryNode(logEntry, info).html()
5304+
: dump.dump(logEntry.args[0], {
5305+
sanitize: logEntry.meta.sanitizeFirst,
5306+
tagName: null, // don't wrap value span
5307+
visualWhiteSpace: false,
5308+
});
5309+
$node.html(html);
52735310
if (dismissible) {
52745311
$node.prepend('<button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
52755312
'<span aria-hidden="true">&times;</span>' +
@@ -5558,7 +5595,8 @@
55585595
logEntry.meta,
55595596
logEntry.meta.inclContext
55605597
? tableAddContextRow
5561-
: null
5598+
: null,
5599+
info
55625600
);
55635601
return $$1('<li>', { class: 'm_' + logEntry.method }).append($table)
55645602
},
@@ -5583,7 +5621,6 @@
55835621
update card header to emphasize error
55845622
*/
55855623
if (meta.errorCat) {
5586-
// console.warn('errorCat', meta.errorCat)
55875624
attribs.class += ' error-' + meta.errorCat;
55885625
if (!meta.isSuppressed) {
55895626
if (method === 'error') {
@@ -5599,18 +5636,19 @@
55995636
if (meta.uncollapse !== undefined) {
56005637
attribs['data-uncollapse'] = JSON.stringify(meta.uncollapse);
56015638
}
5602-
if (['assert', 'error', 'info', 'log', 'warn'].indexOf(method) > -1 && logEntry.args.length > 1) {
5603-
/*
5604-
update tab
5605-
*/
5606-
if (method === 'error') {
5607-
getTab(info).addClass('has-error');
5608-
} else if (method === 'warn') {
5609-
getTab(info).addClass('has-warn');
5610-
} else if (method === 'assert') {
5611-
getTab(info).addClass('has-assert');
5612-
}
5613-
processSubstitutions(logEntry);
5639+
/*
5640+
if (['assert', 'error', 'info', 'log', 'warn'].indexOf(method) > -1 && logEntry.args.length > 1)) {
5641+
}
5642+
*/
5643+
/*
5644+
update tab
5645+
*/
5646+
if (method === 'error') {
5647+
getTab(info).addClass('has-error');
5648+
} else if (method === 'warn') {
5649+
getTab(info).addClass('has-warn');
5650+
} else if (method === 'assert') {
5651+
getTab(info).addClass('has-assert');
56145652
}
56155653
$node = buildEntryNode(logEntry, info);
56165654
$node.attr(attribs);
@@ -5724,14 +5762,20 @@
57245762
var glueAfterFirst = true;
57255763
var args = logEntry.args;
57265764
var numArgs = args.length;
5727-
var meta = $$1.extend({
5765+
var typeInfo;
5766+
var typeMore;
5767+
logEntry.meta = $$1.extend({
57285768
sanitize: true,
57295769
sanitizeFirst: null
57305770
}, logEntry.meta);
5731-
var typeInfo;
5732-
var typeMore;
5733-
if (meta.sanitizeFirst === null) {
5734-
meta.sanitizeFirst = meta.sanitize;
5771+
if (logEntry.meta.sanitizeFirst === null) {
5772+
logEntry.meta.sanitizeFirst = logEntry.meta.sanitize;
5773+
}
5774+
// console.warn('buildEntryNode', JSON.parse(JSON.stringify(logEntry)))
5775+
if (numArgs > 1) {
5776+
processSubstitutions(logEntry);
5777+
args = logEntry.args;
5778+
numArgs = args.length;
57355779
}
57365780
if (typeof args[0] === 'string') {
57375781
if (args[0].match(/[=:]\s*$/)) {
@@ -5751,8 +5795,8 @@
57515795
addQuotes: i !== 0 || typeMore === 'numeric',
57525796
requestInfo: requestInfo,
57535797
sanitize: i === 0
5754-
? meta.sanitizeFirst
5755-
: meta.sanitize,
5798+
? logEntry.meta.sanitizeFirst
5799+
: logEntry.meta.sanitize,
57565800
type: typeInfo[0],
57575801
typeMore: typeInfo[1] || null,
57585802
visualWhiteSpace: i !== 0
@@ -5785,7 +5829,9 @@
57855829
var label = logEntry.args.shift();
57865830
label = logEntry.meta.isFuncName
57875831
? dump.markupIdentifier(label, 'function')
5788-
: dump.dump(label).replace(new RegExp('^<span class="t_string">(.+)</span>$', 's'), '$1');
5832+
: dump.dump(label, {
5833+
requestInfo: requestInfo
5834+
}).replace(new RegExp('^<span class="t_string">(.+)</span>$', 's'), '$1');
57895835
for (i = 0; i < logEntry.args.length; i++) {
57905836
logEntry.args[i] = dump.dump(logEntry.args[i], {
57915837
requestInfo: requestInfo,
@@ -5811,33 +5857,34 @@
58115857
return $header
58125858
}
58135859

5860+
function containsSubstitutions(logEntry)
5861+
{
5862+
if (logEntry.args.length < 2 || typeof logEntry.args[0] !== 'string') {
5863+
return false
5864+
}
5865+
return logEntry.args[0].match(subRegex) !== null
5866+
}
5867+
5868+
58145869
/**
58155870
* @param logEntry
58165871
*
58175872
* @return void
58185873
*/
58195874
function processSubstitutions (logEntry, opts) {
5820-
var subRegex = '%' +
5821-
'(?:' +
5822-
'[coO]|' + // c: css, o: obj with max info, O: obj w generic info
5823-
'[+-]?' + // sign specifier
5824-
'(?:[ 0]|\'.)?' + // padding specifier
5825-
'-?' + // alignment specifier
5826-
'\\d*' + // width specifier
5827-
'(?:\\.\\d+)?' + // precision specifier
5828-
'[difs]' +
5829-
')';
58305875
var args = logEntry.args;
58315876
var argLen = args.length;
5832-
var hasSubs = false;
58335877
var index = 0;
58345878
var typeCounts = {
58355879
c: 0
58365880
};
5837-
if (typeof args[0] !== 'string' || argLen < 2) {
5881+
if (containsSubstitutions(logEntry) === false) {
58385882
return
58395883
}
5840-
subRegex = new RegExp(subRegex, 'g');
5884+
args[0] = dump.dump(args[0], {
5885+
sanitize: logEntry.meta.sanitizeFirst,
5886+
tagName: null
5887+
});
58415888
args[0] = args[0].replace(subRegex, function (match) {
58425889
var replacement = match;
58435890
var type = match.substr(-1);
@@ -5867,17 +5914,13 @@
58675914
delete args[index]; // sets to undefined
58685915
return replacement
58695916
});
5870-
// using reduce to perform an array_sum
5871-
hasSubs = Object.values(typeCounts).reduce(function (acc, val) { return acc + val }, 0) > 0;
5872-
if (hasSubs) {
5873-
if (typeCounts.c) {
5874-
args[0] += '</span>';
5875-
}
5876-
logEntry.args = args.filter(function (val) {
5877-
return val !== undefined
5878-
});
5879-
logEntry.meta.sanitizeFirst = false;
5917+
if (typeCounts.c) {
5918+
args[0] += '</span>';
58805919
}
5920+
logEntry.args = args.filter(function (val) {
5921+
return val !== undefined
5922+
});
5923+
logEntry.meta.sanitizeFirst = false;
58815924
}
58825925

58835926
/**

src/js/main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)