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

Commit b299e07

Browse files
committed
Dispatch event for each started feature, operation and job
1 parent f1be349 commit b299e07

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

src/Events/FeatureStarted.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Lucid\Foundation\Events;
4+
5+
class FeatureStarted
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public $name;
11+
12+
/**
13+
* FeatureStarted constructor.
14+
* @param string $name
15+
*/
16+
public function __construct($name)
17+
{
18+
$this->name = $name;
19+
}
20+
}

src/Events/JobStarted.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Lucid\Foundation\Events;
4+
5+
class JobStarted
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public $name;
11+
12+
/**
13+
* JobStarted constructor.
14+
* @param string $name
15+
*/
16+
public function __construct($name)
17+
{
18+
$this->name = $name;
19+
}
20+
}

src/Events/OperationStarted.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Lucid\Foundation\Events;
4+
5+
class OperationStarted
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public $name;
11+
12+
/**
13+
* OperationStarted constructor.
14+
* @param string $name
15+
*/
16+
public function __construct($name)
17+
{
18+
$this->name = $name;
19+
}
20+
}

src/JobDispatcherTrait.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Lucid\Foundation;
44

5+
use Lucid\Foundation\Events\JobStarted;
6+
use Lucid\Foundation\Events\OperationStarted;
57
use ReflectionClass;
68
use Illuminate\Http\Request;
79
use Illuminate\Support\Collection;
@@ -31,6 +33,13 @@ public function run($job, $arguments = [], $extra = [])
3133
$job = $this->marshal($job, new Collection(), $arguments);
3234
}
3335

36+
if ($job instanceof Operation) {
37+
event(new OperationStarted(get_class($job)));
38+
}
39+
if ($job instanceof Job) {
40+
event(new JobStarted(get_class($job)));
41+
}
42+
3443
$result = $this->dispatch($job, $arguments);
3544
}
3645

src/ServesFeaturesTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Collection;
66
use Illuminate\Foundation\Bus\DispatchesJobs;
7+
use Lucid\Foundation\Events\FeatureStarted;
78

89
trait ServesFeaturesTrait
910
{
@@ -20,6 +21,8 @@ trait ServesFeaturesTrait
2021
*/
2122
public function serve($feature, $arguments = [])
2223
{
24+
event(new FeatureStarted($feature));
25+
2326
return $this->dispatch($this->marshal($feature, new Collection(), $arguments));
2427
}
2528
}

0 commit comments

Comments
 (0)