Skip to content

Commit

Permalink
fix redirector state check (#151)
Browse files Browse the repository at this point in the history
* fix redirector state check
* remove legacy mode check from profiler, fixes #150
  • Loading branch information
solverat committed Oct 13, 2023
1 parent fac7a85 commit 6aaabd3
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 32 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
@@ -1,5 +1,9 @@
# 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)
- Remove legacy mode check in profiler [#150](https://github.com/dachcom-digital/pimcore-i18n/issues/150)

## Migrating from Version 4.x to Version 5.0

### Global Changes
Expand Down
11 changes: 0 additions & 11 deletions src/Adapter/Redirector/AbstractRedirector.php
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
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
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
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
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);
}
}
4 changes: 0 additions & 4 deletions templates/profiler/data_collector.html.twig
Expand Up @@ -12,10 +12,6 @@
<b>zone id</b>
<span>{{ collector.zoneId }}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>mode</b>
<span>{{ collector.i18nMode }}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>current locale</b>
<span>{{ collector.locale }}</span>
Expand Down

0 comments on commit 6aaabd3

Please sign in to comment.