Skip to content

Commit 483fe9c

Browse files
author
Maxime
authored
Merge pull request #35 from delyriand/feature/ignore-routes
Allow routes to be ignored in the disable firewall listener
2 parents 9828179 + e5553db commit 483fe9c

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ monsieurbiz_sylius_nocommerce:
101101

102102
You can allow different sections by changing the parameters to `true`.
103103

104+
## Ignore routes
105+
106+
By default, the disable firewall listener will ignore the following routes for the developer toolbar.
107+
108+
You can ignore additional routes, such as the preview route for error pages, by adding them to the `config/packages/monsieurbiz_sylius_nocommerce_plugin.yaml` file:
109+
110+
```yaml
111+
parameters:
112+
monsieurbiz_sylius_nocommerce.disable_firewall.ignored_routes:
113+
- "_preview_error"
114+
```
115+
104116
## Contributing
105117

106118
You can open an issue or a Pull Request if you want! 😘

src/EventListener/DisableFirewallListener.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ final class DisableFirewallListener
3434

3535
private FeaturesProviderInterface $featuresProvider;
3636

37+
private array $ignoredRoutes;
38+
3739
public function __construct(
3840
FirewallMap $firewallContext,
3941
SettingsInterface $nocommerceSettings,
4042
ChannelContextInterface $channelContext,
41-
FeaturesProviderInterface $featuresProvider
43+
FeaturesProviderInterface $featuresProvider,
44+
array $ignoredRoutes = []
4245
) {
4346
$this->firewallContext = $firewallContext;
4447
$this->nocommerceSettings = $nocommerceSettings;
4548
$this->channelContext = $channelContext;
4649
$this->featuresProvider = $featuresProvider;
50+
$this->ignoredRoutes = $ignoredRoutes;
4751
}
4852

4953
/**
@@ -73,9 +77,10 @@ public function __invoke(RequestEvent $event): void
7377

7478
private function canCheckRoute(RequestEvent $event): bool
7579
{
76-
// allow profiler routes
80+
$ignoredRoutes = array_merge(self::PROFILER_ROUTES, $this->ignoredRoutes);
81+
7782
return $event->isMainRequest()
78-
&& !\in_array($event->getRequest()->attributes->get('_route'), self::PROFILER_ROUTES, true);
83+
&& !\in_array($event->getRequest()->attributes->get('_route'), $ignoredRoutes, true);
7984
}
8085

8186
private function getFirewallContextName(Request $request): string

src/Resources/config/services.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
parameters:
22
sylius.form.type.channel.validation_groups: [monsieurbiz_nocommerce]
3+
monsieurbiz_sylius_nocommerce.disable_firewall.ignored_routes: []
34

45
services:
56
_defaults:
@@ -22,12 +23,14 @@ services:
2223
MonsieurBiz\SyliusNoCommercePlugin\Menu\AdminCustomerShowMenuListener:
2324
tags:
2425
- { name: kernel.event_listener, event: sylius.menu.admin.customer.show, priority: -10000 }
25-
26+
2627
MonsieurBiz\SyliusNoCommercePlugin\Menu\ShopAccountMenuListener:
2728
tags:
2829
- { name: kernel.event_listener, event: sylius.menu.shop.account, priority: -10000 }
29-
30+
3031
MonsieurBiz\SyliusNoCommercePlugin\EventListener\DisableFirewallListener:
32+
arguments:
33+
$ignoredRoutes: '%monsieurbiz_sylius_nocommerce.disable_firewall.ignored_routes%'
3134
tags:
3235
- { name: kernel.event_listener, event: kernel.request, priority: -10000 }
3336

@@ -54,17 +57,17 @@ services:
5457
arguments:
5558
- '@MonsieurBiz\SyliusNoCommercePlugin\Context\NoCurrencyContext.inner'
5659
- '@monsieurbiz.no_commerce.provider.features_provider'
57-
60+
5861
MonsieurBiz\SyliusNoCommercePlugin\Registry\TemplateBlockRegistryDecorator:
5962
decorates: 'Sylius\Bundle\UiBundle\Registry\TemplateBlockRegistryInterface'
6063
arguments:
6164
$templateBlockRegistry: '@MonsieurBiz\SyliusNoCommercePlugin\Registry\TemplateBlockRegistryDecorator.inner'
6265
$featuresProvider: '@monsieurbiz.no_commerce.provider.features_provider'
6366

64-
monsieurbiz.no_commerce.provider.features_provider:
67+
monsieurbiz.no_commerce.provider.features_provider:
6568
class: 'MonsieurBiz\SyliusNoCommercePlugin\Provider\FeaturesProvider'
6669
public: true
67-
70+
6871
# Routing Context
6972
MonsieurBiz\SyliusNoCommercePlugin\Routing\NoCommerceRequestContext:
7073
decorates: router.request_context

0 commit comments

Comments
 (0)