Move settings to config namespace

This commit is contained in:
Joseph Cohen
2015-01-16 00:04:14 -06:00
parent 4f250db260
commit 0f2c9005b1
4 changed files with 9 additions and 9 deletions

68
src/Config/Repository.php Normal file
View File

@@ -0,0 +1,68 @@
<?php
namespace CachetHQ\Cachet\Config;
use Illuminate\Database\Eloquent\Model;
class Repository
{
/**
* The eloquent model instance.
*
* @var \CachetHQ\Cachet\Models\Setting
*/
protected $model;
/**
* Cache of the settings.
*
* @var null|array
*/
protected $settings = null;
/**
* Create a new settings service instance.
*
* @param \CachetHQ\Cachet\Models\Setting $model
*
* @return void
*/
public function __construct(Model $model)
{
$this->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;
}
}