Is changing Sage namespace from 'App' supported?

Hello all. This is my first post/question so I hope I follow guidelines. I also want to note I have really enjoyed working with Trellis/Bedrock/Sage - the development experience is brilliant.

I have a Sage-based theme (let’s call it Theme) that I am developing alongside some plugins (PluginA and PluginB).

I wanted to give all of my software the same root namespace (let’s say BriggySmalls), which leads me to my question: is it not intended for the original App namespace Sage ships with to be changed?

I have been developing with a different namespace for a while now (BriggySmalls\Theme) with no issues - despite finding little discussion of it as an approach.

However release Sage 9.0.2 has introduced soberwp/controller release 2.x.x with its PSR4 autoloading which seems to depend on sharing the App namespace with Sage.

Following the controller guidance I have attempted to use the sober/controller/namespace filter to change the namespace to BriggySmalls\Theme\Controllers, however I continue to get the Class 'App' not found error in the page-header.blade.php template. Running my debugger it appears that the exception is raised before my filter is executed.

FYI: If I fully namespace App as BriggySmalls\Theme\Controllers\App then the exception is not raised.

Is there guidance for anyone wishing to change the default App namespace? Or is it discouraged? I am willing to abandon my approach if it is not supported.

Thanks in advance for any attention this question gets!

App was intended to be a placeholder, but since it’s easier just not to change anything, most people seem not to.

This is the type of thing that’d be nice to add to sage-installer similar to how Laravel has an Artisan command for this.


Thank you @knowler. I appreciate your help. I think I’ll probably revert my namespace change as it seems to complicated to do something unsupported.

I came back to this issue and discovered the cause.

soberwp\controller\controller.php uses the sage function, assuming that it is found in the default App namespace. The current version of soberwp\controller has a test for this function that returns early if the function does not exist.

This approach was first introduced in commit 760378fe0fbb52db2b622aee4ff25cd017f1d38c as part of release 2.0.0.

Hm, that is problematic. Maybe submit an issue over on that repo.

Issue opened at

1 Like