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.
Note: This example will use the "Config PHP files" by default; all files in 'config/*.php'
.
The config file
First, we need a config file with the key-values that we want to access from out Config
:
The Module's Config class
The Config
class from your module can access those config key-values by their keys:
Accessing the Config from the Factory
You can access the Config
methods from the Factory
, to create your domain logic:
The Facade uses the Factory
In the end, the Factory will be used by the module's Facade:
Config files for different environments
You can load (on top of the existing application config files) some particular files with the same suffix as
the APP_ENV
values in the config files. For example, having this config setup:
Then the config value that we will get when looking for 'AKISMET-KEY
will be:
- If we don't have any
APP_ENV
, thendefault-akismet-key
- If we have
APP_ENV=prod
, thenproduction-akismet-key