Skip to content

Commit

Permalink
Prevent circular reference in use elements
Browse files Browse the repository at this point in the history
  • Loading branch information
bsweeney committed Dec 11, 2023
1 parent 4b43073 commit 88163cb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Svg/Tag/UseTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ class UseTag extends AbstractTag
protected $y = 0;
protected $width;
protected $height;
protected $instances = 0;

/** @var AbstractTag */
protected $reference;

protected function before($attributes)
{
$this->instances++;
if ($this->instances > 1) {
//TODO: log circular reference error state
return;
}

if (isset($attributes['x'])) {
$this->x = $attributes['x'];
}
Expand Down Expand Up @@ -52,6 +59,9 @@ protected function before($attributes)
}

protected function after() {
if ($this->instances > 0) {
return;
}
parent::after();

if ($this->reference) {
Expand All @@ -63,6 +73,11 @@ protected function after() {

public function handle($attributes)
{
if ($this->instances > 1) {
//TODO: log circular reference error state
return;
}

parent::handle($attributes);

if (!$this->reference) {
Expand All @@ -87,6 +102,11 @@ public function handle($attributes)

public function handleEnd()
{
$this->instances--;
if ($this->instances > 0) {
return;
}

parent::handleEnd();

if (!$this->reference) {
Expand Down

0 comments on commit 88163cb

Please sign in to comment.