Skip to content

Commit cd3cc7d

Browse files
committed
improve backwards compatibility with PhpDebugConsole < 3.2
1 parent 85908f4 commit cd3cc7d

13 files changed

Lines changed: 272 additions & 103 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"psr-4": { "bdk\\Debug\\": "src/" }
1717
},
1818
"require": {
19-
"bdk/debug": "dev-master"
19+
"bdk/debug": "^3.2"
2020
},
2121
"scripts": {
2222
"post-create-project-cmd": "php -r \"copy('src/index.php', 'index.php');\""

src/js/main.js

Lines changed: 134 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,15 +2865,24 @@
28652865
var info = {};
28662866
var vis = [];
28672867
for (name in items) {
2868+
info = items[name];
2869+
if (typeof info.inheritedFrom !== 'undefined') {
2870+
info.declaredLast = info.inheritedFrom; // note that only populated if inherited...
2871+
// we don't know where it was declared
2872+
delete info.inheritedFrom;
2873+
}
2874+
if (typeof info.overrides !== 'undefined') {
2875+
info.declaredPrev = info.overrides;
2876+
delete info.overrides;
2877+
}
28682878
info = $.extend({
28692879
declaredLast : null,
28702880
declaredPrev : null,
2871-
objClassName : cfg.objClassName, // used by Properties to determine "isDynamic"
2872-
}, items[name]);
2881+
}, info);
28732882
vis = typeof info.visibility === 'object'
28742883
? info.visibility
28752884
: [info.visibility];
2876-
info.isInherited = info.declaredLast && info.declaredLast !== info.objClassName;
2885+
info.isInherited = info.declaredLast && info.declaredLast !== cfg.objClassName;
28772886
info.isPrivateAncestor = $.inArray('private', vis) >= 0 && info.isInherited;
28782887
if (info.isPrivateAncestor) {
28792888
info.isInherited = false;
@@ -2891,7 +2900,15 @@
28912900
},
28922901

28932902
addAttribs: function ($element, info, cfg) {
2894-
2903+
if (cfg.attributeOutput && info.attributes && info.attributes.length) {
2904+
$element.attr('data-attributes', JSON.stringify(info.attributes));
2905+
}
2906+
if (!info.isInherited && info.declaredPrev) {
2907+
$element.attr('data-declared-prev', info.declaredPrev);
2908+
}
2909+
if (info.isInherited && info.declaredLast) {
2910+
$element.attr('data-inherited-from', info.declaredLast);
2911+
}
28952912
},
28962913

28972914
magicMethodInfo: function (abs, methods) {
@@ -2925,9 +2942,7 @@
29252942

29262943
Cases.prototype.addAttribs = function ($element, info, cfg) {
29272944
$element.addClass('case');
2928-
if (cfg.attributeOutput && info.attributes && info.attributes.length) {
2929-
$element.attr('data-attributes', JSON.stringify(info.attributes));
2930-
}
2945+
sectionPrototype.addAttribs($element, info, cfg);
29312946
};
29322947

29332948
Cases.prototype.dump = function (abs) {
@@ -2992,12 +3007,7 @@
29923007
$element.addClass(classname);
29933008
}
29943009
});
2995-
if (cfg.attributeOutput && info.attributes && info.attributes.length) {
2996-
$element.attr('data-attributes', JSON.stringify(info.attributes));
2997-
}
2998-
if (info.isInherited || info.isPrivateAncestor) {
2999-
$element.attr('data-inherited-from', info.declaredLast);
3000-
}
3010+
sectionPrototype.addAttribs($element, info, cfg);
30013011
};
30023012

30033013
Constants.prototype.dump = function (abs) {
@@ -3062,15 +3072,10 @@
30623072
$element.addClass(classname);
30633073
}
30643074
});
3065-
if (cfg.attributeOutput && info.attributes && info.attributes.length) {
3066-
$element.attr('data-attributes', JSON.stringify(info.attributes));
3067-
}
3075+
sectionPrototype.addAttribs($element, info, cfg);
30683076
if (info.implements && info.implements.length) {
30693077
$element.attr('data-implements', info.implements);
30703078
}
3071-
if (info.isInherited) {
3072-
$element.attr('data-inherited-from', info.declaredLast);
3073-
}
30743079
if (info.phpDoc && info.phpDoc.deprecated) {
30753080
$element.attr('data-deprecated-desc', info.phpDoc.deprecated[0].desc);
30763081
}
@@ -3093,7 +3098,7 @@
30933098
return ''
30943099
}
30953100
if (!cfg.collect) {
3096-
return html
3101+
return ''
30973102
}
30983103
return '<dt class="methods">' + this.getLabel(abs) + '</dt>' +
30993104
this.magicMethodInfo(abs, ['__call', '__callStatic']) +
@@ -3219,7 +3224,7 @@
32193224
Methods.prototype.dumpStaticVars = function (info, cfg) {
32203225
var self = this;
32213226
var html = '';
3222-
if (!cfg.staticVarOutput || info.staticVars.length < 1) {
3227+
if (!cfg.staticVarOutput || typeof info.staticVars === 'undefined' || info.staticVars.length < 1) {
32233228
return ''
32243229
}
32253230
html = '<h3>static variables</h3>';
@@ -3249,6 +3254,52 @@
32493254
return label
32503255
};
32513256

3257+
function versionCompare (v1, v2) {
3258+
var v1parts = v1.split('.');
3259+
var v2parts = v2.split('.');
3260+
3261+
function isValidPart(x) {
3262+
return (/^\d+$/).test(x)
3263+
}
3264+
3265+
if (!v1parts.every(isValidPart) || !v2parts.every(isValidPart)) {
3266+
return NaN
3267+
}
3268+
3269+
{
3270+
while (v1parts.length < v2parts.length) {
3271+
v1parts.push('0');
3272+
}
3273+
while (v2parts.length < v1parts.length) {
3274+
v2parts.push('0');
3275+
}
3276+
}
3277+
3278+
{
3279+
v1parts = v1parts.map(Number);
3280+
v2parts = v2parts.map(Number);
3281+
}
3282+
3283+
for (var i = 0; i < v1parts.length; ++i) {
3284+
if (v2parts.length === i) {
3285+
return 1
3286+
}
3287+
if (v1parts[i] === v2parts[i]) {
3288+
continue
3289+
} else if (v1parts[i] > v2parts[i]) {
3290+
return 1
3291+
} else {
3292+
return -1
3293+
}
3294+
}
3295+
3296+
if (v1parts.length != v2parts.length) {
3297+
return -1
3298+
}
3299+
3300+
return 0
3301+
}
3302+
32523303
function Properties (valDumper) {
32533304
this.valDumper = valDumper;
32543305
}
@@ -3258,8 +3309,10 @@
32583309
}
32593310

32603311
Properties.prototype.dump = function (abs) {
3312+
var debugVersion = this.valDumper.getRequestInfo().$container.data('meta').debugVersion;
32613313
var cfg = {
32623314
attributeOutput : abs.cfgFlags & this.valDumper.objectDumper.PROP_ATTRIBUTE_OUTPUT,
3315+
isDynamicSupport : versionCompare(debugVersion, '3.1') >= 0
32633316
};
32643317
var label = Object.keys(abs.properties).length
32653318
? 'properties'
@@ -3280,7 +3333,8 @@
32803333
forceShow: info.forceShow,
32813334
isDynamic: info.declaredLast === null &&
32823335
info.valueFrom === 'value' &&
3283-
info.objclassName !== 'stdClass',
3336+
cfg.objClassName !== 'stdClass' &&
3337+
cfg.isDynamicSupport,
32843338
isPromoted: info.isPromoted,
32853339
isReadOnly: info.isReadOnly,
32863340
isStatic: info.isStatic,
@@ -3293,12 +3347,7 @@
32933347
$element.addClass(classname);
32943348
}
32953349
});
3296-
if (cfg.attributeOutput && info.attributes && info.attributes.length) {
3297-
$element.attr('data-attributes', JSON.stringify(info.attributes));
3298-
}
3299-
if (info.isInherited || info.isPrivateAncestor) {
3300-
$element.attr('data-inherited-from', info.declaredLast);
3301-
}
3350+
sectionPrototype.addAttribs($element, info, cfg);
33023351
};
33033352

33043353
Properties.prototype.dumpInner = function (name, info, cfg) {
@@ -3405,6 +3454,7 @@
34053454
var objNew = {};
34063455
var sortInfo = [];
34073456
var sortVisOrder = ['public', 'magic', 'magic-read', 'magic-write', 'protected', 'private', 'debug'];
3457+
var vis;
34083458
for (name in obj) {
34093459
if (name === '__construct') {
34103460
sortInfo.push({
@@ -3414,10 +3464,13 @@
34143464
});
34153465
continue
34163466
}
3467+
vis = Array.isArray(obj[name].visibility)
3468+
? obj[name].visibility[0]
3469+
: obj[name].visibility;
34173470
sortInfo.push({
34183471
name: name,
34193472
nameSort: name,
3420-
vis: sortVisOrder.indexOf(obj[name].visibility),
3473+
vis: sortVisOrder.indexOf(vis),
34213474
});
34223475
}
34233476
sortBy = sortBy.split(/[,\s]+/);
@@ -3451,11 +3504,24 @@
34513504
var html = '';
34523505
var strClassname = '';
34533506
var dumpOpts = this.dumper.getDumpOpts();
3507+
var debugVersion;
34543508
try {
3455-
abs = this.mergeInherited(abs);
3509+
if (typeof abs.sort === 'undefined') {
3510+
abs.sort = 'vis name';
3511+
} else if (abs.sort === 'visibility') {
3512+
debugVersion = this.dumper.getRequestInfo().$container.data('meta').debugVersion;
3513+
if (versionCompare(debugVersion, '3.2') === -1) {
3514+
abs.sort = 'vis name';
3515+
}
3516+
}
34563517
if (typeof abs.cfgFlags === 'undefined') {
34573518
abs.cfgFlags = 0x1FFFFFF & ~this.BRIEF;
34583519
}
3520+
abs = this.mergeInherited(abs);
3521+
if (typeof abs.implementsList === 'undefined') {
3522+
// PhpDebugConsole < 3.1
3523+
abs.implementsList = abs.implements;
3524+
}
34593525
strClassname = this.dumpClassname(abs);
34603526
if (abs.isRecursion) {
34613527
return strClassname +
@@ -3556,13 +3622,21 @@
35563622
if (!abs.implementsList.length) {
35573623
return ''
35583624
}
3559-
return '<dt class="constants">implements</dt>' +
3625+
if (typeof abs.interfacesCollapse === 'undefined') {
3626+
// PhpDebugConsole < 3.2
3627+
abs.interfacesCollapse = ['ArrayAccess', 'BackedEnum', 'Countable', 'Iterator', 'IteratorAggregate', 'UnitEnum'];
3628+
}
3629+
return '<dt>implements</dt>' +
35603630
'<dd>' + this.buildImplementsTree(abs.implements, abs.interfacesCollapse) + '</dd>'
35613631
};
35623632

35633633
DumpObject.prototype.dumpInner = function (abs) {
35643634
var self = this;
35653635
var html = this.dumpModifiers(abs);
3636+
if (typeof abs.sectionOrder === 'undefined') {
3637+
// PhpDebugConsole < 3.2
3638+
abs.sectionOrder = ['attributes', 'extends', 'implements', 'constants', 'cases', 'properties', 'methods', 'phpDoc'];
3639+
}
35663640
abs.sectionOrder.forEach(function (sectionName) {
35673641
html += self.sectionDumpers[sectionName](abs);
35683642
});
@@ -3762,6 +3836,10 @@
37623836
var i = 0;
37633837
var inherited;
37643838
var noInherit = ['attributes', 'cases', 'constants', 'methods', 'properties'];
3839+
if (abs.classDefinition) {
3840+
// PhpDebugConsole < 3.2
3841+
abs.inheritsFrom = abs.classDefinition;
3842+
}
37653843
while (abs.inheritsFrom) {
37663844
inherited = this.dumper.getClassDefinition(abs.inheritsFrom);
37673845
if (abs.isRecursion || abs.isExcluded) {
@@ -3780,8 +3858,8 @@
37803858
abs.inheritsFrom = inherited.inheritsFrom;
37813859
}
37823860
for (i = 0, count = noInherit.length; i < count; i++) {
3783-
if (Object.keys(abs[noInherit[i]]).length < 2) {
3784-
continue
3861+
if (typeof abs[noInherit[i]] === 'undefined') {
3862+
abs[noInherit[i]] = {};
37853863
}
37863864
abs[noInherit[i]] = sort(abs[noInherit[i]], abs.sort);
37873865
}
@@ -4608,11 +4686,11 @@
46084686
dumpOpts.postDump = function (val, dumpOpts) {
46094687
var lis = [];
46104688
if (abs.contentType) {
4611-
lis.push('<li>mime type = <span class="t_string">' + abs.contentType + '</span></li>');
4689+
lis.push('<li>mime type = <span class="content-type t_string">' + abs.contentType + '</span></li>');
46124690
}
46134691
lis.push('<li>size = <span class="t_int">' + abs.strlen + '</span></li>');
46144692
lis.push(abs.value.length
4615-
? '<li class="t_string"><span class="binary">' + val + '</span></li>'
4693+
? '<li class="t_string">' + val + '</li>'
46164694
: '<li>Binary data not collected</li>');
46174695
val = '<span class="t_keyword">string</span><span class="text-muted">(binary)</span>' +
46184696
'<ul class="list-unstyled value-container" data-type="' + abs.type + '" data-type-more="binary">' +
@@ -4762,7 +4840,7 @@
47624840
}
47634841
if (tagName) {
47644842
dumpOpts.attribs.class.push('t_' + dumpOpts.type);
4765-
if (dumpOpts.typeMore) {
4843+
if (dumpOpts.typeMore && dumpOpts.typeMore !== 'abstraction') {
47664844
dumpOpts.attribs['data-type-more'] = dumpOpts.typeMore.replace(/\0/g, '');
47674845
}
47684846
$wrap = $$1('<' + tagName + ' />')
@@ -4882,21 +4960,23 @@
48824960
};
48834961

48844962
Dump.prototype.dumpArrayValue = function (key, val, withKey) {
4885-
var classes = ['t_key'];
4963+
var $key = $$1('<span></span>');
4964+
if (withKey === false) {
4965+
return this.dump(val, { tagName: 'li' })
4966+
}
4967+
$key
4968+
.addClass('t_key')
4969+
.html(this.dump(key, {
4970+
tagName : null
4971+
}));
48864972
if (/^\d+$/.test(key)) {
4887-
classes.push('t_int');
4888-
}
4889-
return withKey
4890-
? '\t<li>' +
4891-
this.dump(key, {
4892-
attribs : {
4893-
class: classes
4894-
}
4895-
}) +
4896-
'<span class="t_operator">=&gt;</span>' +
4897-
this.dump(val) +
4898-
'</li>\n'
4899-
: '\t' + this.dump(val, { tagName: 'li' }) + '\n'
4973+
$key.addClass('t_int');
4974+
}
4975+
return '<li>' +
4976+
$key[0].outerHTML +
4977+
'<span class="t_operator">=&gt;</span>' +
4978+
this.dump(val) +
4979+
'</li>'
49004980
};
49014981

49024982
Dump.prototype.dumpBool = function (val) {
@@ -5352,7 +5432,10 @@
53525432
var classDefinition;
53535433
if (isInit) {
53545434
info.$container.data('classDefinitions', {});
5355-
info.$container.data('meta', metaVals);
5435+
info.$container.data('meta', $$1.extend({
5436+
debugVersion: meta.debugVersion,
5437+
requestId: meta.requestId,
5438+
}, metaVals));
53565439
}
53575440
if (meta.channelNameRoot) {
53585441
info.$container.find('.debug').data('channelNameRoot', meta.channelNameRoot);

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)