Skip to content

Commit c4e52d9

Browse files
committed
update ErrorHandler @Version tag / update ErrorHandler/Error
1 parent 5a2e572 commit c4e52d9

8 files changed

Lines changed: 74 additions & 55 deletions

File tree

src/ErrorHandler/AbstractComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Brad Kent <bkfake-github@yahoo.com>
66
* @license http://opensource.org/licenses/MIT MIT
77
* @copyright 2014-2022 Brad Kent
8-
* @version v3.4
8+
* @version v3.2
99
*/
1010

1111
namespace bdk\ErrorHandler;

src/ErrorHandler/AbstractErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Brad Kent <bkfake-github@yahoo.com>
66
* @license http://opensource.org/licenses/MIT MIT
77
* @copyright 2014-2022 Brad Kent
8-
* @version v3.4
8+
* @version v3.2
99
*/
1010

1111
namespace bdk\ErrorHandler;

src/ErrorHandler/Error.php

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Brad Kent <bkfake-github@yahoo.com>
66
* @license http://opensource.org/licenses/MIT MIT
77
* @copyright 2014-2022 Brad Kent
8-
* @version v3.4
8+
* @version v3.2
99
*/
1010

1111
namespace bdk\ErrorHandler;
@@ -102,18 +102,9 @@ class Error extends Event
102102
*/
103103
public function __construct(ErrorHandler $errHandler, array $values)
104104
{
105-
$this->assertValues($values);
106105
$this->subject = $errHandler;
107-
$this->values = \array_merge(
108-
$this->values,
109-
$this->defaultValues($values),
110-
$values,
111-
array(
112-
'message' => $this->isHtml()
113-
? \str_replace('<a ', '<a target="phpRef" ', $this->values['message'])
114-
: $this->values['message'],
115-
)
116-
);
106+
$this->assertValues($values);
107+
$this->setValues($values);
117108
unset($this->values['vars']['GLOBALS']);
118109
$errorCaller = $errHandler->get('errorCaller');
119110
if ($errorCaller) {
@@ -265,6 +256,38 @@ public function &offsetGet($key)
265256
return parent::offsetGet($key);
266257
}
267258

259+
/**
260+
* {@inheritDoc}
261+
*/
262+
public function setValues(array $values = array())
263+
{
264+
$this->setValuesInit($values);
265+
$errType = $values['type'];
266+
$hash = $this->hash($values);
267+
$prevOccurance = $this->subject->get('error', $hash);
268+
$isSuppressed = $this->isSuppressed($prevOccurance);
269+
$this->values = \array_merge(
270+
$this->values,
271+
array(
272+
'continueToNormal' => $this->setContinueToNormal($isSuppressed, $prevOccurance === null),
273+
'continueToPrevHandler' => $this->subject->getCfg('continueToPrevHandler'),
274+
'throw' => $this->isFatal() === false && ($errType & $this->subject->getCfg('errorThrow')) === $errType,
275+
),
276+
$values,
277+
array(
278+
'category' => $this->values['category'],
279+
'hash' => $hash,
280+
'isFirstOccur' => !$prevOccurance,
281+
'isHtml' => $this->isHtml(),
282+
'isSuppressed' => $isSuppressed,
283+
'typeStr' => self::$errTypes[$errType],
284+
'message' => $this->isHtml()
285+
? \str_replace('<a ', '<a target="phpRef" ', $this->values['message'])
286+
: $this->values['message'],
287+
)
288+
);
289+
}
290+
268291
/**
269292
* Get human-friendly error type
270293
*
@@ -293,47 +316,17 @@ private function assertValues($values)
293316
$keysMustHave = array('type', 'message', 'file', 'line');
294317
$keys = \array_keys($values);
295318
if (\array_intersect($keysMustHave, $keys) !== $keysMustHave) {
296-
throw new InvalidArgumentException('Error values must include: ' . \implode(', ', $keysMustHave));
319+
throw new InvalidArgumentException('Error values must include: type, message, file, & line');
297320
}
298-
if (\array_key_exists($values['type'], self::$errTypes) === false) {
321+
$validTypes = \array_diff_key(self::$errTypes, \array_flip(array(E_ALL)));
322+
if (\array_key_exists($values['type'], $validTypes) === false) {
299323
throw new InvalidArgumentException('invalid error type specified');
300324
}
301325
if (\array_key_exists('vars', $values) && \is_array($values['vars']) === false) {
302326
throw new InvalidArgumentException('Error vars must be an array');
303327
}
304328
}
305329

306-
/**
307-
* Get default values
308-
*
309-
* @param array $values Initial / primary values
310-
*
311-
* @return array
312-
*/
313-
private function defaultValues($values)
314-
{
315-
$this->values = \array_merge(
316-
$this->values,
317-
$values
318-
);
319-
$errType = $this->values['type'];
320-
$hash = $this->hash();
321-
$prevOccurance = $this->subject->get('error', $hash);
322-
$isSuppressed = $this->isSuppressed($errType, $prevOccurance);
323-
return array(
324-
'category' => $this->getCategory($errType),
325-
'continueToNormal' => $this->setContinueToNormal($isSuppressed, $prevOccurance === null),
326-
'continueToPrevHandler' => $this->subject->getCfg('continueToPrevHandler'),
327-
'exception' => $this->subject->get('uncaughtException'), // non-null if error is uncaught-exception
328-
'hash' => $hash,
329-
'isFirstOccur' => !$prevOccurance,
330-
'isHtml' => $this->isHtml(),
331-
'isSuppressed' => $isSuppressed,
332-
'throw' => $this->isFatal() === false && ($errType & $this->subject->getCfg('errorThrow')) === $errType,
333-
'typeStr' => self::$errTypes[$errType],
334-
);
335-
}
336-
337330
/**
338331
* Generate hash used to uniquely identify this error
339332
*
@@ -389,17 +382,17 @@ private function isHtml()
389382
/**
390383
* Get initial `isSuppressed` value
391384
*
392-
* @param int $errType The level of the error
393385
* @param self|null $prevOccurance previous occurrence of current error
394386
*
395387
* @return bool
396388
*/
397-
private function isSuppressed($errType, self $prevOccurance = null)
389+
private function isSuppressed($prevOccurance = null)
398390
{
399391
if ($prevOccurance && !$prevOccurance['isSuppressed']) {
400392
// if any instance of this error was not supprssed, reflect that
401393
return false;
402394
}
395+
$errType = $this->values['type'];
403396
if (($this->subject->getCfg('suppressNever') & $errType) === $errType) {
404397
// never suppress tyis type
405398
return false;
@@ -432,4 +425,25 @@ private function setContinueToNormal($isSuppressed, $isFirstOccurance)
432425
}
433426
return $continueToNormal;
434427
}
428+
429+
/**
430+
* Set the core values (type, message, file, line)
431+
*
432+
* @param array $values values being set
433+
*
434+
* @return void
435+
*/
436+
private function setValuesInit($values)
437+
{
438+
$errType = $values['type'];
439+
$category = $this->getCategory($errType);
440+
$this->values = \array_merge(
441+
$this->values,
442+
array(
443+
'category' => $category,
444+
'exception' => $this->subject->get('uncaughtException'), // non-null if error is uncaught-exception
445+
),
446+
$values
447+
);
448+
}
435449
}

src/ErrorHandler/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Brad Kent <bkfake-github@yahoo.com>
66
* @license http://opensource.org/licenses/MIT MIT
77
* @copyright 2014-2022 Brad Kent
8-
* @version v3.4
8+
* @version v3.2
99
*/
1010

1111
namespace bdk;

src/ErrorHandler/Plugin/Emailer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Brad Kent <bkfake-github@yahoo.com>
66
* @license http://opensource.org/licenses/MIT MIT
77
* @copyright 2014-2022 Brad Kent
8-
* @version v3.4
8+
* @version v3.2
99
*/
1010

1111
namespace bdk\ErrorHandler\Plugin;

src/ErrorHandler/Plugin/Stats.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Brad Kent <bkfake-github@yahoo.com>
66
* @license http://opensource.org/licenses/MIT MIT
77
* @copyright 2014-2022 Brad Kent
8-
* @version v3.4
8+
* @version v3.2
99
*/
1010

1111
namespace bdk\ErrorHandler\Plugin;

src/ErrorHandler/Plugin/StatsStoreFile.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Brad Kent <bkfake-github@yahoo.com>
66
* @license http://opensource.org/licenses/MIT MIT
77
* @copyright 2014-2022 Brad Kent
8-
* @version v3.4
8+
* @version v3.2
99
*/
1010

1111
namespace bdk\ErrorHandler\Plugin;
@@ -143,7 +143,12 @@ protected function dataWrite()
143143
}
144144
}
145145
if ($return === false) {
146-
\error_log(__METHOD__ . ': error writing data');
146+
\error_log(\sprintf(
147+
__METHOD__ . ': error writing data %s',
148+
$this->cfg['errorStatsFile']
149+
? 'to ' . $this->cfg['errorStatsFile']
150+
: '(no errorStatsFile specified)'
151+
));
147152
}
148153
return $return;
149154
}

src/ErrorHandler/Plugin/StatsStoreInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Brad Kent <bkfake-github@yahoo.com>
66
* @license http://opensource.org/licenses/MIT MIT
77
* @copyright 2014-2022 Brad Kent
8-
* @version v3.4
8+
* @version v3.2
99
*/
1010

1111
namespace bdk\ErrorHandler\Plugin;

0 commit comments

Comments
 (0)