setono/sylius-static-contexts-bundle
Composer 安装命令:
composer require setono/sylius-static-contexts-bundle
包简介
A Symfony bundle that gives you static contexts
README 文档
README
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.xbranch.
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; } }
统计信息
- 总下载量: 6.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-07