description |
---|
Ecotone Framework customization |
Ecotone
allows for customization of the core functionality as well as the modules.
Depending on the provider you choose, you can follow configuration in specific menu
Module Extensions are configurations for specific module. It's class based configuration.
Let's take a look on Dbal module configuration as example:
class MyConfiguration // 1
{
#[ServiceContext] // 2
public function registerTransactions() // 3
{
return DbalConfiguration::createWithDefaults() // 4
->withTransactionOnAsynchronousEndpoints(true)
->withTransactionOnCommandBus(true);
}
}
- Create your own class. You can name it whatever you like.
- Add attribute to let
Ecotone
know that it should call this method to get the configuration. - Name the method whatever you like. You may return
array
of configurations orspecific configuration instance
. - Return specific configuration.
{% hint style="info" %}
Ecotone does not require specific class name or method name.
All what is needed is #[ServiceContext]
attribute.
{% endhint %}
If you want to enable different configuration for specific environment you may use of Environment attribute
.
class MyConfiguration
{
#[ServiceContext]
#[Environment(["dev", "prod"])]
public function registerTransactions()
{
return DbalConfiguration::createWithDefaults()
->withTransactionOnAsynchronousEndpoints(true)
->withTransactionOnCommandBus(true);
}
#[ServiceContext]
#[Environment(["test"])]
public function registerTransactions()
{
return DbalConfiguration::createWithDefaults()
->withTransactionOnAsynchronousEndpoints(false)
->withTransactionOnCommandBus(false);
}
}
Above will turn off transactions for test
environment, keeping it however for prod
and dev
.
You may access your configuration variables inside ServiceContext
methods.
class MyConfiguration
{
#[ServiceContext]
public function registerTransactions(#[ConfigurationVariable("database")] string $connectionDsn)
{
return Repository($connectionDsn);
}
}
If you don't pass ConfigurationVariable
attribute, it will be taken from parameter name.
Below example is equal to above.
class MyConfiguration
{
#[ServiceContext]
public function registerTransactions(string $database)
{
return Repository($database);
}
}
{% hint style="warning" %}
Service Context is evaluated before container is dumped and cached. Therefore if you will change environment variables after your cache is dumped this won't be changed.
This happens because Ecotone tries to maximalize configuration caching, in order to speed up run time execution and do no configuration at that time.
{% endhint %}