2018-08-29 07:58:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
|
|
|
use App\Models\Song;
|
2021-12-06 16:12:47 +00:00
|
|
|
use App\Services\Helper;
|
2018-08-29 07:58:46 +00:00
|
|
|
|
|
|
|
class SongObserver
|
|
|
|
{
|
2021-12-06 16:12:47 +00:00
|
|
|
private Helper $helper;
|
2018-08-29 07:58:46 +00:00
|
|
|
|
2021-12-06 16:12:47 +00:00
|
|
|
public function __construct(Helper $helper)
|
2018-08-29 07:58:46 +00:00
|
|
|
{
|
2021-12-06 16:12:47 +00:00
|
|
|
$this->helper = $helper;
|
2018-08-29 07:58:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function creating(Song $song): void
|
2018-10-19 14:33:04 +00:00
|
|
|
{
|
|
|
|
$this->setFileHashAsId($song);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function setFileHashAsId(Song $song): void
|
2018-08-29 07:58:46 +00:00
|
|
|
{
|
2021-12-06 16:12:47 +00:00
|
|
|
$song->id = $this->helper->getFileHash($song->path);
|
2018-08-29 07:58:46 +00:00
|
|
|
}
|
|
|
|
}
|