Skip to content

Commit

Permalink
[11.x] Add Dispatchable::newPendingDispatch() (#54153)
Browse files Browse the repository at this point in the history
* createPendingDispatch

* clean up

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
cosmastech and taylorotwell authored Jan 10, 2025
1 parent beb8499 commit 61492a8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Illuminate/Foundation/Bus/Dispatchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait Dispatchable
*/
public static function dispatch(...$arguments)
{
return new PendingDispatch(new static(...$arguments));
return static::newPendingDispatch(new static(...$arguments));
}

/**
Expand All @@ -32,12 +32,12 @@ public static function dispatchIf($boolean, ...$arguments)
$dispatchable = new static(...$arguments);

return value($boolean, $dispatchable)
? new PendingDispatch($dispatchable)
? static::newPendingDispatch($dispatchable)
: new Fluent;
}

return value($boolean)
? new PendingDispatch(new static(...$arguments))
? static::newPendingDispatch(new static(...$arguments))
: new Fluent;
}

Expand All @@ -54,12 +54,12 @@ public static function dispatchUnless($boolean, ...$arguments)
$dispatchable = new static(...$arguments);

return ! value($boolean, $dispatchable)
? new PendingDispatch($dispatchable)
? static::newPendingDispatch($dispatchable)
: new Fluent;
}

return ! value($boolean)
? new PendingDispatch(new static(...$arguments))
? static::newPendingDispatch(new static(...$arguments))
: new Fluent;
}

Expand Down Expand Up @@ -97,4 +97,15 @@ public static function withChain($chain)
{
return new PendingChain(static::class, $chain);
}

/**
* Create a new pending job dispatch instance.
*
* @param mixed $job
* @return \Illuminate\Foundation\Bus\PendingDispatch
*/
protected static function newPendingDispatch($job)
{
return new PendingDispatch($job);
}
}

0 comments on commit 61492a8

Please sign in to comment.