mirror of
https://github.com/flarum/core.git
synced 2025-08-04 15:37:51 +02:00
Some fixes to get along with the new bootstrapping
This commit is contained in:
@@ -4,7 +4,7 @@ class Core
|
|||||||
{
|
{
|
||||||
public static function isInstalled()
|
public static function isInstalled()
|
||||||
{
|
{
|
||||||
return file_exists(base_path('../config.php'));
|
return app()->bound('flarum.config');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function inDebugMode()
|
public static function inDebugMode()
|
||||||
@@ -18,7 +18,7 @@ class Core
|
|||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($value = app('db')->table('config')->where('key', $key)->pluck('value'))) {
|
if (is_null($value = app('flarum.db')->table('config')->where('key', $key)->pluck('value'))) {
|
||||||
$value = $default;
|
$value = $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
46
framework/core/src/Core/DatabaseServiceProvider.php
Normal file
46
framework/core/src/Core/DatabaseServiceProvider.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php namespace Flarum\Core;
|
||||||
|
|
||||||
|
use Flarum\Core;
|
||||||
|
use Flarum\Support\ServiceProvider;
|
||||||
|
use Illuminate\Database\ConnectionResolver;
|
||||||
|
use Illuminate\Database\Connectors\ConnectionFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use PDO;
|
||||||
|
|
||||||
|
class DatabaseServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register the service provider.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->singleton('flarum.db', function () {
|
||||||
|
$factory = new ConnectionFactory($this->app);
|
||||||
|
$connection = $factory->make($this->app->make('flarum.config')['database']);
|
||||||
|
$connection->setEventDispatcher($this->app->make('Illuminate\Contracts\Events\Dispatcher'));
|
||||||
|
$connection->setFetchMode(PDO::FETCH_CLASS);
|
||||||
|
return $connection;
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->app->alias('flarum.db', 'Illuminate\Database\ConnectionInterface');
|
||||||
|
|
||||||
|
$this->app->singleton('Illuminate\Database\ConnectionResolverInterface', function () {
|
||||||
|
$resolver = new ConnectionResolver([
|
||||||
|
'flarum' => $this->app->make('flarum.db'),
|
||||||
|
]);
|
||||||
|
$resolver->setDefaultConnection('flarum');
|
||||||
|
return $resolver;
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->app->alias('Illuminate\Database\ConnectionResolverInterface', 'db');
|
||||||
|
|
||||||
|
if (Core::isInstalled()) {
|
||||||
|
$this->app->booting(function() {
|
||||||
|
$resolver = $this->app->make('Illuminate\Database\ConnectionResolverInterface');
|
||||||
|
Model::setConnectionResolver($resolver);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -9,7 +9,7 @@ use Flarum\Forum\Events\RenderView;
|
|||||||
use Flarum\Locale\JsCompiler as LocaleJsCompiler;
|
use Flarum\Locale\JsCompiler as LocaleJsCompiler;
|
||||||
use Flarum\Support\Actor;
|
use Flarum\Support\Actor;
|
||||||
use Flarum\Support\HtmlAction;
|
use Flarum\Support\HtmlAction;
|
||||||
use Illuminate\Database\DatabaseManager;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||||
|
|
||||||
@@ -25,8 +25,7 @@ class IndexAction extends HtmlAction
|
|||||||
|
|
||||||
public static $translations = [];
|
public static $translations = [];
|
||||||
|
|
||||||
// TODO: DatabaseManager should be ConnectionInterface
|
public function __construct(Client $apiClient, Actor $actor, ConnectionInterface $database, SessionInterface $session)
|
||||||
public function __construct(Client $apiClient, Actor $actor, DatabaseManager $database, SessionInterface $session)
|
|
||||||
{
|
{
|
||||||
$this->apiClient = $apiClient;
|
$this->apiClient = $apiClient;
|
||||||
$this->actor = $actor;
|
$this->actor = $actor;
|
||||||
|
Reference in New Issue
Block a user