From b9cf804b2a95dfa3d7e794daed914d8409368857 Mon Sep 17 00:00:00 2001 From: Romain 'Maz' BILLOIR Date: Thu, 24 Aug 2023 15:13:41 +0200 Subject: [PATCH] Allows a Children to be extended --- src/HasParent.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/HasParent.php b/src/HasParent.php index 19f3ec6..db984f2 100644 --- a/src/HasParent.php +++ b/src/HasParent.php @@ -138,6 +138,21 @@ protected function getParentClass(): string { static $parentClassName; - return $parentClassName ?: $parentClassName = (new ReflectionClass($this))->getParentClass()->getName(); + if ($parentClassName) { + return $parentClassName; + } else { + $class = new ReflectionClass($this); + + $firstParent = $class->getParentClass(); + while ($parent = $class->getParentClass()) { + if (in_array(\Parental\HasChildren::class, $parent->getTraitNames())) { + return $parent->getName(); + } + + $class = $parent; + } + + return $firstParent; + } } }