Primo Committ
This commit is contained in:
76
vendor/laravel/framework/src/Illuminate/Foundation/Bus/Dispatchable.php
vendored
Normal file
76
vendor/laravel/framework/src/Illuminate/Foundation/Bus/Dispatchable.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Foundation\Bus;
|
||||
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Support\Fluent;
|
||||
|
||||
trait Dispatchable
|
||||
{
|
||||
/**
|
||||
* Dispatch the job with the given arguments.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Bus\PendingDispatch
|
||||
*/
|
||||
public static function dispatch()
|
||||
{
|
||||
return new PendingDispatch(new static(...func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the job with the given arguments if the given truth test passes.
|
||||
*
|
||||
* @param bool $boolean
|
||||
* @return \Illuminate\Foundation\Bus\PendingDispatch|\Illuminate\Support\Fluent
|
||||
*/
|
||||
public static function dispatchIf($boolean, ...$arguments)
|
||||
{
|
||||
return $boolean
|
||||
? new PendingDispatch(new static(...$arguments))
|
||||
: new Fluent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the job with the given arguments unless the given truth test passes.
|
||||
*
|
||||
* @param bool $boolean
|
||||
* @return \Illuminate\Foundation\Bus\PendingDispatch|\Illuminate\Support\Fluent
|
||||
*/
|
||||
public static function dispatchUnless($boolean, ...$arguments)
|
||||
{
|
||||
return ! $boolean
|
||||
? new PendingDispatch(new static(...$arguments))
|
||||
: new Fluent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a command to its appropriate handler in the current process.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function dispatchNow()
|
||||
{
|
||||
return app(Dispatcher::class)->dispatchNow(new static(...func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a command to its appropriate handler after the current process.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function dispatchAfterResponse()
|
||||
{
|
||||
return app(Dispatcher::class)->dispatchAfterResponse(new static(...func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the jobs that should run if this job is successful.
|
||||
*
|
||||
* @param array $chain
|
||||
* @return \Illuminate\Foundation\Bus\PendingChain
|
||||
*/
|
||||
public static function withChain($chain)
|
||||
{
|
||||
return new PendingChain(static::class, $chain);
|
||||
}
|
||||
}
|
||||
30
vendor/laravel/framework/src/Illuminate/Foundation/Bus/DispatchesJobs.php
vendored
Normal file
30
vendor/laravel/framework/src/Illuminate/Foundation/Bus/DispatchesJobs.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Foundation\Bus;
|
||||
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
|
||||
trait DispatchesJobs
|
||||
{
|
||||
/**
|
||||
* Dispatch a job to its appropriate handler.
|
||||
*
|
||||
* @param mixed $job
|
||||
* @return mixed
|
||||
*/
|
||||
protected function dispatch($job)
|
||||
{
|
||||
return app(Dispatcher::class)->dispatch($job);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a job to its appropriate handler in the current process.
|
||||
*
|
||||
* @param mixed $job
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatchNow($job)
|
||||
{
|
||||
return app(Dispatcher::class)->dispatchNow($job);
|
||||
}
|
||||
}
|
||||
54
vendor/laravel/framework/src/Illuminate/Foundation/Bus/PendingChain.php
vendored
Normal file
54
vendor/laravel/framework/src/Illuminate/Foundation/Bus/PendingChain.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Foundation\Bus;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Queue\CallQueuedClosure;
|
||||
|
||||
class PendingChain
|
||||
{
|
||||
/**
|
||||
* The class name of the job being dispatched.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $job;
|
||||
|
||||
/**
|
||||
* The jobs to be chained.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $chain;
|
||||
|
||||
/**
|
||||
* Create a new PendingChain instance.
|
||||
*
|
||||
* @param mixed $job
|
||||
* @param array $chain
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($job, $chain)
|
||||
{
|
||||
$this->job = $job;
|
||||
$this->chain = $chain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the job with the given arguments.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Bus\PendingDispatch
|
||||
*/
|
||||
public function dispatch()
|
||||
{
|
||||
if (is_string($this->job)) {
|
||||
$firstJob = new $this->job(...func_get_args());
|
||||
} elseif ($this->job instanceof Closure) {
|
||||
$firstJob = CallQueuedClosure::create($this->job);
|
||||
} else {
|
||||
$firstJob = $this->job;
|
||||
}
|
||||
|
||||
return (new PendingDispatch($firstJob))->chain($this->chain);
|
||||
}
|
||||
}
|
||||
137
vendor/laravel/framework/src/Illuminate/Foundation/Bus/PendingDispatch.php
vendored
Normal file
137
vendor/laravel/framework/src/Illuminate/Foundation/Bus/PendingDispatch.php
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Foundation\Bus;
|
||||
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
|
||||
class PendingDispatch
|
||||
{
|
||||
/**
|
||||
* The job.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $job;
|
||||
|
||||
/**
|
||||
* Indicates if the job should be dispatched immediately after sending the response.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $afterResponse = false;
|
||||
|
||||
/**
|
||||
* Create a new pending job dispatch.
|
||||
*
|
||||
* @param mixed $job
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($job)
|
||||
{
|
||||
$this->job = $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired connection for the job.
|
||||
*
|
||||
* @param string|null $connection
|
||||
* @return $this
|
||||
*/
|
||||
public function onConnection($connection)
|
||||
{
|
||||
$this->job->onConnection($connection);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired queue for the job.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return $this
|
||||
*/
|
||||
public function onQueue($queue)
|
||||
{
|
||||
$this->job->onQueue($queue);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired connection for the chain.
|
||||
*
|
||||
* @param string|null $connection
|
||||
* @return $this
|
||||
*/
|
||||
public function allOnConnection($connection)
|
||||
{
|
||||
$this->job->allOnConnection($connection);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired queue for the chain.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return $this
|
||||
*/
|
||||
public function allOnQueue($queue)
|
||||
{
|
||||
$this->job->allOnQueue($queue);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired delay for the job.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int|null $delay
|
||||
* @return $this
|
||||
*/
|
||||
public function delay($delay)
|
||||
{
|
||||
$this->job->delay($delay);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the jobs that should run if this job is successful.
|
||||
*
|
||||
* @param array $chain
|
||||
* @return $this
|
||||
*/
|
||||
public function chain($chain)
|
||||
{
|
||||
$this->job->chain($chain);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the job should be dispatched after the response is sent to the browser.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function afterResponse()
|
||||
{
|
||||
$this->afterResponse = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the object's destruction.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->afterResponse) {
|
||||
app(Dispatcher::class)->dispatchAfterResponse($this->job);
|
||||
} else {
|
||||
app(Dispatcher::class)->dispatch($this->job);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user