public findOneByObjectTypeUriPatternAndPathSegment ( string $objectType, string $uriPattern, string $pathSegment, boolean $caseSensitive = false ) : |
||
$objectType | string | the object type of the ObjectPathMapping object |
$uriPattern | string | the URI pattern of the ObjectPathMapping object |
$pathSegment | string | the URI path segment of the ObjectPathMapping object |
$caseSensitive | boolean | whether the path segment lookup should be done case-sensitive |
return |
/** * Generates a unique string for the given identifier according to $this->uriPattern. * If no UriPattern is set, the path segment is equal to the (URL-encoded) $identifier - otherwise a matching * ObjectPathMapping is fetched from persistence. * If no ObjectPathMapping exists for the given identifier, a new ObjectPathMapping is created. * * @param string $identifier the technical identifier of the object * @return string|integer the resolved path segment(s) * @throws InfiniteLoopException if no unique path segment could be found after 100 iterations */ 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; }