Skip to content

Commit 54f4752

Browse files
committed
StringUtil::prettyJson() - handle JSON_ERROR_INVALID_PROPERTY_NAME error
ObjectAbstraction unserialize backwards compatibility enhancement
1 parent af6c5e3 commit 54f4752

33 files changed

Lines changed: 482 additions & 74 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Log, Debug, Inspect
3131
* errors (even fatal) are captured / logged / displayed
3232
* optionally send error notices via email (throttled as to not to send out a flood of emails)
3333
* password protected
34-
* send debug log via email
34+
* send debug log via email / Discord / Slack / MS Teams
3535

3636
![Screenshot of PHPDebugConsole's Output](http://www.bradkent.com/images/php/screenshot_1.4.png)
3737

@@ -59,7 +59,7 @@ See <http://www.bradkent.com/php/debug>
5959

6060
## PSR-3 Usage
6161

62-
PHPDebugConsole includes a [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) implementation (which can be used as a [monolog](https://github.com/Seldaek/monolog) PSR handler). If you're using a application or library that uses these standards, drop PHPDebugConsole right in.
62+
PHPDebugConsole includes a [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) implementation (which can be used as a [monolog](https://github.com/Seldaek/monolog) PSR handler). If you're using an application or library that uses these standards, drop PHPDebugConsole right in.
6363

6464
(this library includes neither psr/log or monolog/monolog. Include separately if needed.)
6565

src/Debug/Abstraction/AbstractObject.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class AbstractObject extends AbstractComponent
175175
'cfgFlags' => 0, // will default to everything sans "brief" & 'virtualValueCollect'
176176
'className' => '',
177177
'debugMethod' => '',
178-
'interfacesCollapse' => array(), // cfg.interfacesCollapse
178+
'interfacesCollapse' => array(), // cfg.interfacesCollapse (intersected with reflector::getInterfaceNames())
179179
'isExcluded' => false, // don't exclude if we're debugging directly
180180
'isLazy' => false,
181181
'isMaxDepth' => false,
@@ -211,6 +211,9 @@ public function __construct(Abstracter $abstracter)
211211
$subscriber = new Subscriber($this);
212212
$abstracter->debug->eventManager->addSubscriberInterface($subscriber);
213213
}
214+
215+
self::$values['sectionOrder'] = $abstracter->getCfg('objectSectionOrder');
216+
self::$values['sort'] = $abstracter->getCfg('objectSort');
214217
}
215218

216219
/**
@@ -326,8 +329,7 @@ private function doAbstraction(ObjectAbstraction $abs)
326329
*/
327330
protected function getAbstractionValues(ReflectionClass $reflector, $obj, $method = null, array $hist = array())
328331
{
329-
return \array_merge(
330-
self::$values,
332+
return static::buildValues(\array_merge(
331333
array(
332334
'cfgFlags' => $this->getCfgFlags($reflector),
333335
'className' => $this->helper->getClassName($reflector),
@@ -351,7 +353,7 @@ protected function getAbstractionValues(ReflectionClass $reflector, $obj, $metho
351353
'propertyOverrideValues' => array(),
352354
'reflector' => $reflector,
353355
)
354-
);
356+
));
355357
}
356358

357359
/**

src/Debug/Abstraction/AbstractString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ private function getMaxLen($cat, $strlen)
326326
$stringMaxLen = $this->cfg['brief']
327327
? $this->cfg['stringMaxLenBrief']
328328
: $this->cfg['stringMaxLen'];
329-
$maxLen = \array_key_exists($cat, $stringMaxLen)
329+
$maxLen = \array_key_exists($cat, $stringMaxLen)
330330
? $stringMaxLen[$cat]
331331
: $stringMaxLen['other'];
332332

src/Debug/Abstraction/Object/Abstraction.php

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
use bdk\Debug\Abstraction\Abstracter;
1616
use bdk\Debug\Abstraction\Abstraction as BaseAbstraction;
17+
use bdk\Debug\Abstraction\AbstractObject;
18+
use bdk\Debug\Abstraction\Object\Constants;
19+
use bdk\Debug\Abstraction\Object\Definition;
20+
use bdk\Debug\Abstraction\Object\MethodParams;
21+
use bdk\Debug\Abstraction\Object\Methods;
22+
use bdk\Debug\Abstraction\Object\Properties;
1723
use bdk\Debug\Abstraction\Type;
1824
use bdk\Debug\Utility\ArrayUtil;
1925
use bdk\PubSub\ValueStore;
@@ -80,9 +86,8 @@ public function __toString()
8086
*/
8187
public function __unserialize(array $data)
8288
{
83-
$this->inherited = isset($data['inherited'])
84-
? $data['inherited']
85-
: new ValueStore();
89+
$data = $this->unserializeDataPrep($data);
90+
$this->inherited = $data['inherited'];
8691
unset($data['inherited']);
8792
$this->values = $data;
8893
}
@@ -209,11 +214,42 @@ public function offsetExists($key)
209214
#[\ReturnTypeWillChange]
210215
public function &offsetGet($key)
211216
{
217+
if ($key === 'inherited') {
218+
return $this->inherited;
219+
}
212220
// update our local and return it as a reference
213221
$this->values[$key] = $this->getCombinedValue($key);
214222
return $this->values[$key];
215223
}
216224

225+
/**
226+
* Make sure property and method info contains expected keys
227+
*
228+
* @param \ArrayAccess $data Either instance data or inherited data
229+
*
230+
* @return array
231+
*/
232+
public static function unserializeBuildValues($data)
233+
{
234+
$data['constants'] = \array_map(static function (array $info) {
235+
return Constants::buildValues($info);
236+
}, $data['constants']);
237+
238+
$data['properties'] = \array_map(static function (array $info) {
239+
return Properties::buildValues($info);
240+
}, $data['properties']);
241+
242+
$data['methods'] = \array_map(static function (array $info) {
243+
$info = Methods::buildValues($info);
244+
$info['params'] = \array_map(static function (array $paramInfo) {
245+
return MethodParams::buildValues($paramInfo);
246+
}, $info['params']);
247+
return $info;
248+
}, $data['methods']);
249+
250+
return $data;
251+
}
252+
217253
/**
218254
* Get merged class & instance value
219255
*
@@ -299,4 +335,52 @@ protected function sortData(array $array)
299335
}
300336
return $sortData;
301337
}
338+
339+
/**
340+
* Ensure data contains all expected keys
341+
*
342+
* @param array $data Serialized data
343+
*
344+
* @return array
345+
*/
346+
private function unserializeDataPrep(array $data)
347+
{
348+
if (empty($data['definition'])) {
349+
// we are instance values
350+
$data = AbstractObject::buildValues($data);
351+
}
352+
353+
if (empty($data['className'])) {
354+
unset($data['className']);
355+
}
356+
357+
$data['inherited'] = $this->unserializeDataInherited($data);
358+
359+
return $data;
360+
}
361+
362+
/**
363+
* Get inherited ValueStore
364+
*
365+
* @param array $data Serialized data
366+
*
367+
* @return ValueStore
368+
*/
369+
private function unserializeDataInherited(array &$data)
370+
{
371+
if (isset($data['inherited'])) {
372+
$inherited = $data['inherited'];
373+
unset($data['inherited']);
374+
return $this->unserializeBuildValues($inherited);
375+
}
376+
if (isset($data['classDefinition'])) {
377+
// maintain backwards compatibility - v3.1 used 'classDefinition'
378+
$inherited = $data['classDefinition'];
379+
unset($data['classDefinition']);
380+
return $this->unserializeBuildValues($inherited);
381+
}
382+
// maintain backwards compatibility - v3.0 did not inherit
383+
$data = $this->unserializeBuildValues($data);
384+
return new ValueStore(AbstractObject::buildValues(Definition::buildValues()));
385+
}
302386
}

src/Debug/Abstraction/Object/Definition.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,7 @@ public function getValueStoreDefault()
151151
if ($this->default) {
152152
return $this->default;
153153
}
154-
$values = self::buildValues(array(
155-
'isExcluded' => false,
156-
'sectionOrder' => $this->object->getCfg('objectSectionOrder'),
157-
'sort' => $this->object->getCfg('objectSort'),
158-
'stringified' => null,
159-
'traverseValues' => array(),
160-
'viaDebugInfo' => false,
161-
));
154+
$values = $this->object->buildValues(static::buildValues());
162155
$classValueStore = new ValueStore($values);
163156
$this->default = $classValueStore;
164157
$this->debug->data->set([

src/Debug/Collector/Doctrine/Statement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING): void
7070
public function execute($params = null): ResultInterface
7171
{
7272
$info = new StatementInfo($this->sql, $this->params, $this->types);
73-
$result = parent::execute();
73+
$result = parent::execute();
7474

7575
$exception = null;
7676
$result = false;

src/Debug/ConfigNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private function normalizePathFind($path)
218218
return $path;
219219
}
220220
$pathNew = $this->debug->arrayUtil->searchRecursive($path[0], $this->configKeys, true);
221-
$pathNew = $pathNew
221+
$pathNew = $pathNew
222222
? $pathNew
223223
: \array_merge(['debug'], $path);
224224
if (\end($pathNew) !== \end($path)) {

src/Debug/Dump/AbstractValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ protected function parseIdentifier($val, $what = 'className')
393393
$parts['classname'] = $val[0];
394394
$parts['operator'] = '::';
395395
$parts['name'] = $val[1];
396-
} elseif (\preg_match('/^(.+)(::|->)(.+)$/', $val, $matches)) {
396+
} elseif (\preg_match('/^(.+)(::|->)(.+)$/', (string) $val, $matches)) {
397397
$parts['classname'] = $matches[1];
398398
$parts['operator'] = $matches[2];
399399
$parts['name'] = $matches[3];

src/Debug/Dump/Html/HtmlString.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private function dumpAbs(Abstraction $abs)
189189
$this->valDumper->optionSet('visualWhiteSpace', false);
190190
$this->valDumper->optionSet('postDump', $this->buildPrettifiedPostDump($abs));
191191
}
192-
$val = $this->doDump((string) $abs);
192+
$val = $this->doDump($abs);
193193
$strLenDiff = $abs['strlen'] - $abs['strlenValue'];
194194
if ($strLenDiff) {
195195
$val .= '<span class="maxlen">&hellip; ' . $this->debug->i18n->trans('string.more-bytes', array('bytes' => $strLenDiff)) . '</span>';
@@ -285,6 +285,7 @@ private function buildPrettifiedPostDump(Abstraction $abs)
285285
private function doDump($val)
286286
{
287287
$opts = $this->valDumper->optionGet();
288+
$val = (string) $val;
288289
if ($opts['sanitize']) {
289290
$val = \htmlspecialchars($val);
290291
}

src/Debug/Dump/Html/HtmlStringBinary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function dumpPost(Abstraction $abs, $tagName)
130130
$lis[] = $dumped
131131
? '<li class="t_string">' . $dumped . '</li>'
132132
: '<li>' . $this->debug->i18n->trans('string.binary-not-collected') . '</li>';
133-
$wrapped = '<span class="t_keyword">string</span><span class="text-muted">(binary)</span>' . "\n"
133+
$wrapped = '<span class="t_keyword">string</span><span class="text-muted">(binary)</span>' . "\n"
134134
. $this->debug->html->buildTag(
135135
'ul',
136136
\array_filter(array(

0 commit comments

Comments
 (0)