koel/app/Providers/EventServiceProvider.php

54 lines
1.4 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Providers;
use App\Facades\Media;
use App\Models\Album;
2015-12-14 13:22:39 +00:00
use App\Models\Song;
2015-12-13 04:42:28 +00:00
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
2015-12-21 13:49:00 +00:00
'App\Events\SongLikeToggled' => [
'App\Listeners\LoveTrackOnLastfm',
2015-12-13 04:42:28 +00:00
],
2016-02-02 07:47:00 +00:00
2015-12-23 06:26:16 +00:00
'App\Events\SongStartedPlaying' => [
'App\Listeners\UpdateLastfmNowPlaying',
],
2016-02-02 07:47:00 +00:00
'App\Events\LibraryChanged' => [
'App\Listeners\TidyLibrary',
],
2015-12-13 04:42:28 +00:00
];
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
// Generate a unique hash for a song from its path to be the ID
Song::creating(function ($song) {
$song->id = Media::getHash($song->path);
});
// Remove the cover file if the album is deleted
Album::deleted(function ($album) {
if ($album->hasCover) {
2015-12-15 00:14:31 +00:00
@unlink(app()->publicPath().'/public/img/covers/'.$album->cover);
2015-12-13 04:42:28 +00:00
}
});
}
}