Merge pull request #381 from JoeForks/fix/move-loadconfig

Move load config to ServiceProvider and Lang array.
This commit is contained in:
Joe Cohen 2015-01-14 16:06:16 -06:00
commit e369e44792
7 changed files with 58 additions and 34 deletions

View File

@ -145,6 +145,7 @@ return [
'CachetHQ\Cachet\Providers\RepositoryServiceProvider',
'CachetHQ\Cachet\Providers\RoutingServiceProvider',
'CachetHQ\Cachet\Providers\ViewComposerServiceProvider',
'CachetHQ\Cachet\Providers\LoadConfigServiceProvider',
],

9
app/config/langs.php Normal file
View File

@ -0,0 +1,9 @@
<?php
return [
// Enabled langs
'de' => 'Deutsch',
'en' => 'English',
'fr' => 'Français',
'pt-BR' => 'Portuguese, Brazilian',
];

View File

@ -4,6 +4,7 @@ namespace CachetHQ\Cachet\Composers;
use DateTime;
use DateTimeZone;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View;
class TimezoneLocaleComposer
@ -17,10 +18,12 @@ class TimezoneLocaleComposer
*/
public function compose(\Illuminate\View\View $view)
{
$langs = array_map(function ($lang) {
$enabledLangs = Config::get('langs');
$langs = array_map(function ($lang) use ($enabledLangs) {
$locale = basename($lang);
return [$locale => ucwords(locale_get_display_name($locale, $locale))];
return [$locale => $enabledLangs[$locale]];
}, glob(app_path('lang').'/*'));
$langs = call_user_func_array('array_merge', $langs);

View File

@ -1,31 +0,0 @@
<?php
namespace CachetHQ\Cachet\Http\Before;
use CachetHQ\Cachet\Models\Setting;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Lang;
class LoadConfigFilter
{
/**
* Load confit to override values filter.
*
* @param \Illuminate\Http\Request $request
*
* @return null
*/
public function filter(Request $request)
{
// Always allow our own domain.
$appDomain = Setting::get('app_domain');
$appTimezone = Setting::get('app_timezone');
$appLocale = Setting::get('app_locale');
Config::set('app.url', $appDomain ?: Config::get('app.url'));
Config::set('app.timezone', $appTimezone ?: Config::get('app.timezone'));
Config::set('app.locale', $appLocale ?: Config::get('app.locale'));
Lang::setLocale($appLocale);
}
}

View File

@ -6,6 +6,7 @@ use CachetHQ\Cachet\Models\Setting;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
@ -168,6 +169,8 @@ class DashSettingsController extends Controller
return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure'));
}
Lang::setLocale(Binput::get('app_locale'));
return Redirect::back()->with('success', trans('dashboard.settings.edit.success'));
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace CachetHQ\Cachet\Providers;
use CachetHQ\Cachet\Models\Setting;
use Illuminate\Support\ServiceProvider;
class LoadConfigServiceProvider extends ServiceProvider
{
/**
* Boot the service provider.
*
* @return void
*/
public function boot()
{
// Get app custom configuration.
$appDomain = Setting::get('app_domain');
$appTimezone = Setting::get('app_timezone');
$appLocale = Setting::get('app_locale');
// Override default app values.
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url'));
$this->app->config->set('app.timezone', $appTimezone ?: $this->app->config->get('app.timezone'));
$this->app->config->set('app.locale', $appLocale ?: $this->app->config->get('app.locale'));
// Set custom lang.
$this->app->translator->setLocale($appLocale);
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
}

View File

@ -41,7 +41,6 @@ class RoutingServiceProvider extends ServiceProvider
$this->app->router->filter('csrf', 'CachetHQ\Cachet\Http\Before\CsrfFilter');
// Cachet's before filters
$this->app->router->before('CachetHQ\Cachet\Http\Before\LoadConfigFilter');
$this->app->router->filter('is_setup', 'CachetHQ\Cachet\Http\Before\IsSetupFilter');
$this->app->router->filter('has_setting', 'CachetHQ\Cachet\Http\Before\HasSettingFilter');
$this->app->router->filter('login_throttling', 'CachetHQ\Cachet\Http\Before\LoginThrottlingFilter');