Rethinking configuration for my #OpenAPI/#OAS#PHP client generator while transforming it into a package generator. Currently using #YAML hydrating into #PHP classes. Mainly looking to support both those wanting to keep it simple and those with complex setups without to much duplication.
Been working on this slowly over the past few days and honestly #PHP is the way to go. Other formats are nice, but #PHP allows for so much flexibility 💗 !
@wyri I think you could also consider INI, TOML, JSON.
I also have that kind of question on a regular basis. This is where the feature (read a config file) and the format (well... all of those above) have to be decoupled.
There could be a package that handle all those formats (modular), apply some validations (optional) and deliver a pre-defined class. Also, write to those formats.
@dseguy it should be possible to build this using symfony/config. They support a decoupled config definition in php, you just need to write a parser @wyri
@wyri@dseguy yeah they see this as advanced usage, so you need to dig in the code. I disagree with that, but I understand that they have to limit their time on docs.
@jrf_nl@wyri OTOH saving on parsing some "other" language into PHP code and being able to use an IDEs code-completion for the language are positive sideeffects for configs in PHP...
@heiglandreas@jrf_nl@wyri You can get pretty much the same effect with XML and a well defined schema though, IDEs should be able to complete those just fine
@heiglandreas@NanoSector@jrf_nl@gmazzap Ultimately it all has to be hydrated into PHP as the configuration passed around is a nested object tree. YAML and JSON can be mapped into that., XML as well I'm assuming. Doing it directly in PHP allows for more flexibility and more DRY code/config, when things get complicated. Attached WIP PHP and YAML config files.
@jrf_nl@wyri I'm very much for config in PHP. If you support a "config.php" file or so, separation exists, but the boost in flexibility is huge.
If the file has to return an array, what happens in that file is up to you. As an example, functions or vars can avoid duplication in similar parts. And if you document the expected array, you can even have static check via Psalm/Phpstan.
Not to mention freeform comments.
And there're many existing libs for type-safe object hydration from array.
Add comment