Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

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

Closed
ghost opened this issue Oct 25, 2018 · 7 comments
Closed

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

ghost opened this issue Oct 25, 2018 · 7 comments

Comments

@ghost
Copy link

ghost commented Oct 25, 2018

@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.

@ghost
Copy link
Author

ghost commented Oct 25, 2018

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

(removed my post since i missunderstood question) XD

@ghost
Copy link
Author

ghost commented Oct 25, 2018

@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)

@ghost
Copy link
Author

ghost commented Oct 25, 2018

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

Related #604

@ghost
Copy link
Author

ghost commented Oct 25, 2018

@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

@bnomei
Copy link

bnomei commented Feb 24, 2019

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',
    ]
];

1 similar comment
@bnomei
Copy link

bnomei commented Feb 24, 2019

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',
    ]
];

@bastianallgeier
Copy link
Member

This is now solved!

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

No branches or pull requests

3 participants