Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| LaravelLocaleContextBuilder | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
5.03 | |
0.00% |
0 / 1 |
| process | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
5.03 | |||
| 1 | <?php |
| 2 | namespace Apie\LaravelApie\ContextBuilders; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Apie\Core\ContextBuilders\ContextBuilderInterface; |
| 6 | use Apie\Core\ContextConstants; |
| 7 | use Illuminate\Support\Facades\App; |
| 8 | |
| 9 | final class LaravelLocaleContextBuilder implements ContextBuilderInterface |
| 10 | { |
| 11 | public function process(ApieContext $context): ApieContext |
| 12 | { |
| 13 | $locale = App::getLocale(); |
| 14 | if (!$locale) { |
| 15 | return $context; |
| 16 | } |
| 17 | |
| 18 | if (!$context->hasContext(ContextConstants::LOCALE)) { |
| 19 | $context = $context->withContext(ContextConstants::LOCALE, $locale); |
| 20 | } |
| 21 | if (!$context->hasContext(ContextConstants::ACCEPT_LOCALE)) { |
| 22 | $context = $context->withContext(ContextConstants::ACCEPT_LOCALE, $locale); |
| 23 | } |
| 24 | if (!$context->hasContext(ContextConstants::DATA_LOCALE)) { |
| 25 | $context = $context->withContext(ContextConstants::DATA_LOCALE, $locale); |
| 26 | } |
| 27 | |
| 28 | return $context; |
| 29 | } |
| 30 | } |