Download the PHP package jbdevlabs/sylius-cli-context-plugin without Composer
On this page you can find all versions of the php package jbdevlabs/sylius-cli-context-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jbdevlabs/sylius-cli-context-plugin
More information about jbdevlabs/sylius-cli-context-plugin
Files in jbdevlabs/sylius-cli-context-plugin
Package sylius-cli-context-plugin
Short Description Manage easilly Sylius Context on cli command and keep performance
License MIT
Informations about the package sylius-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 DoctrinepostLoad
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 and Multiple channels with php-cli is not possible
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
Run the command composer require jbdevlabs/sylius-cli-context-plugin dev-main
Extends the Sylius Channel Repository
Note: If you have already extended the ChannelRepository, implement the interface
JbDevLabs\SyliusCliContextPlugin\Repository\CliChannelProviderInterface
and use the traitJbDevLabs\SyliusCliContextPlugin\Repository\CliChannelProviderTrait
for interface implementation. Goto the alias configuration step.
Implement and use trait
Make a new PHP class ChannelRepository
in src/Repository
like this:
Configure the new repository
Declare this repository on config/packages/_sylius.yaml
file like this:
Fix the interface alias
Declare the alias for JbDevLabs\SyliusCliContextPlugin\Repository\CliChannelProviderInterface
to the channel repository.
Configuration
Add a file jb_dev_labs_sylius_cli_context.yaml
into config/packages
and set your configuration.
Usage on your command
By default, no Channel context is loaded.
To automaticaly load channel context for your command, implement the interface JbDevLabs\SyliusCliContextPlugin\Command\CliContextAwareInterface
on your command.
Example:
Usage on bundle command
You want load the Sylius Channel context when command provided by another plugin is executed ?
Add the command class namespace on your configuration to enable the Context initialisation.
Usage programatically
See the documentation
Contributor Installation (docker)
-
Clone this project
- From the plugin skeleton root directory, run the following commands:
Quality tools
ProTip use Makefile
;)
Contributor quickstart Installation (legacy)
-
Clone this project
- From the plugin skeleton root directory, run the following commands:
To be able to setup a plugin's database, remember to configure you database credentials in tests/Application/.env
and tests/Application/.env.test
.
Usage
Running plugin tests
-
PHPUnit
-
PHPSpec
-
Behat (non-JS scenarios)
-
Behat (JS scenarios)
-
Start Headless Chrome:
-
Install SSL certificates (only once needed) and run test application's webserver on
127.0.0.1:8080
: - Run Behat:
-
Static Analysis
-
Psalm
- PHPStan
-
- Coding Standard
Opening Sylius with your plugin
-
Using
test
environment: - Using
dev
environment: