Skip to content

Commit

Permalink
Merge pull request #1135 from oat-sa/feat/adf-1802/unique-identifier
Browse files Browse the repository at this point in the history
feat: use get parent classes IDs method to speed up
  • Loading branch information
gabrielfs7 authored Nov 5, 2024
2 parents c0ba756 + 72572e6 commit 813f709
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions core/kernel/classes/class.Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,24 +757,28 @@ public function equals(core_kernel_classes_Resource $resource): bool
}

/**
* Whenever or not the current resource is
* an instance of the specified class
* Whenever or not the current resource is an instance of the specified class
*
* @access public
* @author Joel Bout, <joel.bout@tudor.lu>
* @param Class class
* @return boolean
*/
public function isInstanceOf(core_kernel_classes_Class $class): bool
{
$returnValue = (bool) false;
foreach ($this->getTypes() as $type) {
if ($class->equals($type) || $type->isSubClassOf($class)) {
$returnValue = true;
break;
}
}
return (bool) $returnValue;
return in_array($class->getUri(), $this->getParentClassesIds(), true);
}

public function getRootId(): string
{
$parentClassesIds = $this->getParentClassesIds();

return array_pop($parentClassesIds);
}

/**
* Return the parent class URI of a resource
*/
public function getParentClassId(): ?string
{
return current($this->getParentClassesIds()) ?: null;
}

public function getParentClassesIds(): array
Expand Down

0 comments on commit 813f709

Please sign in to comment.