Cachet is now a Laravel 5 app

This commit is contained in:
Joseph Cohen
2015-03-20 18:30:45 -06:00
parent 7cfa158e68
commit b4ac66d727
338 changed files with 4164 additions and 4114 deletions

79
app/Config/Repository.php Normal file
View File

@@ -0,0 +1,79 @@
<?php
namespace CachetHQ\Cachet\Config;
use CachetHQ\Cachet\Models\Setting;
class Repository
{
/**
* The eloquent model instance.
*
* @var \CachetHQ\Cachet\Models\Setting
*/
protected $model;
/**
* Cache of the settings.
*
* @var array|null
*/
protected $settings;
/**
* Create a new settings service instance.
*
* @param \CachetHQ\Cachet\Models\Setting $model
*
* @return void
*/
public function __construct(Setting $model)
{
$this->model = $model;
}
/**
* Returns a setting from the database.
*
* @param string $name
* @param bool $checkEnv
*
* @return string|null
*/
public function get($name, $checkEnv = true)
{
// if we've not loaded the settings, load them now
if (!$this->settings) {
$this->settings = $this->model->all()->lists('value', 'name');
}
// if the setting exists, return it
if (isset($this->settings[$name])) {
return $this->settings[$name];
}
// fallback to getenv if allowed to
if ($checkEnv) {
return $this->settings[$name] = getenv(strtoupper($name));
}
}
/**
* Creates or updates a setting value.
*
* @param string $name
* @param string $value
*
* @return void
*/
public function set($name, $value)
{
// save the change to the db
$this->model->updateOrCreate(compact('name'), compact('value'));
// if we've loaded the settings, persist this change
if ($this->settings) {
$this->settings[$name] = $value;
}
}
}