PHPackages                             jbdevlabs/sylius-cli-context-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. jbdevlabs/sylius-cli-context-plugin

ActiveSylius-plugin[CLI &amp; Console](/categories/cli)

jbdevlabs/sylius-cli-context-plugin
===================================

Manage easilly Sylius Context on cli command and keep performance

v1.4.0(1y ago)47.0k↑55.6%1MITPHPPHP &gt;=8.1CI passing

Since Feb 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/JBDevLabs/SyliusCliContextPlugin)[ Packagist](https://packagist.org/packages/jbdevlabs/sylius-cli-context-plugin)[ GitHub Sponsors](https://github.com/macintoshplus)[ RSS](/packages/jbdevlabs-sylius-cli-context-plugin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (29)Versions (6)Used By (0)

Cli Context Plugin
==================

[](#cli-context-plugin)

This plugin provide a default channel context for your Symfony Command.

When Sylius load a resource implements `Sylius\Component\Resource\Model\TranslatableInterface`, a Doctrine`postLoad` event listener defines the default local and the current locale into the loaded object. The current local is determined from the current HTTP request and the `ChannelContext`.

In HTTP context, the current channel into `ChannelContext` is defined from hostname.

In Console context (cli), we have no HTTP request and the `ChannelContext` is empty. When you load a translatable resource, the channel context will load the first channel after running the `findAll` function on `ChannelRepository`.

But the `ChannelContext` will execute the `findAll` function for each resource loaded. The more you load resource more your command consume more memory and use more CPU resources.

Know issues: [Performance issue in cli commands: channel db request after each translatable entity postLoad event](https://github.com/Sylius/Sylius/issues/9296) and [Multiple channels with php-cli is not possible](https://github.com/Sylius/Sylius/issues/9987)

This Sylius plugin allows you to load the channel into the `ChannelContext` on `ConsoleCommandEvent` event. The `findAll` function on `ChannelRepository` will never be executed by `ChannelContext` and you preserve your performances.

Installation
------------

[](#installation)

Run the command `composer require jbdevlabs/sylius-cli-context-plugin dev-main`

Extends the Sylius Channel Repository
-------------------------------------

[](#extends-the-sylius-channel-repository)

> Note: If you have already extended the ChannelRepository, implement the interface `JbDevLabs\SyliusCliContextPlugin\Repository\CliChannelProviderInterface`and use the trait `JbDevLabs\SyliusCliContextPlugin\Repository\CliChannelProviderTrait` for interface implementation. Goto the alias configuration step.

### Implement and use trait

[](#implement-and-use-trait)

Make a new PHP class `ChannelRepository` in `src/Repository` like this:

```
