Configuration
Configuration files in Masonite are gathered in one folder named config
in default projects.
Each feature can have some options in its own file named after the feature. For example you will find mail related options in config/mail.py
file.
Getting Started
The Configuration
class is responsible for loading all configuration files before the application starts.
It will load all files located at path defined through config.location
binding which default to config/
.
Then values are accessed based on the file they belong to and a dotted path can be used to access nested options.
Given the following config/mail.py
file:
Accessing
mail
will return a dictionary with all the options.Accessing
mail.from_email
will return theFROM_EMAIL
valueAccessing
mail.drivers.smtp.port
will return the port value for smtp driver.
Getting Value
To read a configuration value one can use the Config
facade:
or the config
helper:
Setting Value
Setting configuration values is achieved through projet configuration files.
Overriding Value
However, you can override on the fly a configuration value with the Config
facade:
This should be done sparingly as this could have unexpected side effects depending at which time you override the configuration option.
This is mostly useful during tests, when you want to override a configuration option to test a specific behaviour:
But if you simply want to have different configuration depending on the environment (development, testing or production) you should rely instead on environment variables used to define configuration options.
Last updated