Skip to content

Commit

Permalink
Merge branch '5.1'
Browse files Browse the repository at this point in the history
* 5.1:
  Removed Redirect entity update bug in RedirectRouter
  • Loading branch information
Kristof Jochmans committed Jan 21, 2019
2 parents a19b322 + f14ddd5 commit 3f6b981
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/Kunstmaan/RedirectBundle/Router/RedirectRouter.php
Expand Up @@ -117,7 +117,9 @@ private function initRoutes()
foreach ($redirects as $redirect) {
// Check for wildcard routing and adjust as required
if ($this->isWildcardRedirect($redirect)) {
$this->calculateWildcardDestination($redirect);
$route = $this->createWildcardRoute($redirect);
} else {
$route = $this->createRoute($redirect);
}

// Only add the route when the domain matches or the domain is empty
Expand All @@ -126,11 +128,7 @@ private function initRoutes()

$this->routeCollection->add(
'_redirect_route_' . $redirect->getId(),
new Route($redirect->getOrigin(), [
'_controller' => 'FrameworkBundle:Redirect:urlRedirect',
'path' => $redirect->getTarget(),
'permanent' => $redirect->isPermanent(),
], [], ['utf8' => $needsUtf8])
$route
);
}
}
Expand Down Expand Up @@ -161,21 +159,42 @@ private function isPathInfoWildcardMatch($matchSegment)

/**
* @param Redirect $redirect
*
* @return Route
*/
private function createRoute(Redirect $redirect)
{
return new Route(
$redirect->getOrigin(), array(
'_controller' => 'FrameworkBundle:Redirect:urlRedirect',
'path' => $redirect->getTarget(),
'permanent' => $redirect->isPermanent(),
));
}

/**
* @param Redirect $redirect
*
* @return Route
*/
private function calculateWildcardDestination(Redirect $redirect)
private function createWildcardRoute(Redirect $redirect)
{
$origin = $redirect->getOrigin();
$target = $redirect->getTarget();
$url = $this->context->getPathInfo();

$redirect->setOrigin($url);

$origin = substr($origin, 0, -1);
$target = substr($target, 0, -1);
$url = str_replace($origin, $target, $url);
$pathInfo = str_replace($origin, $target, $url);

$this->context->setPathInfo($pathInfo);

$this->context->setPathInfo($url);
$redirect->setTarget($url);
return new Route(
$url, array(
'_controller' => 'FrameworkBundle:Redirect:urlRedirect',
'path' => $url,
'permanent' => $redirect->isPermanent(),
));
}

/**
Expand Down

0 comments on commit 3f6b981

Please sign in to comment.