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

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

Open
pagegwood opened this issue Jan 28, 2022 · 3 comments
Labels

Comments

@pagegwood
Copy link

pagegwood commented Jan 28, 2022

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,

@pagegwood pagegwood changed the title Cannot override /config/app.php in theme on multisite install Cannot override Class aliases in /config/app.php within theme on multisite install Jan 28, 2022
@jlambe jlambe added the feature label Jan 28, 2022
@jlambe
Copy link
Contributor

jlambe commented Jan 28, 2022

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.

@michaelmano
Copy link

michaelmano commented Mar 4, 2022

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.

@jlambe
Copy link
Contributor

jlambe commented May 31, 2022

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

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

3 participants