Better Setting model which will lookup the settings and env
This commit is contained in:
@@ -1,13 +1,44 @@
|
||||
<?php
|
||||
|
||||
use \BadConfigKeyException;
|
||||
|
||||
class Setting extends Eloquent {
|
||||
public static function get($settingName) {
|
||||
/**
|
||||
* Returns a setting from the database.
|
||||
* @param string $settingName
|
||||
* @param bool $checkEnv
|
||||
* @return string
|
||||
*/
|
||||
public static function get($settingName, $checkEnv = true) {
|
||||
// Default setting value.
|
||||
$setting = null;
|
||||
|
||||
// First try finding the setting in the database.
|
||||
try {
|
||||
$setting = self::where('name', $settingName)->first()->value;
|
||||
} catch (ErrorException $e) {
|
||||
$setting = null;
|
||||
$setting = self::whereName($settingName)->first()->value;
|
||||
} catch (\ErrorException $e) {
|
||||
// If we don't have a setting, check the env (fallback for original version)
|
||||
if ($checkEnv) {
|
||||
if (!($setting = getenv(strtoupper($settingName)))) {
|
||||
self::unknownSettingException($settingName);
|
||||
}
|
||||
} else {
|
||||
self::unknownSettingException($settingName);
|
||||
}
|
||||
}
|
||||
|
||||
return $setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an BadConfigKeyException
|
||||
* @param string $setting
|
||||
* @throws BadConfigKeyException
|
||||
* @return void
|
||||
*/
|
||||
public static function unknownSettingException($setting) {
|
||||
throw new BadConfigKeyException(
|
||||
sprintf('Unknown setting %s', $settingName)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>{{ getenv('APP_NAME') }} | Cachet</title>
|
||||
<title>{{ Setting::get('app_name') }} | Cachet</title>
|
||||
<!-- Set the viewport width to device width for mobile -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="author" content="http://james-brooks.uk">
|
||||
|
||||
Reference in New Issue
Block a user