Skip to content

Commit

Permalink
fix redirector state check
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Oct 13, 2023
1 parent fac7a85 commit b9c3ae3
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 28 deletions.
3 changes: 3 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Upgrade Notes

## 5.0.1
- Remove `isEnabled` and `setEnabled` from redirector adapter since disabled services aren't available anymore [#149](https://github.com/dachcom-digital/pimcore-i18n/issues/149)

## Migrating from Version 4.x to Version 5.0

### Global Changes
Expand Down
11 changes: 0 additions & 11 deletions src/Adapter/Redirector/AbstractRedirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,10 @@

abstract class AbstractRedirector implements RedirectorInterface
{
protected bool $enabled = true;
protected array $config = [];
protected ?string $name;
protected array $decision = [];

public function isEnabled(): bool
{
return $this->enabled;
}

public function setEnabled(bool $enabled): void
{
$this->enabled = $enabled;
}

public function getConfig(): array
{
return $this->config;
Expand Down
4 changes: 0 additions & 4 deletions src/Adapter/Redirector/RedirectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

interface RedirectorInterface
{
public function isEnabled(): bool;

public function setEnabled(bool $enabled): void;

public function getName(): string;

public function setName(string $name): void;
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/RedirectorAdapterPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function process(ContainerBuilder $container): void
}

foreach ($services as $service) {

$serviceAlias = $service['alias'];
$available = isset($redirectorRegistry[$serviceAlias]) ? $redirectorRegistry[$serviceAlias]['enabled'] : true;

Expand All @@ -44,7 +45,6 @@ public function process(ContainerBuilder $container): void
$definition->addMethodCall('register', [$service['reference'], $serviceAlias]);

$service['definition']->addMethodCall('setName', [$serviceAlias]);
$service['definition']->addMethodCall('setEnabled', [$available]);
$service['definition']->addMethodCall('setConfig', [$redirectorRegistry[$serviceAlias]['config'] ?? []]);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/EventListener/DetectorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,12 @@ public function onKernelResponse(ResponseEvent $event): void
return;
}

$cookieRedirector = $this->redirectorRegistry->get('cookie');

//check if we're allowed to bake a cookie at the first place!
if (false === $cookieRedirector->isEnabled()) {
if (!$this->redirectorRegistry->has('cookie')) {
return;
}

$cookieRedirector = $this->redirectorRegistry->get('cookie');
$cookieHelper = new CookieHelper($cookieRedirector->getConfig()['cookie']);

$i18nContext = $this->i18nContextResolver->getContext($event->getRequest());
Expand Down
10 changes: 1 addition & 9 deletions src/Registry/RedirectorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ public function get(string $alias): RedirectorInterface
*/
public function all(): array
{
$list = [];
foreach ($this->adapter as $adapter) {
if (!$adapter->isEnabled()) {
continue;
}
$list[] = $adapter;
}

return $list;
return array_values($this->adapter);
}
}

0 comments on commit b9c3ae3

Please sign in to comment.