Add settings repository interface and database implementation.

Almost done with flarum/core#121 now.
This commit is contained in:
Franz Liedke 2015-07-01 23:08:26 +02:00
parent 03fd4a5aba
commit 12dd550a14
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace Flarum\Core;
use Illuminate\Database\ConnectionInterface;
class DatabaseSettingsRepository implements SettingsRepositoryInterface
{
protected $database;
public function __construct(ConnectionInterface $connection)
{
$this->database = $connection;
}
public function get($key, $default = null)
{
if (is_null($value = $this->database->table('config')->where('key', $key)->pluck('value'))) {
return $default;
}
return $value;
}
public function set($key, $value)
{
$this->database->table('config')->where('key', $key)->update(['value' => $value]);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Flarum\Core;
interface SettingsRepositoryInterface
{
public function get($key, $default = null);
public function set($key, $value);
}