diff --git a/app/config/app.php b/app/config/app.php index 9ca2cde3..a4d5eebc 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -147,6 +147,7 @@ return [ 'CachetHQ\Cachet\Providers\RoutingServiceProvider', 'CachetHQ\Cachet\Providers\ViewComposerServiceProvider', 'CachetHQ\Cachet\Providers\LoadConfigServiceProvider', + 'CachetHQ\Cachet\Providers\SettingsServiceProvider', ], @@ -185,7 +186,7 @@ return [ 'Response' => 'Illuminate\Support\Facades\Response', 'Route' => 'Illuminate\Support\Facades\Route', 'Session' => 'Illuminate\Support\Facades\Session', - 'Setting' => 'CachetHQ\Cachet\Models\Setting', + 'Setting' => 'CachetHQ\Cachet\Facades\Setting', 'Str' => 'Illuminate\Support\Str', ], diff --git a/app/config/packages/fideloper/proxy/config.php b/app/config/packages/fideloper/proxy/config.php index 8eec3191..7ea52c28 100644 --- a/app/config/packages/fideloper/proxy/config.php +++ b/app/config/packages/fideloper/proxy/config.php @@ -1,5 +1,5 @@ array( + 'proxies' => [ '204.93.240.0', '204.93.177.0', '199.27.128.0', @@ -46,6 +46,6 @@ return array( '2803:f800::', '2405:b500::', '2405:8100::', - ) + ], -); +]; diff --git a/app/database/seeds/UsersTableSeeder.php b/app/database/seeds/UsersTableSeeder.php index 66f4828c..6dbdc90d 100644 --- a/app/database/seeds/UsersTableSeeder.php +++ b/app/database/seeds/UsersTableSeeder.php @@ -21,7 +21,7 @@ class UsersTableSeeder extends Seeder "password" => "test123", "email" => "test@test.com", "level" => 1, - ] + ], ]; User::truncate(); diff --git a/src/Config/Repository.php b/src/Config/Repository.php new file mode 100644 index 00000000..b8350b8a --- /dev/null +++ b/src/Config/Repository.php @@ -0,0 +1,68 @@ +model = $model; + } + + /** + * Returns a setting from the database. + * + * @param string $settingName + * @param bool $checkEnv + * + * @return string|null + */ + public function get($settingName, $checkEnv = true) + { + $setting = null; + + try { + if (! $this->settings) { + $this->settings = $this->model->all()->lists('value', 'name'); + } + + if (array_key_exists($settingName, $this->settings)) { + return $this->settings[$settingName]; + } + } catch (ErrorException $e) { + if ($checkEnv) { + $env = getenv(strtoupper($settingName)); + if (!$env) { + return $env; + } + } + + return $setting; + } + + return $setting; + } +} diff --git a/src/Facades/Setting.php b/src/Facades/Setting.php new file mode 100644 index 00000000..3fb453ea --- /dev/null +++ b/src/Facades/Setting.php @@ -0,0 +1,21 @@ + '']; - - /** - * Returns a setting from the database. - * - * @param string $settingName - * @param bool $checkEnv - * - * @return string|null - */ - public static function get($settingName, $checkEnv = true) - { - $setting = null; - - try { - $setting = self::whereName($settingName)->first()->value; - } catch (ErrorException $e) { - if ($checkEnv) { - $env = getenv(strtoupper($settingName)); - if (!$env) { - return $env; - } - } - - return $setting; - } - - return $setting; - } } diff --git a/src/Providers/LoadConfigServiceProvider.php b/src/Providers/LoadConfigServiceProvider.php index 9cf3221b..6ca2c83c 100644 --- a/src/Providers/LoadConfigServiceProvider.php +++ b/src/Providers/LoadConfigServiceProvider.php @@ -2,7 +2,7 @@ namespace CachetHQ\Cachet\Providers; -use CachetHQ\Cachet\Models\Setting; +use CachetHQ\Cachet\Facades\Setting; use Illuminate\Database\QueryException; use Illuminate\Support\ServiceProvider; diff --git a/src/Providers/SettingsServiceProvider.php b/src/Providers/SettingsServiceProvider.php new file mode 100644 index 00000000..6f2485fa --- /dev/null +++ b/src/Providers/SettingsServiceProvider.php @@ -0,0 +1,32 @@ +app->bindShared('setting', function ($app) { + return new Repository(new SettingModel()); + }); + } +}