-
-
Notifications
You must be signed in to change notification settings - Fork 170
Description
The fallback logic should get moved out of the trait into dedicated class(es) which could be easily replaced by custom user logic without adjusting the whole trait.
It should be possible to chain multiple strategies to handle the current state but in multiple classes.
'fallback_strategies' => [
LocaleStrategy::class => [
'locale' => 'en',
],
CountryLocaleStrategy::class,
FirstDefinedLocaleStrategy::class,
],
A strategy instance should be created via DIC - this way an instance could also be bound, possible required injections will be done and custom arguments could be passed via an array like for LocaleStrategy
.
The signature of called method should retrieve a lot of arguments to also handle model aware logic, attribute specific fallback and so on.
$strategy->fallback(
Model $model,
string $currentLocale,
Collection $alreadyCheckedLocales,
?string $attribute = null,
): ?Model;
The method should return an instance of the translatable model or throw an exception FallbackNotFound
which contains all checked localesnull
.
Every checked locale should be pushed to the collection. This way we can pass all already checked locales to the following strategies and prevent duplicated checks.