1
0
mirror of https://github.com/flarum/core.git synced 2025-10-18 10:16:09 +02:00
Files
php-flarum/src/Settings/DatabaseSettingsRepository.php
Franz Liedke d492579638 Apply fixes from StyleCI
[ci skip] [skip ci]
2019-11-28 00:16:50 +00:00

51 lines
1.1 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Settings;
use Illuminate\Database\ConnectionInterface;
class DatabaseSettingsRepository implements SettingsRepositoryInterface
{
protected $database;
public function __construct(ConnectionInterface $connection)
{
$this->database = $connection;
}
public function all(): array
{
return $this->database->table('settings')->pluck('value', 'key')->all();
}
public function get($key, $default = null)
{
if (is_null($value = $this->database->table('settings')->where('key', $key)->value('value'))) {
return $default;
}
return $value;
}
public function set($key, $value)
{
$query = $this->database->table('settings')->where('key', $key);
$method = $query->exists() ? 'update' : 'insert';
$query->$method(compact('key', 'value'));
}
public function delete($key)
{
$this->database->table('settings')->where('key', $key)->delete();
}
}