Open sunchayn opened 6 years ago
This is the expected behavior. Your configuration files are supposed to be your source of truth and are never changed directly. Config::set()
will just let you set/override a value (in memory) after it's been loaded from your config.
I've been thinking about this and it might be worth adding a Config::persist()
method for saving changes to the config files. This might be tricky though due to the support of multiple config file formats.
Reopening for now to track this.
Hey Chris,
Actually, the project I was working on needed a 2 way config system. Unfortunately, I did not found a lightweight library for this task so I created my own package and use it in my project. I called the method sync()
. Here is my package and this was my main project, I made it supports PHP based configuration only because that's what I needed, persisting JSON is easy too. It's straightforward to start with these two configurations and add the rest gradually.
It's straightforward to start with these two configurations and add the rest gradually.
We already support six different config file formats so persistence should support each, otherwise we start fragmenting support which makes the package harder to maintain.
any plans on adding this feature as i need to save the config once i set something
Looking forward to Config::persist()
method
Hi @PHLAK, I've been implementing a persist through Symfony/Cache.
In the example below, I have hard-configured items to ignore in a config. When the system loads, it retrieves these from the cache through a callback unless the cache is expired or doesn't exist yet. That way I can add items on runtime, which will then be persisted for cacheDuration
time.
$cache = new FilesystemAdapter(namespace: $config->get('Api.RaceName'), defaultLifetime: 7 * 24 * 3600, directory: $config->get('Logging.Directory', 'Logs')); $alwaysIgnore = $cache->get(IGNORECACHEKEY, function (ItemInterface $item) use ($config) { $item->expiresAfter(new DateInterval('P3D')); // 3 days return $config->get("Configuration.AlwaysIgnore", []); });
Hey there, isn't supposed that the
set
method update the config file ? I'm using PHP configuration and nothing seems to happen when i useset
except changing the value in memory only.