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

[11.x] Add Dispatchable::newPendingDispatch() #54153

Merged
merged 3 commits into from
Jan 10, 2025
Merged
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
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);
}
}