Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Make Listeners, Mailables, and Notifications accept ShouldBeEncrypted #36036

Merged
merged 4 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Illuminate/Events/CallQueuedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class CallQueuedListener implements ShouldQueue
*/
public $timeout;

/**
* Indicates if the job should be encrypted.
*
* @var bool
*/
public $shouldBeEncrypted = false;

/**
* Create a new job instance.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Container\Container as ContainerContract;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -600,6 +601,8 @@ protected function propagateListenerOptions($listener, $job)

$job->retryUntil = method_exists($listener, 'retryUntil')
? $listener->retryUntil() : null;

$job->shouldBeEncrypted = $listener instanceof ShouldBeEncrypted;
});
}

Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Mail/SendQueuedMailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Mail\Factory as MailFactory;
use Illuminate\Contracts\Mail\Mailable as MailableContract;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;

class SendQueuedMailable
{
Expand All @@ -31,6 +32,13 @@ class SendQueuedMailable
*/
public $timeout;

/**
* Indicates if the job should be encrypted.
*
* @var bool
*/
public $shouldBeEncrypted = false;

/**
* Create a new job instance.
*
Expand All @@ -43,6 +51,7 @@ public function __construct(MailableContract $mailable)
$this->tries = property_exists($mailable, 'tries') ? $mailable->tries : null;
$this->timeout = property_exists($mailable, 'timeout') ? $mailable->timeout : null;
$this->afterCommit = property_exists($mailable, 'afterCommit') ? $mailable->afterCommit : null;
$this->shouldBeEncrypted = $mailable instanceof ShouldBeEncrypted;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Notifications/SendQueuedNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -49,6 +50,13 @@ class SendQueuedNotifications implements ShouldQueue
*/
public $timeout;

/**
* Indicates if the job should be encrypted.
*
* @var bool
*/
public $shouldBeEncrypted = false;

/**
* Create a new job instance.
*
Expand All @@ -65,6 +73,7 @@ public function __construct($notifiables, $notification, array $channels = null)
$this->tries = property_exists($notification, 'tries') ? $notification->tries : null;
$this->timeout = property_exists($notification, 'timeout') ? $notification->timeout : null;
$this->afterCommit = property_exists($notification, 'afterCommit') ? $notification->afterCommit : null;
$this->shouldBeEncrypted = $notification instanceof ShouldBeEncrypted;
}

/**
Expand Down
17 changes: 16 additions & 1 deletion src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected function createObjectPayload($job, $queue)
],
]);

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

Expand Down Expand Up @@ -213,6 +213,21 @@ public function getJobExpiration($job)
? $expiration->getTimestamp() : $expiration;
}

/**
* Determine if the job should be encrypted.
*
* @param object $job
* @return bool
*/
protected function jobShouldBeEncrypted($job)
{
if ($job instanceof ShouldBeEncrypted) {
return true;
}

return isset($job->shouldBeEncrypted) && $job->shouldBeEncrypted;
}

/**
* Create a typical, string based queue payload array.
*
Expand Down