wpemerge icon indicating copy to clipboard operation
wpemerge copied to clipboard

Default class namespace prefix - config option (feature request?)

Open piotrku opened this issue 3 years ago • 1 comments

Version

0.16.0

Expected behavior

Config option to set custom namespace prefix

Actual behavior

I see it in the WP Emerge Starter Theme but no effect here

Comments

Not actually an issue but I cannot find another way of contact.

Is it a good practice to use in my project the default \App namespace? Won't this cause problems when I install by some chance some other library using the same generic namespace?

I see your WP Emerge Starter Theme uses its own, custom namespace MyApp\\ which is defined in the config file. Here I cannot find a way to define something like the default namespace, so the first problem I encountered was the controller - I have overcome that by prefixing the controller class like: ->handle('WPLar\Controllers\Web\HomeController@index'); but one thing - this is not very convenient and the second thing - will I have more problems like this further on the way where the default \App namespace will create some unexpected behaviours and problems for me?

piotrku avatar Jun 14 '21 20:06 piotrku

Hi @piotrku ,

Not actually an issue but I cannot find another way of contact.

That's fine, using an issue as a feature request is OK in my book. If you don't feel like posting an issue for such things you can hop for a quick chat on https://gitter.im/wpemerge/Lobby, for example.

Is it a good practice to use in my project the default \App namespace?

It is not for the exact reason you mentioned - potential namespace conflicts.

Here I cannot find a way to define something like the default namespace

It seems I've not made this clear but there is a way to specify a default namespace via the 'attributes' key of the routes configuration: https://docs.wpemerge.com/#/framework/configuration By passing something like this:

'routes' => [
        'web'   => [
            'definitions' => get_template_directory() . '/routes/web.php',
            'attributes'  => [ 'namespace' => 'WPLar\\Controllers\\Web\\' ],
        ],
        // ...

You can see how the same approach is used in WP Emerge itself here: https://github.com/htmlburger/wpemerge/blob/0.16.0/src/Routing/RoutingServiceProvider.php#L54

In the next version there will be a top-level configuration option for a default namespace as the above is neither obvious nor too convenient.

Hope that helps :)

atanas-dev avatar Jun 14 '21 21:06 atanas-dev