diff --git a/framework/core/migrations/2015_02_24_000000_create_posts_table.php b/framework/core/migrations/2015_02_24_000000_create_posts_table.php index da534bae1..8a3fc96aa 100644 --- a/framework/core/migrations/2015_02_24_000000_create_posts_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_posts_table.php @@ -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)'); } /** diff --git a/framework/core/src/Admin/Actions/IndexAction.php b/framework/core/src/Admin/Actions/IndexAction.php index 10e8dad67..15fea7ab8 100644 --- a/framework/core/src/Admin/Actions/IndexAction.php +++ b/framework/core/src/Admin/Actions/IndexAction.php @@ -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'); diff --git a/framework/core/src/Core/Application.php b/framework/core/src/Core/Application.php new file mode 100644 index 000000000..b9a40dca4 --- /dev/null +++ b/framework/core/src/Core/Application.php @@ -0,0 +1,169 @@ +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); + } + } +} \ No newline at end of file diff --git a/framework/core/src/Core/Repositories/EloquentNotificationRepository.php b/framework/core/src/Core/Repositories/EloquentNotificationRepository.php index bece07e40..2590c48c2 100644 --- a/framework/core/src/Core/Repositories/EloquentNotificationRepository.php +++ b/framework/core/src/Core/Repositories/EloquentNotificationRepository.php @@ -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(); } diff --git a/framework/core/src/Core/Seeders/ConfigTableSeeder.php b/framework/core/src/Core/Seeders/ConfigTableSeeder.php index 96d58846e..f692379dc 100644 --- a/framework/core/src/Core/Seeders/ConfigTableSeeder.php +++ b/framework/core/src/Core/Seeders/ConfigTableSeeder.php @@ -1,7 +1,6 @@ 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)); } diff --git a/framework/core/tests/api/_bootstrap.php b/framework/core/tests/api/_bootstrap.php index d5fb59d60..2acb9aae7 100644 --- a/framework/core/tests/api/_bootstrap.php +++ b/framework/core/tests/api/_bootstrap.php @@ -29,5 +29,5 @@ foreach ($permissions as &$permission) { 'permission' => $permission[2] ]; } -\DB::table('permissions')->truncate(); -\DB::table('permissions')->insert($permissions); \ No newline at end of file +app('db')->table('permissions')->truncate(); +app('db')->table('permissions')->insert($permissions); \ No newline at end of file