koel/app/Providers/AppServiceProvider.php

66 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2015-12-13 12:42:28 +08:00
<?php
namespace App\Providers;
use App\Services\Contracts\MusicEncyclopedia;
2022-08-08 18:00:59 +02:00
use App\Services\LastfmService;
use App\Services\License\Contracts\LicenseServiceInterface;
use App\Services\LicenseService;
2022-08-08 18:00:59 +02:00
use App\Services\NullMusicEncyclopedia;
2022-07-18 13:00:37 +02:00
use App\Services\SpotifyService;
2018-08-31 20:47:15 +07:00
use Illuminate\Database\DatabaseManager;
2024-05-19 13:49:42 +08:00
use Illuminate\Database\Eloquent\Model;
2018-08-31 20:47:15 +07:00
use Illuminate\Database\Schema\Builder;
use Illuminate\Database\SQLiteConnection;
2022-06-10 12:47:46 +02:00
use Illuminate\Http\Resources\Json\JsonResource;
2015-12-13 12:42:28 +08:00
use Illuminate\Support\ServiceProvider;
2022-07-18 13:00:37 +02:00
use SpotifyWebAPI\Session as SpotifySession;
2015-12-13 12:42:28 +08:00
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot(Builder $schema, DatabaseManager $db): void
2015-12-13 12:42:28 +08:00
{
2017-04-19 12:22:02 +08:00
// Fix utf8mb4-related error starting from Laravel 5.4
2018-08-31 20:47:15 +07:00
$schema->defaultStringLength(191);
2017-04-19 12:22:02 +08:00
2024-05-19 13:49:42 +08:00
Model::preventLazyLoading(!app()->isProduction());
// Enable on delete cascade for sqlite connections
2018-08-31 20:47:15 +07:00
if ($db->connection() instanceof SQLiteConnection) {
$db->statement($db->raw('PRAGMA foreign_keys = ON')->getValue($db->getQueryGrammar()));
}
2022-06-10 12:47:46 +02:00
// disable wrapping JSON resource in a `data` key
JsonResource::withoutWrapping();
2022-07-18 13:00:37 +02:00
$this->app->bind(SpotifySession::class, static function () {
return SpotifyService::enabled()
? new SpotifySession(config('koel.spotify.client_id'), config('koel.spotify.client_secret'))
: null;
});
2022-08-08 18:00:59 +02:00
$this->app->bind(MusicEncyclopedia::class, function () {
return $this->app->get(LastfmService::enabled() ? LastfmService::class : NullMusicEncyclopedia::class);
});
2024-01-05 17:42:50 +01:00
2024-01-09 19:34:40 +01:00
$this->app->bind(LicenseServiceInterface::class, LicenseService::class);
2024-01-05 17:42:50 +01:00
$this->app->when(LicenseService::class)
->needs('$hashSalt')
->give(config('app.key'));
2015-12-13 12:42:28 +08:00
}
/**
* Register any application services.
*/
2018-08-29 11:06:17 +07:00
public function register(): void
2015-12-13 12:42:28 +08:00
{
2022-06-10 12:47:46 +02:00
if ($this->app->environment() !== 'production' && class_exists('Laravel\Tinker\TinkerServiceProvider')) {
$this->app->register('Laravel\Tinker\TinkerServiceProvider');
}
2015-12-13 12:42:28 +08:00
}
}