Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
piotrku opened this issue Jun 14, 2021 · 1 comment
Open
Assignees
Labels

Comments

@piotrku
Copy link

piotrku commented Jun 14, 2021

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?

@atanas-dev
Copy link
Contributor

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 atanas-dev self-assigned this Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants