Skip to content
Greg Bowler edited this page Jun 7, 2018 · 8 revisions

Configuration files are used to store data that can change between environments, such as database connection details, API keys, timezone information, and so on. It is common practice to have different configuration values based on the environment where the application is running.

All configuration files for WebEngine applications are stored in the project's root directory as .ini files, and a default config is supplied by WebEngine to set all config values to meaningful defaults.

Config override order

Multiple config files can exist which introduce new config values or override existing values. All values can also be overridden by setting environment variables on the server.

The following order is used to override configuration values:

  • The WebEngine default config: /vendor/phpgt/webengine/config.default.ini
  • The project's default config: config.ini
  • Development config: config.dev.ini
  • Deployment config: config.deploy.ini
  • Production config: config.prod.ini
  • Environment variables

Configuration file contents

// Sections.

Environment variables

// Use underscore to separate sections.

Accessing configuration variables

Throughout WebEngine, global variables are not permitted. Config values can usually be seen as global state, meaning that they can be read from anywhere in your code (or your code's dependencies). Rather than passing around important API keys and database passwords to every class in the application, a single instance of the Config class is passed to your Page Logic entrypoint, allowing you to decide which classes of the application get passed the configuration, and which sections of the configuration they have access to.

From within a Logic class, $this->config is set to an instance of the Config object. The config object has two mechanisms for retrieving config data: get and getSection.

Config::get

The get method allows the use of dot-notation to grab the value of some config by name.

Configuring production servers

// Store in web server.

Ini types

// Bool (on off, etc)

Clone this wiki locally