Issues (25)

src/Http/Middleware/SetLocale.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Diglabby\Doika\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Carbon;
7
use Mcamara\LaravelLocalization\LaravelLocalization;
0 ignored issues
show
The type Mcamara\LaravelLocalization\LaravelLocalization was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class SetLocale
10
{
11
    /**
12
     * @var \Mcamara\LaravelLocalization\LaravelLocalization
13
     */
14
    protected $localization;
15
16
    public function __construct(LaravelLocalization $localization)
17
    {
18
        $this->localization = $localization;
19
    }
20
21
    /**
22
     * Handle an incoming request.
23
     *
24
     * @param \Illuminate\Http\Request $request
25
     * @param \Closure $next
26
     *
27
     * @throws \Mcamara\LaravelLocalization\Exceptions\SupportedLocalesNotDefined
28
     *
29
     * @return mixed
30
     */
31
    public function handle($request, Closure $next)
32
    {
33
        $currentLocale = $this->localization->getCurrentLocale();
34
        $supportedLocale = $this->localization->getSupportedLocales()[$currentLocale];
35
36
        /*
37
         * setLocale for php. Enables localized dates, format numbers, etc.
38
         */
39
        setlocale(LC_ALL,
40
            $supportedLocale['regional'],
41
            "{$supportedLocale['regional']}.utf-8",
42
            "{$supportedLocale['regional']}.iso-8859-1",
43
            $supportedLocale['locale_win']
44
        );
45
46
        /*
47
         * setLocale to use Carbon source locales. Enables diffForHumans() localized
48
         */
49
        Carbon::setLocale($currentLocale);
50
        Carbon::setUtf8(true);
51
52
        /*
53
         * Set Captcha locale
54
         */
55
        app('config')->set('no-captcha.lang', $currentLocale);
56
57
        return $next($request);
58
    }
59
}
60