forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[9.x] Add unique locking to broadcast events (laravel#43416)
* Add unique locking to broadcast events * Don't require uniqueId, set default * Locking irrelevant when broadcasting now * formatting Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
a9165c4
commit 3450bb3
Showing
4 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Illuminate\Broadcasting; | ||
|
||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
|
||
class UniqueBroadcastEvent extends BroadcastEvent implements ShouldBeUnique | ||
{ | ||
/** | ||
* The unique lock identifier. | ||
* | ||
* @var mixed | ||
*/ | ||
public $uniqueId; | ||
|
||
/** | ||
* The number of seconds the unique lock should be maintained. | ||
* | ||
* @var int | ||
*/ | ||
public $uniqueFor; | ||
|
||
/** | ||
* The cache repository implementation that should be used to obtain unique locks. | ||
* | ||
* @var \Illuminate\Contracts\Cache\Repository | ||
*/ | ||
public $uniqueVia; | ||
|
||
/** | ||
* Create a new job handler instance. | ||
* | ||
* @param mixed $event | ||
* @return void | ||
*/ | ||
public function __construct($event) | ||
{ | ||
$this->uniqueId = get_class($event); | ||
|
||
if (method_exists($event, 'uniqueId')) { | ||
$this->uniqueId = $event->uniqueId(); | ||
} elseif (property_exists($event, 'uniqueId')) { | ||
$this->uniqueId = $event->uniqueId; | ||
} | ||
|
||
if (method_exists($event, 'uniqueFor')) { | ||
$this->uniqueFor = $event->uniqueFor(); | ||
} elseif (property_exists($event, 'uniqueFor')) { | ||
$this->uniqueFor = $event->uniqueFor; | ||
} | ||
|
||
if (method_exists($event, 'uniqueVia')) { | ||
$this->uniqueVia = $event->uniqueVia(); | ||
} elseif (property_exists($event, 'uniqueVia')) { | ||
$this->uniqueVia = $event->uniqueVia; | ||
} | ||
|
||
parent::__construct($event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Illuminate\Contracts\Broadcasting; | ||
|
||
interface ShouldBeUnique | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters