Skip to content

Commit

Permalink
Address #50946 (review)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatTheCat committed Oct 7, 2023
1 parent 65f4a67 commit 17d1964
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->createFirewalls($config, $container);

if ($container::willBeAvailable('symfony/routing', ContainerLoader::class, ['symfony/security-bundle'])) {
$this->createLogoutPathsParameter($config['firewalls'] ?? [], $container);
$this->createLogoutUrisParameter($config['firewalls'] ?? [], $container);
} else {
$container->removeDefinition('security.route_loader.logout');
}
Expand Down Expand Up @@ -1100,15 +1100,19 @@ private function getSortedFactories(): array
return $this->sortedFactories;
}

private function createLogoutPathsParameter(array $firewallsConfig, ContainerBuilder $container): void
private function createLogoutUrisParameter(array $firewallsConfig, ContainerBuilder $container): void
{
$logoutPaths = [];
$logoutUris = [];
foreach ($firewallsConfig as $name => $config) {
if ($logoutPath = $config['logout']['path'] ?? null) {
$logoutPaths[$name] = $logoutPath;
if (!$logoutPath = $config['logout']['path'] ?? null) {
continue;
}

if ('/' === $logoutPath[0]) {
$logoutUris[$name] = $logoutPath;
}
}

$container->setParameter('security.logout_paths', $logoutPaths);
$container->setParameter('security.logout_uris', $logoutUris);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@

->set('security.route_loader.logout', LogoutRouteLoader::class)
->args([
'%security.logout_paths%',
'security.logout_paths',
'%security.logout_uris%',
'security.logout_uris',
])
->tag('routing.route_loader')

Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Bundle/SecurityBundle/Routing/LogoutRouteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

class LogoutRouteLoader
final class LogoutRouteLoader
{
/**
* @param iterable<string, string> $logoutPaths Logout paths indexed by the corresponding firewall name
* @param string $parameterName Name of the container parameter containing {@see $logoutPaths}' value
* @param array<string, string> $logoutUris Logout URIs indexed by the corresponding firewall name
* @param string $parameterName Name of the container parameter containing {@see $logoutUris}' value
*/
public function __construct(
private readonly iterable $logoutPaths,
private readonly array $logoutUris,
private readonly string $parameterName,
) {
}

public function __invoke(): RouteCollection
{
$collection = new RouteCollection();
$collection->addResource(new ContainerParametersResource([$this->parameterName => $this->logoutPaths]));
$collection->addResource(new ContainerParametersResource([$this->parameterName => $this->logoutUris]));

$routeNames = [];
foreach ($this->logoutPaths as $firewallName => $logoutPath) {
foreach ($this->logoutUris as $firewallName => $logoutPath) {
$routeName = '_logout_'.$firewallName;

if (isset($routeNames[$logoutPath])) {
Expand Down

0 comments on commit 17d1964

Please sign in to comment.