Improve reference tokens transformation

This commit is contained in:
Andrea Marco Sartori 2022-11-28 20:55:25 +10:00
parent 979fdae4ae
commit da5df48779

View File

@ -49,9 +49,10 @@ class Pointer implements ArrayAccess, Stringable
throw PointerException::invalid($this->pointer); throw PointerException::invalid($this->pointer);
} }
$tokens = explode('/', substr($this->pointer, 1)); $tokens = explode('/', $this->pointer);
$referenceTokens = array_map(fn (string $token) => str_replace(['~1', '~0'], ['/', '~'], $token), $tokens);
return array_map(fn (string $token) => str_replace(['~1', '~0'], ['/', '~'], $token), $tokens); return array_slice($referenceTokens, 1);
} }
/** /**
@ -94,17 +95,6 @@ class Pointer implements ArrayAccess, Stringable
return is_int($key) && $this->referenceTokens[$depth] === '-'; return is_int($key) && $this->referenceTokens[$depth] === '-';
} }
/**
* Determine whether the pointer matches the given tree
*
* @param Tree $tree
* @return bool
*/
public function matchesTree(Tree $tree): bool
{
return $this->referenceTokens == $tree->original() || $this->referenceTokens == $tree->wildcarded();
}
/** /**
* Determine whether the pointer includes the given tree * Determine whether the pointer includes the given tree
* *