mirror of
https://github.com/flarum/core.git
synced 2025-08-02 14:37:49 +02:00
Add settings repository interface and database implementation.
Almost done with flarum/core#121 now.
This commit is contained in:
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);
|
||||||
|
}
|
Reference in New Issue
Block a user