Skip to content
This repository was archived by the owner on May 5, 2024. It is now read-only.

The Configuration Object

brandonsavage edited this page Dec 19, 2014 · 1 revision

The Modus Framework offers simple to complex configuration, depending on your needs.

The Configuration Object

All configuration files are read and parsed by Modus\Config\Config when the framework is loaded. This object has two tasks:

  • Read the configuration files, consisting of PHP arrays;
  • Read the configuration objects for the Dependency Injection Container.

The configuration object stores the configuration and makes itself available as a service on the dependency inversion container.

Configuration files

Modus uses configuration files consisting of PHP arrays for the purposes of loading configuration into the system. Modus ships with a default configuration file, but it's possible to add others to suit your needs. In addition, Modus has support for various environments. The available environments are:

  • dev - For development
  • staging - Staging environment
  • production - A production environment
  • testing - For testing environments (Selenium, etc)

The configuration object will automatically merge the configuration files, overriding settings according to a predetermined hierarchy. The following hierarchy is used for configuration:

  • config.php - This is the base configuration file, and is always loaded first
  • The environment (dev, staging, production, testing)
  • local.php - A local configuration file of your specific settings

The Dependency Injection Container System

Modus includes and uses Aura.Di as the dependency injection container for the framework.

When the configuration files have been read and merged, the configuration object moves on to reading through the object configurations. Each object configuration is stored in its own file, as part of the AppConfig/ namespace.

By default, Modus is configured to lazy-load the objects into the container. This means the objects are not instantiated until they are actually called. However, in some cases (e.g. where the object will be passed as part of an array in a configuration argument), the object is instantiated (since lazy-loading the object creates a closure).

Setting the configuration environment

Modus expects that the configuration environment will be available as an environment variable called MODUS_ENV. Setting this in your .htaccess file, Nginx configuration file, or virtual host file in Apache will allow Modus to load the correct environment.