Skip to content

Commit

Permalink
feat: allow routes to be ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
delyriand committed Mar 26, 2024
1 parent 9828179 commit 2ca79c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/EventListener/DisableFirewallListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ final class DisableFirewallListener

private FeaturesProviderInterface $featuresProvider;

private array $ignoredRoutes;

public function __construct(
FirewallMap $firewallContext,
SettingsInterface $nocommerceSettings,
ChannelContextInterface $channelContext,
FeaturesProviderInterface $featuresProvider
FeaturesProviderInterface $featuresProvider,
array $ignoredRoutes = []
) {
$this->firewallContext = $firewallContext;
$this->nocommerceSettings = $nocommerceSettings;
$this->channelContext = $channelContext;
$this->featuresProvider = $featuresProvider;
$this->ignoredRoutes = $ignoredRoutes;
}

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

private function canCheckRoute(RequestEvent $event): bool
{
// allow profiler routes
$ignoredRoutes = array_merge(self::PROFILER_ROUTES, $this->ignoredRoutes);

return $event->isMainRequest()
&& !\in_array($event->getRequest()->attributes->get('_route'), self::PROFILER_ROUTES, true);
&& !\in_array($event->getRequest()->attributes->get('_route'), $ignoredRoutes, true);
}

private function getFirewallContextName(Request $request): string
Expand Down
13 changes: 8 additions & 5 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
sylius.form.type.channel.validation_groups: [monsieurbiz_nocommerce]
monsieurbiz_sylius_nocommerce.disable_firewall.ignored_routes: []

services:
_defaults:
Expand All @@ -22,12 +23,14 @@ services:
MonsieurBiz\SyliusNoCommercePlugin\Menu\AdminCustomerShowMenuListener:
tags:
- { name: kernel.event_listener, event: sylius.menu.admin.customer.show, priority: -10000 }

MonsieurBiz\SyliusNoCommercePlugin\Menu\ShopAccountMenuListener:
tags:
- { name: kernel.event_listener, event: sylius.menu.shop.account, priority: -10000 }

MonsieurBiz\SyliusNoCommercePlugin\EventListener\DisableFirewallListener:
arguments:
$ignoredRoutes: '%monsieurbiz_sylius_nocommerce.disable_firewall.ignored_routes%'
tags:
- { name: kernel.event_listener, event: kernel.request, priority: -10000 }

Expand All @@ -54,17 +57,17 @@ services:
arguments:
- '@MonsieurBiz\SyliusNoCommercePlugin\Context\NoCurrencyContext.inner'
- '@monsieurbiz.no_commerce.provider.features_provider'

MonsieurBiz\SyliusNoCommercePlugin\Registry\TemplateBlockRegistryDecorator:
decorates: 'Sylius\Bundle\UiBundle\Registry\TemplateBlockRegistryInterface'
arguments:
$templateBlockRegistry: '@MonsieurBiz\SyliusNoCommercePlugin\Registry\TemplateBlockRegistryDecorator.inner'
$featuresProvider: '@monsieurbiz.no_commerce.provider.features_provider'

monsieurbiz.no_commerce.provider.features_provider:
monsieurbiz.no_commerce.provider.features_provider:
class: 'MonsieurBiz\SyliusNoCommercePlugin\Provider\FeaturesProvider'
public: true

# Routing Context
MonsieurBiz\SyliusNoCommercePlugin\Routing\NoCommerceRequestContext:
decorates: router.request_context
Expand Down

0 comments on commit 2ca79c7

Please sign in to comment.