Skip to content

Commit ff33775

Browse files
[8.x] Make Listeners, Mailables, and Notifications accept ShouldBeEncrypted (#36036)
* accept a command in object form in Bus::assertChained * Revert " accept a command in object form in Bus::assertChained" This reverts commit 137623f. * make listeners notifictaions and mailables encryptable in queue * Update Queue.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 958386a commit ff33775

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

src/Illuminate/Events/CallQueuedListener.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class CallQueuedListener implements ShouldQueue
6161
*/
6262
public $timeout;
6363

64+
/**
65+
* Indicates if the job should be encrypted.
66+
*
67+
* @var bool
68+
*/
69+
public $shouldBeEncrypted = false;
70+
6471
/**
6572
* Create a new job instance.
6673
*

src/Illuminate/Events/Dispatcher.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
1010
use Illuminate\Contracts\Container\Container as ContainerContract;
1111
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
12+
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
1213
use Illuminate\Contracts\Queue\ShouldQueue;
1314
use Illuminate\Support\Arr;
1415
use Illuminate\Support\Str;
@@ -600,6 +601,8 @@ protected function propagateListenerOptions($listener, $job)
600601

601602
$job->retryUntil = method_exists($listener, 'retryUntil')
602603
? $listener->retryUntil() : null;
604+
605+
$job->shouldBeEncrypted = $listener instanceof ShouldBeEncrypted;
603606
});
604607
}
605608

src/Illuminate/Mail/SendQueuedMailable.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Bus\Queueable;
66
use Illuminate\Contracts\Mail\Factory as MailFactory;
77
use Illuminate\Contracts\Mail\Mailable as MailableContract;
8+
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
89

910
class SendQueuedMailable
1011
{
@@ -31,6 +32,13 @@ class SendQueuedMailable
3132
*/
3233
public $timeout;
3334

35+
/**
36+
* Indicates if the job should be encrypted.
37+
*
38+
* @var bool
39+
*/
40+
public $shouldBeEncrypted = false;
41+
3442
/**
3543
* Create a new job instance.
3644
*
@@ -43,6 +51,7 @@ public function __construct(MailableContract $mailable)
4351
$this->tries = property_exists($mailable, 'tries') ? $mailable->tries : null;
4452
$this->timeout = property_exists($mailable, 'timeout') ? $mailable->timeout : null;
4553
$this->afterCommit = property_exists($mailable, 'afterCommit') ? $mailable->afterCommit : null;
54+
$this->shouldBeEncrypted = $mailable instanceof ShouldBeEncrypted;
4655
}
4756

4857
/**

src/Illuminate/Notifications/SendQueuedNotifications.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Notifications;
44

55
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
67
use Illuminate\Contracts\Queue\ShouldQueue;
78
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
89
use Illuminate\Database\Eloquent\Model;
@@ -49,6 +50,13 @@ class SendQueuedNotifications implements ShouldQueue
4950
*/
5051
public $timeout;
5152

53+
/**
54+
* Indicates if the job should be encrypted.
55+
*
56+
* @var bool
57+
*/
58+
public $shouldBeEncrypted = false;
59+
5260
/**
5361
* Create a new job instance.
5462
*
@@ -65,6 +73,7 @@ public function __construct($notifiables, $notification, array $channels = null)
6573
$this->tries = property_exists($notification, 'tries') ? $notification->tries : null;
6674
$this->timeout = property_exists($notification, 'timeout') ? $notification->timeout : null;
6775
$this->afterCommit = property_exists($notification, 'afterCommit') ? $notification->afterCommit : null;
76+
$this->shouldBeEncrypted = $notification instanceof ShouldBeEncrypted;
6877
}
6978

7079
/**

src/Illuminate/Queue/Queue.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function createObjectPayload($job, $queue)
152152
],
153153
]);
154154

155-
$command = $job instanceof ShouldBeEncrypted && $this->container->bound(Encrypter::class)
155+
$command = $this->jobShouldBeEncrypted($job) && $this->container->bound(Encrypter::class)
156156
? $this->container[Encrypter::class]->encrypt(serialize(clone $job))
157157
: serialize(clone $job);
158158

@@ -213,6 +213,21 @@ public function getJobExpiration($job)
213213
? $expiration->getTimestamp() : $expiration;
214214
}
215215

216+
/**
217+
* Determine if the job should be encrypted.
218+
*
219+
* @param object $job
220+
* @return bool
221+
*/
222+
protected function jobShouldBeEncrypted($job)
223+
{
224+
if ($job instanceof ShouldBeEncrypted) {
225+
return true;
226+
}
227+
228+
return isset($job->shouldBeEncrypted) && $job->shouldBeEncrypted;
229+
}
230+
216231
/**
217232
* Create a typical, string based queue payload array.
218233
*

0 commit comments

Comments
 (0)