Skip to content
Marty Wallace edited this page Jul 13, 2016 · 8 revisions

Tempest includes an inbuilt method for managing configuration across different environments. This happens via the Configuration class.

Providing Configuration.

When instantiating Tempest, you are able to provide a path to a configuration file that it will load and make use of. The configuration file is simply a .php file that returns an array containing your configuration options:

return array(
    'myConfigVar' => 'Hello World!'
);

Variables set in your configuration are accessible via your main application instance:

App::get()->config->get('myConfigVar'); // Hello World!

Environments.

You are able to break your configuration down by environment. The environment is defined by an environment variable on your server named PHP_ENV. Tempest assumes you will make use of three environments that it provides constants for in the Environment class: dev, stage and prod.

To enable multi-environment configuration, your array must have a key * defined. This key stores the default configuration that applies to all environments. Environment provides a constant ALL if you'd prefer to use that for clarity:

use Tempest\Environment;

return array(
    Environment::ALL => array(
        'myConfigVar' => 'Hello World!'
    ),

    Environment::DEV => array(
        'myConfigVar' => 'Hello Dev!'
    )
);

Note: The default environment if one is not set on the server is dev.

Inbuilt Options.

There are a handful of inbuild configuration options too:

Option Default Description
Core
enabled: bool true Whether or not the site is enabled. If not, the site does not activate any services or trigger any routes. A 503 Service Unavailable response is sent while the site is not enabled.
url: string Educated guess using server name and port variables. The application URL e.g. http://yoursite.com.
timezone: string Default timezone provided by your PHP installation. The application timezone.
Routing
routes: array[] array() An array containing route information. Valid route information can be in any of these formats:
  • [uri, controller]
  • [uri, method, controller]
  • [uri, method, ...middleware, controller]
Where method is the HTTP method e.g. GET or POST. Middleware is executed in the order they are defined.
Connections
db: string - If defined, provides the connection details used by the internal database service. The value expected in a string in the following format: user:password@host/database. Note that dropping :password is also valid for empty password (typical for your development environment).
Paths
templates: string|string[] --- A path or array of paths where application level Twig templates can be loaded from.
controllers: string Controllers The base namespace for all controller classes.
middleware: string Middleware The base namespace for all middleware classes.
Clone this wiki locally