Skip to content

Commit

Permalink
Create multi-dimensional array instead of fiddling with composed keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Sep 12, 2024
1 parent 9c38466 commit f05c7de
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Registry/ElementRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ public static function getInstance(): AbstractElementRegistry
public function registerElementHandler(string $class): void
{
Assert::subclassOf($class, AbstractElement::class);
$namespace = class::NS;
$className = AbstractElement::getClassName($class);
$key = ($class::NS === null) ? $className : implode(':', [$class::NS, $className]);
$this->registry[$key] = $class;

$this->registry[$namespace][$key] = $class;
}


Expand All @@ -79,11 +80,6 @@ public function getElementHandler(?string $namespace, string $element): ?string
Assert::nullOrValidURI($namespace, InvalidDOMElementException::class);
Assert::validNCName($element, InvalidDOMElementException::class);

$key = ($namespace === null) ? $element : implode(':', [$namespace, $element]);
if (array_key_exists($key, $this->registry) === true) {
return $this->registry[$key];
}

return null;
return $this->registry[$namespace][$element] ?? null;
}
}

0 comments on commit f05c7de

Please sign in to comment.