Skip to content

Commit

Permalink
[ApiBundle] Revert changes in RouteNameResolver and PathPrefixProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Feb 26, 2021
1 parent f40dba3 commit f705b37
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,12 @@ private function returnMatchingRouteName(
}

foreach ($matchingRoutes as $routeName => $route) {
$routePrefix = $this->pathPrefixProvider->getPathPrefix($route->getPath());
$requestPrefix = $this->pathPrefixProvider->getCurrentPrefix();

if ($requestPrefix === '' && strpos($routeName, '_shop_')) {
return $routeName;
}
$routePrefix = $this->pathPrefixProvider->getPathPrefix($route->getPath());

if ($requestPrefix !== null && $routePrefix !== null && $requestPrefix === $routePrefix) {
return $routeName;
}

if ($requestPrefix === null) {
return $routeName;
}
}

throw new InvalidArgumentException(
Expand Down
6 changes: 1 addition & 5 deletions src/Sylius/Bundle/ApiBundle/Provider/PathPrefixProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public function getCurrentPrefix(): ?string
/** @var UserInterface|null $user */
$user = $this->userContext->getUser();

if ($user === null) {
return '';
}

if ($user instanceof ShopUserInterface) {
if ($user === null || $user instanceof ShopUserInterface) {
return PathPrefixes::SHOP_PREFIX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ function it_returns_shop_prefix_if_currently_logged_in_is_shop_user(
$this->getCurrentPrefix()->shouldReturn('shop');
}

function it_returns_empty_string_if_there_is_no_logged_in_user(UserContextInterface $userContext): void
function it_returns_shop_prefix_if_there_is_no_logged_in_user(UserContextInterface $userContext): void
{
$userContext->getUser()->willReturn(null);

$this->getCurrentPrefix()->shouldReturn('');
$this->getCurrentPrefix()->shouldReturn('shop');
}
}

0 comments on commit f705b37

Please sign in to comment.