We are using the same options that Kirby does in the core. That can be a problem. The options are increasing with every version. Now there are about 50 “protected” options in there.
If I make a plugin today with options, who knows if Kirby takes that “key” in the next version?
I would say there is rather the need for plugin developers to really use specific names for their options. And looking at the upcoming registry, that allows plugins to register blueprints, templates, snippets etc. this becomes even more important.
I agree! We already talked about a developer guideline internally and this should be part of it, together with naming convetions for classes, helper functions, etc.
Maybe I’m over analyzing stuff but maybe I create a plugin called tinyurl. Therefor that would be my prefix of all my options.
Then my options would be like:
tinyurl.controller
tinyurl.folder
Oops! tinyurl.folder is already taken by the Kirby core. If the Kirby core option would have been named kirby.tinyurl.folder the problem would have never existed.
Would be nice to have something to grab on to. Else it’s hard to know. Can I use the option seo.controller.path even in future versions of Kirby? How can I be sure? Right now I can’t be, but I simply need to calculate the risk of that just that option key is taken or not.
Even if there was a separate user configuration object, how could you be sure that no other plugin developer uses the same option as you?
A separate user configuration would therefore only add complexity (“wait, does this plugin require c::set or u::set?”), create bugs because of that and wouldn’t even really solve the problem.
My advice: Use namespaced config options like myplugin.something and if you see that there is a conflict, update your plugin with a non-conflicting version. The chance of this happening is so slim that any extra effort on either side is not worth it.
If we implemented that at runtime, people would start to dynamically change their option names, which also doesn’t make sense.
My approach when developing plugins is: Always namespace, and if even that doesn’t work while testing, I quickly see that something else is in the way. Let’s not make Kirby more complex here.
I’d recommend having a developer guide with conventions. Nothing enforced in code but some good recommendations.
For instance plugins could try to use a config prefix like "plugin.mypluginname.". Of course there could still be collisions between plugins (two plugins picking the same name), but that would avoid collisions with core features ("featurename." prefix) or older plugins (often using “pluginname.” prefixes).
The “this wouldn’t prevent collisions between plugins” objection is basically the same as saying “you have 2 problems, and if you can’t fix both you should’nt fix any!”. I say a recommendation that avoids collisions with Kirby core is quite good enough, especially as collisions between plugins are not as critical as collisions with Kirby core.
For PHP classes, maybe using a Kirby\Plugin\MyPlugin namespace?
This kinda requires you to spam use statements (or do stuff like class MyComponent extends \Kirby\Component\Something {}), but that’s an okay cost IMO and nobody would be forced to follow this recommendation anyway.