This concept is not a design pattern itself, but it's designed in a way that you can easily access all config values in your modules, and it's accessible from the Factory out of the box. The Config allows you to construct your business objects with specific configuration values clearly and straightforwardly.
Reading the key-values
Config class can get the key-values from your config files. You can define your config files in
Config class is accesible from the
Factory, so you can inject these config values to your business/domain
In order to achieve that, you need to create a
gacela.php file in your application root:
ConfigGacela -> config()
Config PHP files
Config ENV files
Multiple and different config files
- type: enum with possible values php or env.
- path: this is the path of the folder which contains your application configuration. You can use ? or * in order to match 1 or multiple characters. Check glob() function for more info.
- path_local: this is the last file loaded, which means, it will override the previous configuration, so you can easily add it to your .gitignore and set your local config values in case you want to have something different for some cases.
ConfigGacela -> mappingInterfaces()
You can define a map between an interface and the concrete class that you want to create/use when that interface is found during the process of auto-wiring of the dependencies of the Factory via its constructor.
As one step forward, you can let know Gacela the global services that you want to have access in your
gacela.php config file
by passing them in the entry point of your app:
In the example above, whenever
OneInterface::class is found then
ConcreteClass2::class will be resolved.
If you don't define any
gacela.php file, the Config will use the "Config PHP files" configuration.
You can define your own ConfigReaders
You can implement your custom config reader by using
and setting it to the config-singleton. For example:
There is actually a YAML/YML config reader package out-of-the box in the Gacela repository. This package is not included by default in Gacela because it has its own specific dependencies.
A complete example
Non gacela.php needed. It will use the "Config PHP files" by default.