Skip to content

Commit

Permalink
Allow chaining queueable methods onto trait dispatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 13, 2017
1 parent 827d075 commit 9fde549
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Bus/Dispatchable.php
Expand Up @@ -7,10 +7,10 @@ trait Dispatchable
/**
* Dispatch the job with the given arguments.
*
* @return void
* @return \Illuminate\Foundation\Bus\PendingDispatch
*/
public static function dispatch()
{
return dispatch(new static(...func_get_args()));
return new PendingDispatch(new static(...func_get_args()));
}
}
66 changes: 66 additions & 0 deletions src/Illuminate/Foundation/Bus/PendingDispatch.php
@@ -0,0 +1,66 @@
<?php

namespace Illuminate\Foundation\Bus;

class PendingDispatch
{
/**
* 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 delay for the job.
*
* @param \DateTime|int|null $delay
* @return $this
*/
public function delay($delay)
{
$this->job->delay($delay);

return $this;
}

/**
* Handle the object's destruction.
*
* @return void
*/
public function __destruct()
{
dispatch($this->job);
}
}

0 comments on commit 9fde549

Please sign in to comment.