Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit 39de3d2

Browse files
committed
add operation
1 parent fdf3e0d commit 39de3d2

File tree

4 files changed

+90
-50
lines changed

4 files changed

+90
-50
lines changed

src/Feature.php

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,11 @@
22

33
namespace Lucid\Foundation;
44

5-
use ReflectionClass;
6-
use Illuminate\Http\Request;
7-
use Illuminate\Support\Collection;
8-
use App\Domains\Queue\DefaultQueue;
95
use Illuminate\Foundation\Bus\DispatchesJobs;
106

117
abstract class Feature
128
{
139
use MarshalTrait;
1410
use DispatchesJobs;
15-
16-
/**
17-
* beautifier function to be called instead of the
18-
* laravel function dispatchFromArray.
19-
* When the $arguments is an instance of Request
20-
* it will call dispatchFrom instead.
21-
*
22-
* @param string $job
23-
* @param array|\Illuminate\Http\Request $arguments
24-
* @param array $extra
25-
*
26-
* @return mixed
27-
*/
28-
public function run($job, $arguments = [], $extra = [])
29-
{
30-
if ($arguments instanceof Request) {
31-
$result = $this->dispatch($this->marshal($job, $arguments, $extra));
32-
} else {
33-
if (!is_object($job)) {
34-
$job = $this->marshal($job, new Collection(), $arguments);
35-
}
36-
37-
$result = $this->dispatch($job, $arguments);
38-
}
39-
40-
return $result;
41-
}
42-
43-
/**
44-
* Run the given job in the given queue.
45-
*
46-
* @param string $job
47-
* @param array $arguments
48-
* @param Queue|null $queue
49-
*
50-
* @return mixed
51-
*/
52-
public function runInQueue($job, array $arguments = [], $queue = 'default')
53-
{
54-
// instantiate and queue the job
55-
$reflection = new ReflectionClass($job);
56-
$jobInstance = $reflection->newInstanceArgs($arguments);
57-
$jobInstance->onQueue((string) $queue);
58-
59-
return $this->dispatch($jobInstance);
60-
}
11+
use JobDispatcherTrait;
6112
}

src/JobDispatcherTrait.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Lucid\Foundation;
4+
5+
use ReflectionClass;
6+
use Illuminate\Http\Request;
7+
use Illuminate\Support\Collection;
8+
use App\Domains\Queue\DefaultQueue;
9+
use Illuminate\Foundation\Bus\DispatchesJobs;
10+
11+
trait JobDispatcherTrait
12+
{
13+
/**
14+
* beautifier function to be called instead of the
15+
* laravel function dispatchFromArray.
16+
* When the $arguments is an instance of Request
17+
* it will call dispatchFrom instead.
18+
*
19+
* @param string $job
20+
* @param array|\Illuminate\Http\Request $arguments
21+
* @param array $extra
22+
*
23+
* @return mixed
24+
*/
25+
public function run($job, $arguments = [], $extra = [])
26+
{
27+
if ($arguments instanceof Request) {
28+
$result = $this->dispatch($this->marshal($job, $arguments, $extra));
29+
} else {
30+
if (!is_object($job)) {
31+
$job = $this->marshal($job, new Collection(), $arguments);
32+
}
33+
34+
$result = $this->dispatch($job, $arguments);
35+
}
36+
37+
return $result;
38+
}
39+
40+
/**
41+
* Run the given job in the given queue.
42+
*
43+
* @param string $job
44+
* @param array $arguments
45+
* @param Queue|null $queue
46+
*
47+
* @return mixed
48+
*/
49+
public function runInQueue($job, array $arguments = [], $queue = 'default')
50+
{
51+
// instantiate and queue the job
52+
$reflection = new ReflectionClass($job);
53+
$jobInstance = $reflection->newInstanceArgs($arguments);
54+
$jobInstance->onQueue((string) $queue);
55+
56+
return $this->dispatch($jobInstance);
57+
}
58+
}

src/Operation.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Lucid\Foundation;
4+
5+
use Illuminate\Foundation\Bus\DispatchesJobs;
6+
7+
abstract class Operation
8+
{
9+
use MarshalTrait;
10+
use DispatchesJobs;
11+
use JobDispatcherTrait;
12+
}

src/QueueableOperation.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Lucid\Foundation;
4+
5+
use Illuminate\Queue\SerializesModels;
6+
use Illuminate\Queue\InteractsWithQueue;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
use Illuminate\Bus\Queueable;
9+
10+
/**
11+
* An abstract Operation that can be managed with a queue
12+
* when extended the operation will be queued by default.
13+
*/
14+
class QueueableOperation extends Operation implements ShouldQueue
15+
{
16+
use SerializesModels;
17+
use InteractsWithQueue;
18+
use Queueable;
19+
}

0 commit comments

Comments
 (0)