Closed lcharette closed 8 months ago
~After looking further into this, the following solution has been implemented for 5.1 release :~
~1. Locator's location must have unique names, otherwise an exception will be thrown (fix a real issue with locator);
sprinkle:list
bakery command;debug:twig
bakery function has been added. It displays each namespace, with the path it point to.~~tl;dr : Two sprinkle can have the same name, as long as they don't have the same package name (which shouldn't be, because of Composer). Plus, Twig namespace will be changed from @adminlte-theme
to @userfrosting/theme-adminlte
.~
Scratch that, Twig namespaces doesn't support /
in it 🤦♂️
Alright, let do this once again.
After looking further into this, the following solution has been implemented for 5.1 release :
debug:twig
bakery function has been added. It displays each namespace, with the path it point to.tl;dr : Two sprinkle still can't have the same name, but now a proper exception will be thrown instead of silently removing a location. Twig namespace can be found using debug:twig
.
To reproduce
php bakery debug:locator
everything works fine
My Application
toAdmin Sprinkle
php bakery debug:locator
againNotice the original "Admin Sprinkle" is gone. All Admin routes returns an error.
Changing Sprinkle name from
My Application
toCore Sprinkle
is even worst, since default configuration files are not found anymore.The cause
Routes locations are stores by name here : https://github.com/userfrosting/framework/blob/c71ea13d8d91d0572d0255c2d13464c24baf628c/src/UniformResourceLocator/ResourceLocator.php#L239
And each sprinkle register it's location here, using the sprinkle name as the location name : https://github.com/userfrosting/sprinkle-core/blob/6695e47c182fafe93db93f971433634861ba1a11/app/src/ServicesProvider/LocatorService.php#L38
It doesn't help that slugs are derived from sprinkle name: https://github.com/userfrosting/framework/blob/c71ea13d8d91d0572d0255c2d13464c24baf628c/src/UniformResourceLocator/ResourceLocation.php#L55-L58
And finally Twig namespaces are using the route slugs (which is not ideal on it's own) : https://github.com/userfrosting/sprinkle-core/blob/6695e47c182fafe93db93f971433634861ba1a11/app/src/ServicesProvider/TwigService.php#L50
This is obviously an issue, as the sprinkle name should be for display purpose only. Plus, renaming a sprinkle could break Twig namespace feature, which is no good.
The solution
The solution is a bit complex, but an opportunity for further improvement at the same time.
removeLocation
andgetLocation
needs to be changed from name to slug as the argument [BC]{vendor}/{package}
format could be used as our sprinkle unique slugs. This could be helpful to get info from composer about each sprinkle (eg. installed version of a sprinkle for debug purposes). Another solution would be the recipe FQN, but this wouldn't work with the Twig namespace thing.The other solution would be to store Locations not based on anything (add them to a simple array instead of associative array). However, this solutions means it's ~not longer possible~ way harder for a location to be removed.
Location path could also be used instead of slug, but I'm not sure it's the right solution. For one, Twig namespace still needs be be tied to the location, not the sprinkle, as a sprinkle can still have a second, manual, location...
Fixing this will require a breaking change in both Framework and Core-sprinkle , so it can't be fixed on the 5.0 branch, hence marking it for 5.1. I'm creating this issue to track progress on this, and as a note if anyone encounter this issue.