Experimenting with some new ways to handle config

For now I’ve chucked it on Flarum\Core as a static method, but
ultimately I think we will need a ConfigRepository abstraction (whether
it replaces or sits underneath the Flarum\Core static method I’m not
sure).

Also starting to think about multisite scenarios, I think this is
important. The Forum model could actually end up with a database table
behind it, and each forum would have its own config settings? Haven’t
really thought about it too hard yet…
This commit is contained in:
Toby Zerner 2015-05-19 10:59:57 +09:30
parent 1adfe5d867
commit 53357ad56f
3 changed files with 18 additions and 1 deletions

View File

@ -1,9 +1,20 @@
<?php namespace Flarum; <?php namespace Flarum;
use DB;
class Core class Core
{ {
public static function isInstalled() public static function isInstalled()
{ {
return file_exists(base_path('../config.php')); return file_exists(base_path('../config.php'));
} }
public static function config($key, $default = null)
{
if (is_null($value = DB::table('config')->where('key', $key)->pluck('value'))) {
$value = $default;
}
return $value;
}
} }

View File

@ -1,8 +1,14 @@
<?php namespace Flarum\Core\Models; <?php namespace Flarum\Core\Models;
use Tobscure\Permissible\Permissible; use Tobscure\Permissible\Permissible;
use Flarum\Core;
class Forum extends Model class Forum extends Model
{ {
use Permissible; use Permissible;
public function getTitleAttribute()
{
return Core::config('forum_title');
}
} }

View File

@ -18,7 +18,7 @@ class ExtensionsServiceProvider extends ServiceProvider
return; return;
} }
$extensions = json_decode(DB::table('config')->where('key', 'extensions_enabled')->pluck('value'), true); $extensions = json_decode(Core::config('extensions_enabled'), true);
$providers = []; $providers = [];
foreach ($extensions as $extension) { foreach ($extensions as $extension) {