PHP code example of setono / sylius-static-contexts-bundle

1. Go to this page and download the library: Download setono/sylius-static-contexts-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

setono / sylius-static-contexts-bundle example snippets


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

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