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