Skip to content

Commit 540d548

Browse files
authored
Turn GenerateSocialShareImage Action to a Job (#970)
* turn GenerateSocialShareImage Action to a Job * call the GenerateSocialShareImage job directly
1 parent 6078dce commit 540d548

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

app/Http/Controllers/SocialImageController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Actions\GenerateSocialShareImage;
5+
use App\Jobs\GenerateSocialShareImage;
66
use App\Models\Article;
77

88
class SocialImageController extends Controller
99
{
10-
public function __invoke(GenerateSocialShareImage $generateImage, Article $article)
10+
public function __invoke(Article $article)
1111
{
12-
return $generateImage($article);
12+
return $this->dispatchSync(new GenerateSocialShareImage($article));
1313
}
1414
}

app/Actions/GenerateSocialShareImage.php renamed to app/Jobs/GenerateSocialShareImage.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace App\Actions;
3+
namespace App\Jobs;
44

55
use App\Models\Article;
66
use Intervention\Image\ImageManager;
@@ -23,15 +23,15 @@ final class GenerateSocialShareImage
2323

2424
const CACHE_LIFETIME = 43200;
2525

26-
public function __construct(private ImageManager $image)
26+
public function __construct(private Article $article)
2727
{
2828
}
2929

30-
public function __invoke(Article $article): mixed
30+
public function handle(ImageManager $image): mixed
3131
{
32-
$text = wordwrap($article->title(), self::CHARACTERS_PER_LINE);
32+
$text = wordwrap($this->article->title(), self::CHARACTERS_PER_LINE);
3333

34-
return $this->image->cache(function ($image) use ($text) {
34+
return $image->cache(function ($image) use ($text) {
3535
$image->make(resource_path('images/'.self::TEMPLATE))
3636
->text($text, self::TEXT_X_POSITION, self::TEXT_Y_POSITION, function ($font) {
3737
$font->file(resource_path('fonts/'.self::FONT));

0 commit comments

Comments
 (0)