Merge branch 'develop' into trunk
This commit is contained in:
commit
2a7cd8bb9f
2 changed files with 40 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ldc/ldccrm",
|
||||
"version": "4.0.4",
|
||||
"version": "4.0.5",
|
||||
"type": "project",
|
||||
"description": "LDC CRM",
|
||||
"license": "MIT",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue