|
|
|
|
|
by sergiosgc
1667 days ago
|
|
I have. Elegant it is not. Actually, it smells like Enterprise Java code, which made me flee from the Java ecosystem. To each his own, but this is not an elegant event listener (copied from the examples page): use App\Events\ArtistInformationFetched;
use App\Services\MediaMetadataService;
use Throwable;
class DownloadArtistImage
{
private MediaMetadataService $mediaMetadataService;
public function __construct(MediaMetadataService $mediaMetadataService)
{
$this->mediaMetadataService = $mediaMetadataService;
}
public function handle(ArtistInformationFetched $event): void
{
$info = $event->getInformation();
$artist = $event->getArtist();
$image = array_get($info, 'image');
if (!$artist->has_image && $image && ini_get('allow_url_fopen')) {
try {
$this->mediaMetadataService->downloadArtistImage($artist, $image);
} catch (Throwable $e) {
}
}
}
}
Source: https://laravelexamples.com/example/koel/events-listeners |
|
https://laravel.com/docs/8.x/container#introduction
Or, if you wanted something perhaps at least use one of their featured partners for real code? https://github.com/tighten/jigsaw/blob/main/src/Jigsaw.php
I also would argue that the majority of code I see in other languages is equally or worse than the example you gave.
You can write terribly in any language, Laravel included.