public function create($sourceUrl, $destinationUrl, $forward = false)
{
if ($this->repository->hasAccess('content', 'urltranslator') !== true) {
throw new UnauthorizedException('content', 'urltranslator');
}
$sourceUrl = $this->cleanUrl($sourceUrl);
$destinationUrl = $this->cleanUrl($destinationUrl);
$spiUrlWildcards = $this->urlWildcardHandler->loadAll();
foreach ($spiUrlWildcards as $wildcard) {
if ($wildcard->sourceUrl === $sourceUrl) {
throw new InvalidArgumentException('$sourceUrl', 'Pattern already exists');
}
}
preg_match_all('(\\*)', $sourceUrl, $patterns);
preg_match_all('(\\{(\\d+)\\})', $destinationUrl, $placeholders);
$patterns = array_map('intval', $patterns[0]);
$placeholders = array_map('intval', $placeholders[1]);
if (!empty($placeholders) && max($placeholders) > count($patterns)) {
throw new ContentValidationException('Placeholders are not matching with wildcards.');
}
$this->repository->beginTransaction();
try {
$spiUrlWildcard = $this->urlWildcardHandler->create($sourceUrl, $destinationUrl, $forward);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
return $this->buildUrlWildcardDomainObject($spiUrlWildcard);
}