Merge branch 'develop' into trunk

This commit is contained in:
Vincent BRIDIER 2024-10-15 14:13:39 +02:00
commit 2a7cd8bb9f
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
2 changed files with 40 additions and 2 deletions

View file

@ -142,7 +142,7 @@ trait BaseEnum
public function equals(object ...$others): bool
{
foreach ($others as $other) {
if (!\in_array(BaseEnum::class, \class_uses_recursive($other))) {
if (!\in_array(BaseEnum::class, $this->classUsesRecursive($other))) {
throw new \Error(__METHOD__ .
' requires $enum to use ' . BaseEnum::class);
}
@ -269,4 +269,42 @@ trait BaseEnum
} //end if
return $GLOBALS[self::class]['customProps'];
}
/**
* Returns all traits used by a class, its parent classes and trait of their traits.
*
* @param object|string $class
* @return array
*/
private function classUsesRecursive($class)
{
if (is_object($class)) {
$class = get_class($class);
}
$results = [];
foreach (array_reverse(class_parents($class) ?: []) + [$class => $class] as $class) {
$results += $this->traitUsesRecursive($class);
}
return array_unique($results);
}
/**
* Returns all traits used by a trait and its traits.
*
* @param object|string $trait
* @return array
*/
private function traitUsesRecursive($trait)
{
$traits = class_uses($trait) ?: [];
foreach ($traits as $trait) {
$traits += $this->traitUsesRecursive($trait);
}
return $traits;
}
}

View file

@ -1,6 +1,6 @@
{
"name": "ldc/ldccrm",
"version": "4.0.4",
"version": "4.0.5",
"type": "project",
"description": "LDC CRM",
"license": "MIT",