Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why Config::set(), do not update the value in the config file ? #5

Open
sunchayn opened this issue Nov 6, 2018 · 7 comments
Open
Assignees

Comments

@sunchayn
Copy link

sunchayn commented Nov 6, 2018

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 use set except changing the value in memory only.

@PHLAK
Copy link
Owner

PHLAK commented Nov 6, 2018

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.

@PHLAK PHLAK closed this as completed Nov 6, 2018
@PHLAK
Copy link
Owner

PHLAK commented Nov 27, 2018

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.

@PHLAK PHLAK reopened this Nov 27, 2018
@sunchayn
Copy link
Author

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.

@PHLAK
Copy link
Owner

PHLAK commented Nov 27, 2018

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.

@xbipin
Copy link

xbipin commented Aug 28, 2019

any plans on adding this feature as i need to save the config once i set something

@PHLAK PHLAK self-assigned this Aug 28, 2019
@darkstriders
Copy link

Looking forward to Config::persist() method

@Externaluse
Copy link
Contributor

Externaluse commented Nov 4, 2023

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", []); });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants