Remove last remaining usage of DB facade

This commit is contained in:
Franz Liedke 2015-06-09 02:40:02 +02:00
parent 29847698c5
commit 6994f71757
6 changed files with 176 additions and 10 deletions

View File

@ -34,7 +34,7 @@ class CreatePostsTable extends Migration
$table->engine = 'MyISAM';
});
DB::statement('ALTER TABLE posts ADD FULLTEXT content (content)');
app('db')->statement('ALTER TABLE posts ADD FULLTEXT content (content)');
}
/**

View File

@ -6,7 +6,6 @@ use Flarum\Support\Actor;
use Flarum\Support\HtmlAction;
use Session;
use Config;
use DB;
use Psr\Http\Message\ServerRequestInterface as Request;
class IndexAction extends HtmlAction
@ -23,7 +22,7 @@ class IndexAction extends HtmlAction
protected function render(Request $request, $routeParams = [])
{
$config = DB::table('config')->whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key');
$config = app('db')->table('config')->whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key');
$data = [];
$session = [];
$alert = Session::get('alert');

View File

@ -0,0 +1,169 @@
<?php
namespace Flarum\Core;
use Illuminate\Container\Container;
use Illuminate\Contracts\Foundation\Application as LaravelApplication;
class Application extends Container implements LaravelApplication
{
/**
* @var string
*/
protected $basePath;
/**
* @var array
*/
protected $serviceProviders = [];
/**
* @var array
*/
protected $bootingListeners = [];
/**
* @var array
*/
protected $bootedListeners = [];
/**
* Create the application instance.
*
* @param $basePath
*/
public function __construct($basePath)
{
$this->basePath = $basePath;
}
/**
* Get the version number of the application.
*
* @return string
*/
public function version()
{
return '1.0.dev';
}
/**
* Get the base path of the Laravel installation.
*
* @return string
*/
public function basePath()
{
return $this->basePath;
}
/**
* Get or check the current application environment.
*
* @param mixed
* @return string
*/
public function environment()
{
return 'production';
}
/**
* Determine if the application is currently down for maintenance.
*
* @return bool
*/
public function isDownForMaintenance()
{
return false;
}
/**
* Register all of the configured providers.
*
* @return void
*/
public function registerConfiguredProviders()
{
foreach ($this->serviceProviders as $provider) {
$provider->register();
}
}
/**
* Register a service provider with the application.
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @param array $options
* @param bool $force
* @return \Illuminate\Support\ServiceProvider
*/
public function register($provider, $options = array(), $force = false)
{
$this->serviceProviders[] = $provider;
}
/**
* Register a deferred provider and service.
*
* @param string $provider
* @param string $service
* @return void
*/
public function registerDeferredProvider($provider, $service = null)
{
$this->register($provider);
}
/**
* Boot the application's service providers.
*
* @return void
*/
public function boot()
{
$this->fireListeners($this->bootingListeners);
foreach ($this->serviceProviders as $provider) {
$this->call([$provider, 'boot']);
}
$this->fireListeners($this->bootedListeners);
}
/**
* Register a new boot listener.
*
* @param mixed $callback
* @return void
*/
public function booting($callback)
{
$this->bootingListeners[] = $callback;
}
/**
* Register a new "booted" listener.
*
* @param mixed $callback
* @return void
*/
public function booted($callback)
{
$this->bootedListeners[] = $callback;
}
/**
* Fire the given array of listener callbacks.
*
* @param array $listeners
* @return void
*/
protected function fireListeners(array $listeners)
{
foreach ($listeners as $listener)
{
$listener($this);
}
}
}

View File

@ -2,13 +2,12 @@
use Flarum\Core\Models\Notification;
use Flarum\Core\Models\User;
use DB;
class EloquentNotificationRepository implements NotificationRepositoryInterface
{
public function findByUser(User $user, $limit = null, $offset = 0)
{
$primaries = Notification::select(DB::raw('MAX(id) AS id'), DB::raw('SUM(is_read = 0) AS unread_count'))
$primaries = Notification::select(app('db')->raw('MAX(id) AS id'), app('db')->raw('SUM(is_read = 0) AS unread_count'))
->where('user_id', $user->id)
->whereIn('type', array_filter(array_keys(Notification::getTypes()), [$user, 'shouldAlert']))
->where('is_deleted', false)
@ -20,7 +19,7 @@ class EloquentNotificationRepository implements NotificationRepositoryInterface
return Notification::with('subject')
->select('notifications.*', 'p.unread_count')
->mergeBindings($primaries->getQuery())
->join(DB::raw('('.$primaries->toSql().') p'), 'notifications.id', '=', 'p.id')
->join(app('db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', 'p.id')
->orderBy('time', 'desc')
->get();
}

View File

@ -1,7 +1,6 @@
<?php namespace Flarum\Core\Seeders;
use Illuminate\Database\Seeder;
use DB;
class ConfigTableSeeder extends Seeder
{
@ -26,7 +25,7 @@ class ConfigTableSeeder extends Seeder
'theme_colored_header' => false,
];
DB::table('config')->insert(array_map(function ($key, $value) {
app('db')->table('config')->insert(array_map(function ($key, $value) {
return compact('key', 'value');
}, array_keys($config), $config));
}

View File

@ -29,5 +29,5 @@ foreach ($permissions as &$permission) {
'permission' => $permission[2]
];
}
\DB::table('permissions')->truncate();
\DB::table('permissions')->insert($permissions);
app('db')->table('permissions')->truncate();
app('db')->table('permissions')->insert($permissions);