Cachet/app/Providers/ConfigServiceProvider.php

81 lines
2.4 KiB
PHP
Raw Normal View History

2015-03-21 02:33:38 -06:00
<?php
/*
* This file is part of Cachet.
*
2015-05-25 17:59:08 +01:00
* (c) Cachet HQ <support@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2015-03-21 02:33:38 -06:00
namespace CachetHQ\Cachet\Providers;
2015-03-20 18:30:45 -06:00
2015-05-28 19:46:54 +01:00
use CachetHQ\Cachet\Config\Repository;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Setting as SettingModel;
use Exception;
2015-03-20 18:30:45 -06:00
use Illuminate\Support\ServiceProvider;
class ConfigServiceProvider extends ServiceProvider
{
/**
2015-05-28 19:46:54 +01:00
* Boot the service provider.
2015-03-20 18:30:45 -06:00
*
2015-05-28 19:46:54 +01:00
* @return void
*/
public function boot()
{
2015-05-28 19:54:47 +01:00
$appDomain = $appLocale = null;
2015-05-28 19:46:54 +01:00
try {
// Get app custom configuration.
$appDomain = Setting::get('app_domain');
$appLocale = Setting::get('app_locale');
// Set the Segment.com settings.
if (Setting::get('app_track')) {
$segmentRepository = $this->app->make('CachetHQ\Cachet\Segment\RepositoryInterface');
$this->app->config->set('segment.write_key', $segmentRepository->fetch());
}
// Setup Cors.
$allowedOrigins = $this->app->config->get('cors.defaults.allowedOrigins');
$allowedOrigins[] = Setting::get('app_domain');
// Add our allowed domains too.
if ($allowedDomains = Setting::get('allowed_domains')) {
$domains = explode(',', $allowedDomains);
foreach ($domains as $domain) {
$allowedOrigins[] = $domain;
}
} else {
$allowedOrigins[] = env('APP_URL');
}
$this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins);
} catch (Exception $e) {
// Don't throw any errors, we may not be setup yet.
}
// Override default app values.
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url'));
$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
2015-03-20 18:30:45 -06:00
*/
public function register()
{
2015-05-28 19:46:54 +01:00
$this->app->bindShared('setting', function () {
return new Repository(new SettingModel());
});
2015-03-20 18:30:45 -06:00
}
}