mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 09:25:28 +08:00
Add settings repository interface and database implementation.
Almost done with flarum/core#121 now.
This commit is contained in:
parent
03fd4a5aba
commit
12dd550a14
29
src/Core/DatabaseSettingsRepository.php
Normal file
29
src/Core/DatabaseSettingsRepository.php
Normal 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]);
|
||||
}
|
||||
}
|
10
src/Core/SettingsRepositoryInterface.php
Normal file
10
src/Core/SettingsRepositoryInterface.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Flarum\Core;
|
||||
|
||||
interface SettingsRepositoryInterface
|
||||
{
|
||||
public function get($key, $default = null);
|
||||
|
||||
public function set($key, $value);
|
||||
}
|
Loading…
Reference in New Issue
Block a user