Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging default configuration with user options

Lets say our application has configuration that is stored as a simple array:

$config = array(
    'max_files' => 10,
    'suffixes'  => '[jpg,swf,png,gif]',
    'max_size'  => '10G'
);

We want to keep this configuration in the code, because when we release new versions of the software we want to add or change default values.

Now lets say that we want to open these configuration values to the user (admin) of the website. They will modify these values with some kind of GUI (textbox, dropdown, multiselect etc).

How do we apply updates when we release new versions of the software and still allow users to edit values. How do bigger systems do this (i.e magento for example). Should we copy the values to the database upon "upgrade" and then not use the values in the code?

Happy to hear ideas and thoughts

like image 617
Mike Parkin Avatar asked Feb 22 '23 22:02

Mike Parkin


1 Answers

  1. Grab your default configuration value array
  2. Grab the config values set from the user (from a seperate database, config file, whatever)
  3. Merge the two arrays, overwriting any intersecting keys from the default configuration
  4. ??
  5. Profit
like image 176
John Cartwright Avatar answered Feb 25 '23 11:02

John Cartwright