private function getTruncatedPath($segment, $path)
{
if ($path === $segment) {
// Segment and path are same; return empty string
return '';
}
$segmentLength = strlen($segment);
if (strlen($path) > $segmentLength) {
// Strip segment from start of path
return substr($path, $segmentLength);
}
if ('/' === substr($segment, -1)) {
// Re-try by submitting with / stripped from end of segment
return $this->getTruncatedPath(rtrim($segment, '/'), $path);
}
// Segment is longer than path. There's an issue
throw new RuntimeException('Layer and request path have gone out of sync');
}