From 279475df03115dc25a448cc5969ddf56ea1bd6ca Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 3 Jan 2017 14:33:22 +0000 Subject: [PATCH] Use settings repository --- app/Http/Middleware/Localize.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/Http/Middleware/Localize.php b/app/Http/Middleware/Localize.php index 6ac7cc9db730..02a5434afc3f 100644 --- a/app/Http/Middleware/Localize.php +++ b/app/Http/Middleware/Localize.php @@ -11,9 +11,10 @@ namespace CachetHQ\Cachet\Http\Middleware; +use CachetHQ\Cachet\Settings\Repository as SettingsRepository; use Carbon\Carbon; use Closure; -use Illuminate\Config\Repository; +use Illuminate\Contracts\Config\Repository as ConfigRepository; use Illuminate\Http\Request; /** @@ -26,30 +27,31 @@ class Localize { /** - * Array of languages Cachet can use. + * The config repository instance. * - * @var string[] + * @var \Illuminate\Contracts\Config\Repository */ - protected $langs; + protected $config; /** - * The config repository instance. + * The settings repository instance. * - * @var \Illuminate\Config\Repository + * @var \CachetHQ\Cachet\Settings\Repository */ - protected $config; + protected $settings; /** * Constructs a new localize middleware instance. * - * @param \Illuminate\Config\Repository $config + * @param \Illuminate\Contracts\Config\Repository $config + * @param \CachetHQ\Cachet\Settings\Repository $settings * * @return void */ - public function __construct(Repository $config) + public function __construct(ConfigRepository $config, SettingsRepository $settings) { $this->config = $config; - $this->langs = $config->get('langs'); + $this->settings = $settings; } /** @@ -62,17 +64,18 @@ public function __construct(Repository $config) */ public function handle(Request $request, Closure $next) { - if (!(bool) $this->config->get('setting.automatic_localization')) { + if (!(bool) $this->settings->get('automatic_localization')) { return $next($request); } - $supportedLanguages = $request->getLanguages(); + $requestedLanguages = $request->getLanguages(); $userLanguage = $this->config->get('app.locale'); + $langs = $this->config->get('langs'); - foreach ($supportedLanguages as $language) { + foreach ($requestedLanguages as $language) { $language = str_replace('_', '-', $language); - if (isset($this->langs[$language])) { + if (isset($langs[$language])) { $userLanguage = $language; break; }