Skip to content

Instantly share code, notes, and snippets.

@remie
Created January 8, 2012 20:28
Show Gist options
  • Save remie/1579561 to your computer and use it in GitHub Desktop.
Save remie/1579561 to your computer and use it in GitHub Desktop.
Design document for Symphony Issue 669

Design document for Symphony Issue 669

This document is created to list all options for solving Symphony Issue 669. The goal is to find a way to make the config.php file aware of the environment on which it runs and to make it sharable between developers. Most of the configuration settings are the same for all environments, so only a subset needs to be changeable to deal with the differences between multiple local environments during development and releasing to T/A/P.

Requirements

  1. Allow environment specific configuration
  2. Allow configuration to be shared between developers
  3. require minimal core changes
  4. require no breaking changes to the Configuration class
  5. be relatively backwards compatible with the ability to update the old format to the new format
  6. be secure
  7. implement the minimum, and allow an extension to take care of the edge cases

Implementation proposals

There are several ways to solve this problem. Below is a list of four possible implementations with their pros and cons.

  1. Private sections in config.php
  2. Environment specific sections in config.php
  3. Environment specific configuration files (included on naming convention)
  4. JAVA style property replacement

Private sections in config.php

At the end of the config.php there will be a private section which will not be overwritten when the document is saved by the Configuration class. A preset marker will be used to separate the two sections.

Default configuration should go in the regular config.php and settings should be overwritten by the private section.

Pros

  1. Meets requirements 3,4,5,7. Requirement 6 is only met when this feature is used by smart people.
  2. Single configuration file
  3. Allows any type of custom PHP code to be added

Cons

  1. It does not meet requirement 1 & 2: this only works in a single-user setting. The contents of this file will still live in version control. Changes are shared with all team members. In order for everybody to be able to work with the project, they will need to adjust their local environment to match the settings in the config.php file.
  2. Teams can still meet requirement 1 & 2 if they are smart enough to use this ability to implement propasal 3: including environment specific config files which are not in version control and contain settings specific to that environment. So why not just do that in the first place?
  3. It is potentially insecure: environment specific information could end up in version control.

Environment specific sections in config.php

At the end of the config.php there will be a environment specific section which will not be overwritten when the document is saved by the Configuration class. A marker based on the host name will be used to separate the multiple configuration sections.

Default configuration should go in the regular config sections and settings should be overwritten by the environment specific section.

Pros

  1. Meets requirements 1,2,3,4,5,7
  2. Single configuration file
  3. Allows any type of custom PHP code to be added

Cons

  1. Configuration file can become unmanageable in case of large number of environments.
  2. Insecure: environment specific information is committed to version control and available to all team members.

Environment specific configuration files (included on naming convention)

The environment specific configuration lives in a separate file. This can included based on fixed name (environment.php), a file named after the host (MyLocalHostName.php) or pattern inclusion (config.*.php). The environment specific configuration files can live outside version control and are thus truly independent.

Default configuration should go in the regular config.php and settings should be overwritten by the included files.

Pros

  1. Meets requirements 1,2,3,4,5,6,7
  2. Allows any type of custom PHP code to be added

Cons

  1. Creates multiple sources for configuration: If a developer only adds a config setting to their local file and not to the generic config.php, this will not be available in other environments.

JAVA style property replacement

The config.php file will contain variables (properties) which will be replaced on runtime by the configuration class. This technique is borrowed from JAVA programming. The value of the variable will be place in a separate file which is a CRLF-separated key/value pair list (*.properties files).

Config settings that contain variables will not be replaced by the configuration class upon saving. This will exclude those settings from being updated programmatically. Developers will need to create a default.properties file to ensure that the variables will be replaced on runtime if no environment specific information is available.

JAVA properties can be nested, but their value is immutable. The order in which the property files are included determines the runtime value of the variable. This allows for sophisticated, sometimes overly complex, configuration. The inclusion order should be set in the config.php file, and will contain something like 'default.properties;local.properties' where the 'local.properties' file will not be placed under version control and is thus truly independent.

Pros

  1. Meets requirements 1,2,4,5,6,7
  2. Single configuration file
  3. JAVA properties allow complex configuration. This is both a pro and a con

Cons

  1. Although this can be made backwards compatible, and does not require breaking changes to the configuration class, it will include major changes to this class. JAVA properties are not natively supported in PHP. This means an additional class will be created to deal with the parsing of property files.
  2. It is not common for PHP projects to use JAVA style properties. Even though they are easy to understand and to implement, there will be a learning curve for most developers.
  3. JAVA properties allow complex configuration. This is both a pro and a con
  4. If you forget to create a property for a variable in the config file, it will not be replaced on runtime, and it could potentially break your project.
  5. Config settings that contain variables will not be replaced by the configuration class upon saving
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment