mirror of
https://github.com/flarum/core.git
synced 2025-10-11 23:14:29 +02:00
Some fixes to get along with the new bootstrapping
This commit is contained in:
46
src/Core/DatabaseServiceProvider.php
Normal file
46
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user