Skip to content

Commit dfa2bb8

Browse files
committed
LogRequest & LogResponse no longer create channel if not logging
Update UnserializeLogTest
1 parent 3a1bd94 commit dfa2bb8

27 files changed

Lines changed: 1039 additions & 925 deletions

src/Debug/Abstraction/AbstractObject.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class AbstractObject extends AbstractComponent
182182
'keys' => array(),
183183
// methods may be populated with __toString info, or methods with staticVars
184184
'properties' => array(),
185-
'scopeClass' => '',
185+
'scopeClass' => null,
186186
'sectionOrder' => array(), // cfg.objectSectionOrder
187187
'sort' => '', // cfg.objectSort
188188
'stringified' => null,
@@ -260,7 +260,9 @@ public static function buildValues(array $values = array())
260260
return $carry | $val;
261261
}, 0) & ~self::BRIEF & ~self::PROP_VIRTUAL_VALUE_COLLECT;
262262
}
263-
return \array_merge(self::$values, $values);
263+
$values = \array_merge(self::$values, $values);
264+
\ksort($values);
265+
return $values;
264266
}
265267

266268
/**

src/Debug/Abstraction/Object/AbstractInheritable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public function __construct(AbstractObject $abstractObject)
4949
*/
5050
public static function buildValues(array $values = array())
5151
{
52-
return \array_merge(static::$values, $values);
52+
$values = \array_merge(static::$values, $values);
53+
\ksort($values);
54+
return $values;
5355
}
5456

5557
/**

src/Debug/Abstraction/Object/Abstraction.php

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
use bdk\Debug\Abstraction\Abstracter;
1414
use bdk\Debug\Abstraction\Abstraction as BaseAbstraction;
1515
use bdk\Debug\Abstraction\AbstractObject;
16-
use bdk\Debug\Abstraction\Object\Constants;
1716
use bdk\Debug\Abstraction\Object\Definition;
18-
use bdk\Debug\Abstraction\Object\MethodParams;
19-
use bdk\Debug\Abstraction\Object\Methods;
20-
use bdk\Debug\Abstraction\Object\Properties;
2117
use bdk\Debug\Abstraction\Type;
2218
use bdk\Debug\Utility\ArrayUtil;
2319
use bdk\PubSub\ValueStore;
@@ -84,7 +80,7 @@ public function __toString()
8480
*/
8581
public function __unserialize(array $data)
8682
{
87-
$data = $this->unserializeDataPrep($data);
83+
$data['inherited'] = $this->unserializeDataInherited($data);
8884
$this->inherited = $data['inherited'];
8985
unset($data['inherited']);
9086
$this->values = $data;
@@ -136,8 +132,7 @@ public function jsonSerialize()
136132
public function getInheritedValues()
137133
{
138134
$values = $this->inherited->getValues();
139-
unset($values['cfgFlags']);
140-
unset($values['__isUsed']);
135+
unset($values['__isUsed']); // don't inherit __isUsed
141136
return $values;
142137
}
143138

@@ -233,34 +228,6 @@ public function &offsetGet($key)
233228
return $this->values[$key];
234229
}
235230

236-
/**
237-
* Make sure property and method info contains expected keys
238-
*
239-
* @param \ArrayAccess $data Either instance data or inherited data
240-
*
241-
* @return array
242-
*/
243-
public static function unserializeBuildValues($data)
244-
{
245-
$data['constants'] = \array_map(static function (array $info) {
246-
return Constants::buildValues($info);
247-
}, $data['constants']);
248-
249-
$data['properties'] = \array_map(static function (array $info) {
250-
return Properties::buildValues($info);
251-
}, $data['properties']);
252-
253-
$data['methods'] = \array_map(static function (array $info) {
254-
$info = Methods::buildValues($info);
255-
$info['params'] = \array_map(static function (array $paramInfo) {
256-
return MethodParams::buildValues($paramInfo);
257-
}, $info['params']);
258-
return $info;
259-
}, $data['methods']);
260-
261-
return $data;
262-
}
263-
264231
/**
265232
* Get merged class & instance value
266233
*
@@ -273,7 +240,7 @@ private function getCombinedValue($key)
273240
$value = isset($this->values[$key])
274241
? $this->values[$key]
275242
: null;
276-
if (\in_array($key, self::$keysTemp, true)) {
243+
if (\in_array($key, self::$keysTemp, true) || $key === '__isUsed') {
277244
return $value;
278245
}
279246
$classVal = $this->inheritValue($key)
@@ -347,29 +314,6 @@ protected function sortData(array $array)
347314
return $sortData;
348315
}
349316

350-
/**
351-
* Ensure data contains all expected keys
352-
*
353-
* @param array $data Serialized data
354-
*
355-
* @return array
356-
*/
357-
private function unserializeDataPrep(array $data)
358-
{
359-
if (empty($data['definition'])) {
360-
// we are instance values
361-
$data = AbstractObject::buildValues($data);
362-
}
363-
364-
if (empty($data['className'])) {
365-
unset($data['className']);
366-
}
367-
368-
$data['inherited'] = $this->unserializeDataInherited($data);
369-
370-
return $data;
371-
}
372-
373317
/**
374318
* Get inherited ValueStore
375319
*
@@ -382,16 +326,14 @@ private function unserializeDataInherited(array &$data)
382326
if (isset($data['inherited'])) {
383327
$inherited = $data['inherited'];
384328
unset($data['inherited']);
385-
return $this->unserializeBuildValues($inherited);
329+
return $inherited;
386330
}
387331
if (isset($data['classDefinition'])) {
388332
// maintain backwards compatibility - v3.1 used 'classDefinition'
389333
$inherited = $data['classDefinition'];
390334
unset($data['classDefinition']);
391-
return $this->unserializeBuildValues($inherited);
335+
return $inherited;
392336
}
393-
// maintain backwards compatibility - v3.0 did not inherit
394-
$data = $this->unserializeBuildValues($data);
395337
return new ValueStore(AbstractObject::buildValues(Definition::buildValues()));
396338
}
397339
}

src/Debug/Abstraction/Object/Definition.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public function __construct(AbstractObject $abstractObject)
105105
*/
106106
public static function buildValues(array $values = array())
107107
{
108-
return \array_merge(self::$values, $values);
108+
$values = \array_merge(self::$values, $values);
109+
\ksort($values);
110+
return $values;
109111
}
110112

111113
/**

src/Debug/Abstraction/Object/MethodParams.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public function __construct(AbstractObject $abstractObject)
6969
*/
7070
public static function buildValues(array $values = array())
7171
{
72-
return \array_merge(static::$baseParamInfo, $values);
72+
$values = \array_merge(static::$baseParamInfo, $values);
73+
\ksort($values);
74+
return $values;
7375
}
7476

7577
/**

src/Debug/Abstraction/Object/Subscriber.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,12 @@ private function onStartTable(ObjectAbstraction $abs)
304304
$debug = $this->abstractObject->debug;
305305
$this->isAbstractingTable = true;
306306
$debug->eventManager->subscribe(Debug::EVENT_OBJ_ABSTRACT_END, [$this, 'tableCellValueAbstracter']);
307-
$values = $obj->jsonSerialize();
308-
$values = $debug->abstracter->crate($values, $abs['debugMethod'], $abs['hist']);
309-
$values['type'] = Type::TYPE_TABLE;
307+
try {
308+
$values = $obj->jsonSerialize();
309+
$values = $debug->abstracter->crate($values, $abs['debugMethod'], $abs['hist']);
310+
} catch (Exception $e) {
311+
$values = array();
312+
}
310313
$debug->eventManager->unsubscribe(Debug::EVENT_OBJ_ABSTRACT_END, [$this, 'tableCellValueAbstracter']);
311314
$this->isAbstractingTable = false;
312315
$abs['unstructuredValue'] = new Abstraction(Type::TYPE_TABLE, $values);

src/Debug/Plugin/LogRequest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ public function getSubscriptions()
5050
*/
5151
public function onBootstrap(Event $event)
5252
{
53-
$this->debug = $event->getSubject()->getChannel($this->cfg['channelKey'], $this->cfg['channelOptions']);
54-
$collectWas = $this->debug->setCfg('collect', true);
53+
$this->debug = $event->getSubject();
5554
$this->logRequest();
56-
$this->debug->setCfg('collect', $collectWas, Debug::CONFIG_NO_RETURN);
5755
}
5856

5957
/**
@@ -66,6 +64,8 @@ public function logRequest()
6664
if ($this->testLogRequest() === false) {
6765
return;
6866
}
67+
$this->debug = $this->debug->rootInstance->getChannel($this->cfg['channelKey'], $this->cfg['channelOptions']);
68+
$collectWas = $this->debug->setCfg('collect', true);
6969
$this->debug->log(
7070
$this->debug->i18n->trans('request'),
7171
$this->debug->meta(array(
@@ -87,6 +87,7 @@ public function logRequest()
8787
$this->logRequestCookies();
8888
$this->logPostOrInput();
8989
$this->logFiles();
90+
$this->debug->setCfg('collect', $collectWas, Debug::CONFIG_NO_RETURN);
9091
}
9192

9293
/**

src/Debug/Plugin/LogResponse.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function getSubscriptions()
5555
*/
5656
public function onBootstrap(Event $event)
5757
{
58-
$this->debug = $event->getSubject()->getChannel($this->cfg['channelKey'], $this->cfg['channelOptions']);
58+
// logResponse will update to request/response channel
59+
$this->debug = $event->getSubject();
5960
}
6061

6162
/**
@@ -97,6 +98,7 @@ public function logResponse()
9798
if ($this->debug->rootInstance->getCfg('logResponse', Debug::CONFIG_DEBUG) === false) {
9899
return;
99100
}
101+
$this->debug = $this->debug->rootInstance->getChannel($this->cfg['channelKey'], $this->cfg['channelOptions']);
100102
$this->debug->log(
101103
$this->debug->i18n->trans('response'),
102104
$this->debug->meta(array(

0 commit comments

Comments
 (0)