protected function getPathSegmentByIdentifier($identifier)
{
if ($this->getUriPattern() === '') {
return rawurlencode($identifier);
}
$objectPathMapping = $this->objectPathMappingRepository->findOneByObjectTypeUriPatternAndIdentifier($this->objectType, $this->getUriPattern(), $identifier);
if ($objectPathMapping !== null) {
return $this->lowerCase ? strtolower($objectPathMapping->getPathSegment()) : $objectPathMapping->getPathSegment();
}
$object = $this->persistenceManager->getObjectByIdentifier($identifier, $this->objectType);
$pathSegment = $uniquePathSegment = $this->createPathSegmentForObject($object);
$pathSegmentLoopCount = 0;
do {
if ($pathSegmentLoopCount++ > 99) {
throw new InfiniteLoopException('No unique path segment could be found after ' . ($pathSegmentLoopCount - 1) . ' iterations.', 1316441798);
}
if ($uniquePathSegment !== '') {
$objectPathMapping = $this->objectPathMappingRepository->findOneByObjectTypeUriPatternAndPathSegment($this->objectType, $this->getUriPattern(), $uniquePathSegment, !$this->lowerCase);
if ($objectPathMapping === null) {
$this->storeObjectPathMapping($uniquePathSegment, $identifier);
break;
}
}
$uniquePathSegment = sprintf('%s-%d', $pathSegment, $pathSegmentLoopCount);
} while (true);
return $this->lowerCase ? strtolower($uniquePathSegment) : $uniquePathSegment;
}