From d448622ff4e47e136cbc20104a1f6a82f17e860d Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 23 Jun 2022 15:17:33 +1200 Subject: [PATCH] ENH Allow subclasses to be defined for backtrace filtered functions. --- src/Dev/Backtrace.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Dev/Backtrace.php b/src/Dev/Backtrace.php index 1aa6cde74..deae15921 100644 --- a/src/Dev/Backtrace.php +++ b/src/Dev/Backtrace.php @@ -81,9 +81,9 @@ class Backtrace $match = false; if (!empty($frame['class'])) { foreach ($ignoredArgs as $fnSpec) { - if (is_array($fnSpec) && - ('*' == $fnSpec[0] || $frame['class'] == $fnSpec[0]) && - $frame['function'] == $fnSpec[1] + if (is_array($fnSpec) + && self::matchesFilterableClass($frame['class'], $fnSpec[0]) + && $frame['function'] == $fnSpec[1] ) { $match = true; break; @@ -202,4 +202,13 @@ class Backtrace } return $result; } + + /** + * Checks if the filterable class is wildcard, of if the class name is the filterable class, or a subclass of it, + * or implements it. + */ + private static function matchesFilterableClass(string $className, string $filterableClass): bool + { + return $filterableClass === '*' || $className === $filterableClass || is_subclass_of($className, $filterableClass); + } }