setono/sylius-static-contexts-bundle

A Symfony bundle that gives you static contexts

Maintainers

πŸ‘ loevgaard

Package info

github.com/Setono/sylius-static-contexts-bundle

Type:symfony-bundle

pkg:composer/setono/sylius-static-contexts-bundle

Statistics

Installs: 6 944

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-04-13 08:03 UTC

MIT d07bc806c36d7b1f60eb8713070cc65487aad55a

  • Joachim LΓΈvgaard <joachim.woop@loevgaard.dk>

This package is auto-updated.

Last update: 2026-06-13 08:34:34 UTC


README

πŸ‘ Latest Version
πŸ‘ Software License
πŸ‘ Build Status
πŸ‘ Code Coverage
πŸ‘ Mutation testing

Provides static channel and locale contexts for Sylius. This allows you to set the channel and locale programmatically instead of relying on HTTP request resolution β€” useful for CLI commands, message handlers, and testing.

Both contexts are registered at priority 256, so they take precedence over Sylius's default request-based contexts whenever a value is set.

Requirements

  • PHP >= 8.2
  • Symfony ^6.4 || ^7.4
  • Sylius v2

For Sylius v1 support, use the 1.x branch.

Installation

composer require setono/sylius-static-contexts-bundle

Usage

Setting the channel

use Setono\SyliusStaticContextsBundle\Context\StaticChannelContext;

final class YourCommand extends Command
{
 public function __construct(private readonly StaticChannelContext $channelContext)
 {
 parent::__construct();
 }

 protected function execute(InputInterface $input, OutputInterface $output): int
 {
 // Set by channel code (looks up the channel via the repository)
 $this->channelContext->setChannelCode('web_us');

 // Or set by channel object directly
 $this->channelContext->setChannel($channel);

 // Now any service that depends on ChannelContextInterface
 // will resolve to this channel
 // ...

 // Reset when done (also happens automatically via Symfony's ResetInterface)
 $this->channelContext->reset();

 return Command::SUCCESS;
 }
}

Setting the locale

use Setono\SyliusStaticContextsBundle\Context\StaticLocaleContext;

final class YourCommand extends Command
{
 public function __construct(private readonly StaticLocaleContext $localeContext)
 {
 parent::__construct();
 }

 protected function execute(InputInterface $input, OutputInterface $output): int
 {
 $this->localeContext->setLocaleCode('en_US');

 // Now any service that depends on LocaleContextInterface
 // will resolve to this locale
 // ...

 $this->localeContext->reset();

 return Command::SUCCESS;
 }
}