getkirby/ideas

[Cms] Namespaced options as array instead of dot-notation

Opened this issue · 7 comments

@jenstornell commented on Jul 27, 2018, 4:46 AM UTC:

In the options in config/config.php, currently what we do is this:

return [
    'jenstornell.robots.content' => 'testing',
    'jenstornell.ga.id' => '12345',
    'jenstornell.ga.debug' => true,
];

It works fine, but I'm very tempted to instead write something like this:

return [
    'jenstornell' => [
        'robots' => [
            'content' => 'testing'
        ],
        'ga' => [
            'id' => '12345',
            'debug' => true,
        ]
    ],
];

The big difference is that the last version is DRY. If the namespace or the plugin name is changed, I can just change it in one place.

Also plugins with the same author will be nicely grouped together when they use the same namespace.

This issue was moved by bastianallgeier from k-next/kirby#761.

@bnomei commented on Jul 27, 2018, 5:32 AM UTC:

(removed my post since i missunderstood question) XD

@bnomei commented on Jul 27, 2018, 7:47 PM UTC:

not totally unrelated to DRY is total length of config files. splitting them based on plugin etc.
but rejoice – for which there is a solution:

k-next/plugins#21 (comment)

@distantnative commented on Aug 24, 2018, 9:28 AM UTC:

Related #604

@omz13 commented on Sep 1, 2018, 6:27 PM UTC:

FWIW, in the latest release of my xmlsitemap I implemented a single-level pseudo-namespace. The readme gives an example. The more interesting bit of code is below. With some recursion it could probably be extended to support multiple levels of namespace.

https://github.com/omz13/kirby3-xmlsitemap/blob/757b4130ce1ef5547f79c2ecf2a1a187b0618df1/src/xmlsitemap.php#L61-L78

i just ran into this inconsistency again but the other way around – trying to write core options like plugin options. it would be nice if both ways would work. it boils down to just imploding recursively with a ., right?

https://getkirby.com/docs/reference/system/options/session

<?php
return [
    'session.cookieName' => 'kirby_session', // will fail since using plugin syntax
    'session' => [ // will work for since its not a plugin
        'cookieName' => 'kirby_session',
    ]
];

i just ran into this inconsistency again but the other way around – trying to write core options like plugin options. it would be nice if both ways would work. it boils down to just imploding recursively with a ., right?

https://getkirby.com/docs/reference/system/options/session

<?php
return [
    'session.cookieName' => 'kirby_session', // will fail since using plugin syntax
    'session' => [ // will work for since its not a plugin
        'cookieName' => 'kirby_session',
    ]
];

This is now solved!