Skip to main content
page last edited on 18 July 2022

Configuration

Version: 5.5.0

Configuration is a set of data whose values affect the operation of X-Cart.

Static configuration is data written to a file. It is assumed that this data does not change during X-Cart operation; if it changes, Symfony cache needs to be regenerated.

Dynamic configuration is data written to a database. The values can change dynamically; in some cases, X-Cart cache needs to be regenerated.

Runtime configuration is data that is calculated on each request and is mixed into the static or the dynamic configuration.

Static Configuration

For the purpose of declaring a configuration within Symfony, the X-Cart core is represented as a bundle. Further, the standard functionality is used: https://symfony.com/doc/current/bundles/configuration.html

The configuration scheme is declared in the class \XCart\DependencyInjection\Configuration

Although all the default values are declared in the scheme, the configuration file is still required both from the technical viewpoint and for clarity: src/config/packages/x_cart.yaml

To ensure the correct order, the module files /modules/[Author]/[Name]/config/service.yaml are loaded automatically. A DI extension in a module now only needs to be created if necessary.

The src/config/local/*.yaml files are the last to load.

To extend a configuration with a module or to declare a local configuration, the general scheme of the src/config/packages/x_cart.yaml file must be followed. In this case, declaring values into list variables will lead to automatic merging, whereas declaring them into scalar ones will lead to redefinition.

It is recommended that modules' own variables should be declared in the modules section. Please keep in mind that there will be no merging in the modules section, only redefinition.

There are two ways of changing the configuration from the code:

  • Via CompilerPass. In this case, the changes will be cached. Also, there will be no access to the values set through ENV.
  • In runtime - for example, via the xcart.boot event handler.

In both cases, you need to work with the service \XCart\Domain\StaticConfigDomain.

You can get the configuration values in the code via the \XCart\Domain\StaticConfigDomain service (Symfony way) or via \Includes\Utils\ConfigParser::getOptions (X-Cart way).

Switching to Storing Sessions in Redis

To switch to stoing sessions in Redis, you need to do the following:

  • Specify the correct parameters for connecting to Redis in ENV (.env.local)
###> Redis ###
REDIS_HOST="localhost"
REDIS_PORT="6379"
###< Redis ###
  • Switch the session handler. To do so, create a file /config/local/framework.yaml. (You can simply make a copy of /config/packages/framework.yaml and comment/uncomment the sections in it as you require.) The above needs to be done both in X-Cart and in the service-tool (/service-tool/config/local).
services:
Redis:
# you can also use \RedisArray, \RedisCluster or \Predis\Client classes
class: Redis
calls:
- connect:
- '%env(REDIS_HOST)%'
- '%env(int:REDIS_PORT)%'
# uncomment the following if your Redis server requires a password
# - auth:
# - '%env(REDIS_PASSWORD)%'
Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler:
arguments:
- '@Redis'
# you can optionally pass an array of options. The only options are 'prefix' and 'ttl',
# which define the prefix to use for the keys to avoid collision on the Redis server
# and the expiration time for any given entry (in seconds), defaults are 'sf_s' and null:
# - { 'prefix': 'my_prefix', 'ttl': 600 }

framework:
session:
handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler