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

Add support for writing configuration files #107

Closed
filips123 opened this issue Jul 1, 2018 · 8 comments
Closed

Add support for writing configuration files #107

filips123 opened this issue Jul 1, 2018 · 8 comments
Milestone

Comments

@filips123
Copy link
Collaborator

Add support for writing configuration files. This would be useful so developers could make user-friendly installers for configuration files.

For INI, XML, JSON, YAML and other formats, this should not be hard, because they already support writing. For PHP files, this could be harder.

Example of writing config from start:

// Instantiation
$conf = new Config();

// Setting value using key
$conf->set('debug', true);
$conf['debug'] = true;

// Setting value using nested key
$conf->set('security.secret', 'eXaMpLe');
$conf['security.secret'] = 'eXaMpLe';
$conf['security']['secret'] = 'eXaMpLe';

// Setting all values from array
$settings = array(
    'debug' => true,
    'security' => array(
        'secret' => 'eXaMpLe',
        'password' => '1234'
    ),
    'app.timeout' => 3000,
    'app.name' => 'Website'
);
$conf->set('', $settings);
$conf->all() = $settings;
$conf = $settings;

// Writing to file
$conf->write('config.json');

Example of writing using existing config:

// Instantiation
$conf = new Config('config.json');

// Setting value using key
$conf['debug'] = true;

// Writing to existing file (file should now have all previous settings and new ones)
$conf->write();

// Writing to new file (file should now have all previous settings from other file and new ones)
$conf->write('config.yml');
@filips123
Copy link
Collaborator Author

@DavidePastore @hassankhan I'm working on writing support in my repository. Currently, the result of writing would be minified (for example one file for JSON). Is this OK or should the result be not minified?

@DavidePastore
Copy link
Collaborator

@filips123 I would prefer to have the chance to choose (using configuration) if I want minified output or not.

@filips123
Copy link
Collaborator Author

@DavidePastore I currently don't have much time, but I will continue implementing writing support next month. Problem is that I would have to change, add and rename methods in parsers and other classes so this would be breaking change and new major version (3.0.0). Is that OK? Would it be possible to do this without breaking changes?

@DavidePastore
Copy link
Collaborator

@filips123 I think you can do it without breaking changes but by only adding new methods for the purpose. If you already have something in mind you can share it with us (cc @hassankhan ) so we could discuss about it. Anyway it could make sense to create a new major version for this kind of improvement.

@filips123
Copy link
Collaborator Author

@DavidePastore I created something in my repository. However, those changes are old and I will need to rewrite them because of git conflicts with new updates.

@DavidePastore
Copy link
Collaborator

@filips123 I like the idea behind it and the way you did it. The breaking change you were talking about before was the parse-> decode refactoring, right?

@filips123
Copy link
Collaborator Author

I like the idea behind it and the way you did it.

Thank you. I need to fix all git conflicts. I will then also provide support for writer configuration (#107 (comment)).

The breaking change you were talking about before was the parse-> decode refactoring, right?

Yes.

@filips123
Copy link
Collaborator Author

Fixed with #122 in 2.1.0.

@DavidePastore DavidePastore modified the milestones: Future Release, 2.1.0 Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants