Skip to content

Commit

Permalink
Use settings repository
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Jan 3, 2017
1 parent c4c1192 commit 279475d
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions app/Http/Middleware/Localize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
Expand Down

0 comments on commit 279475d

Please sign in to comment.