themosis / framework

The Themosis framework core.

Home Page:https://framework.themosis.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot override Class aliases in /config/app.php within theme on multisite install

pagegwood opened this issue · comments

commented

I could see this one viewed as a bug report, or a feature suggestion. Either way, kudos to everyone involved in this amazing framework.

Themosis 2.0 is great in that it more closely resembles the Laravel framework. It has, however, been challenging to work with for multisite installations that leverage multiple themes. One of the pain points would be related to loading class aliases.

Previously you would define all class aliases in a config file within a Themosis theme. Now, this is done in config/app.php in the root of the project.

I just attempted to override some of these class aliases by loading a new file in theme}/config/app.php and had no such luck.

For now I am prefixing class aliases in /config/app.php for each site, which feels a bit dirty. Example,

'Site1' => App\Site1\Option\Site::class,
'Site2' => App\Site2\Option\Site::class,

I can see this. This is something that we could focus on perhaps at some point. We had the chance to work on multi-tenancy project recently and perhaps there is some learning there that could help us built a good solution to resolve this. Any following suggestions or ideas is very welcomed at this moment though so feel free, anyone, to add comments to this issue.

Not a solution but what we do is

    'aliases' => include $_SERVER['HTTP_HOST'].'.aliases.php',

Then make a file in the config dir named domain.aliases.php and return the array required. (probably a much better way of doing this by knowing which theme is loaded so on.. also not safe.

Another approach would be a plugin also. If the root contains all shared code for all instances, if you need specific features for a specific sub-site, a plugin holding its own configuration with class aliases will also fit as you can activate them per site only.

For what I've learned, changing sub-site shouldn't need to use different classes. Having classes at the root that are only used by one sub-site theme for example is definitely working using the full classname. Aliases are handled through a core class called "AliasLoader" which we have access to from a theme functions.php file for example. From there, I think it's possible to register aliases for your theme like so:

use Themosis\Core\AliasLoader;

AliasLoader::getInstance(config('theme.aliases', []))
    ->register();

@pagegwood FYI