setono/sylius-static-contexts-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

setono/sylius-static-contexts-bundle

Composer 安装命令:

composer require setono/sylius-static-contexts-bundle

包简介

A Symfony bundle that gives you static contexts

README 文档

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;
    }
}

统计信息

  • 总下载量: 6.89k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固