From bce2d380aa8eae5ade3ceb25e572eb5826ab991b Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Fri, 27 Mar 2020 13:39:37 +0100 Subject: [PATCH] Replace class_uses_recursive helper with own service method --- src/Services/ClassUses.php | 70 +++++++++++++++++++++++++++++++++++ src/Services/QueueMonitor.php | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/Services/ClassUses.php diff --git a/src/Services/ClassUses.php b/src/Services/ClassUses.php new file mode 100644 index 00000000..eb9cc625 --- /dev/null +++ b/src/Services/ClassUses.php @@ -0,0 +1,70 @@ + $class] as $class) { + $results += self::traitUsesRecursive($class); + } + + return array_unique($results); + } + + /** + * Returns all traits used by a trait and its traits. + * + * @param string $trait + * @return array + */ + public static function traitUsesRecursive($trait) + { + $traits = class_uses($trait); + + foreach ($traits as $trait) { + $traits += self::traitUsesRecursive($trait); + } + + return $traits; + } +} diff --git a/src/Services/QueueMonitor.php b/src/Services/QueueMonitor.php index 7fea476b..e1094fda 100644 --- a/src/Services/QueueMonitor.php +++ b/src/Services/QueueMonitor.php @@ -166,7 +166,7 @@ protected static function jobFinished(JobContract $job, bool $failed = false, $e */ public static function shouldBeMonitored(JobContract $job): bool { - return array_key_exists(IsMonitored::class, class_uses_recursive( + return array_key_exists(IsMonitored::class, ClassUses::classUsesRecursive( $job->resolveName() )); }