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

Commit 470fb24

Browse files
authored
Merge pull request #16 from adiachenko/events57
Dispatch event for each started feature, operation and job
2 parents f1be349 + e12186f commit 470fb24

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

Diff for: src/Events/FeatureStarted.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Lucid\Foundation\Events;
4+
5+
class FeatureStarted
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public $name;
11+
12+
/**
13+
* @var array
14+
*/
15+
public $arguments;
16+
17+
/**
18+
* FeatureStarted constructor.
19+
* @param string $name
20+
* @param array $arguments
21+
*/
22+
public function __construct($name, array $arguments = [])
23+
{
24+
$this->name = $name;
25+
$this->arguments = $arguments;
26+
}
27+
}

Diff for: src/Events/JobStarted.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Lucid\Foundation\Events;
4+
5+
class JobStarted
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public $name;
11+
12+
/**
13+
* @var array
14+
*/
15+
public $arguments;
16+
17+
/**
18+
* JobStarted constructor.
19+
* @param string $name
20+
* @param array $arguments
21+
*/
22+
public function __construct($name, array $arguments = [])
23+
{
24+
$this->name = $name;
25+
$this->arguments = $arguments;
26+
}
27+
}

Diff for: src/Events/OperationStarted.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Lucid\Foundation\Events;
4+
5+
class OperationStarted
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public $name;
11+
12+
/**
13+
* @var array
14+
*/
15+
public $arguments;
16+
17+
/**
18+
* OperationStarted constructor.
19+
* @param string $name
20+
* @param array $arguments
21+
*/
22+
public function __construct($name, array $arguments = [])
23+
{
24+
$this->name = $name;
25+
$this->arguments = $arguments;
26+
}
27+
}

Diff for: src/JobDispatcherTrait.php

+9
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), $arguments));
38+
}
39+
if ($job instanceof Job) {
40+
event(new JobStarted(get_class($job), $arguments));
41+
}
42+
3443
$result = $this->dispatch($job, $arguments);
3544
}
3645

Diff for: src/ServesFeaturesTrait.php

+3
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, $arguments));
25+
2326
return $this->dispatch($this->marshal($feature, new Collection(), $arguments));
2427
}
2528
}

0 commit comments

Comments
 (0)