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

Commit

Permalink
Merge pull request #13 from adiachenko/events56
Browse files Browse the repository at this point in the history
[5.6] Dispatch event for each started feature, operation and job
  • Loading branch information
adiachenko authored Aug 27, 2019
2 parents 1501f55 + 29d12df commit 6bc61ef
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Events/FeatureStarted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Lucid\Foundation\Events;

class FeatureStarted
{
/**
* @var string
*/
public $name;

/**
* @var array
*/
public $arguments;

/**
* FeatureStarted constructor.
* @param string $name
* @param array $arguments
*/
public function __construct($name, array $arguments = [])
{
$this->name = $name;
$this->arguments = $arguments;
}
}
27 changes: 27 additions & 0 deletions src/Events/JobStarted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Lucid\Foundation\Events;

class JobStarted
{
/**
* @var string
*/
public $name;

/**
* @var array
*/
public $arguments;

/**
* JobStarted constructor.
* @param string $name
* @param array $arguments
*/
public function __construct($name, array $arguments = [])
{
$this->name = $name;
$this->arguments = $arguments;
}
}
27 changes: 27 additions & 0 deletions src/Events/OperationStarted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Lucid\Foundation\Events;

class OperationStarted
{
/**
* @var string
*/
public $name;

/**
* @var array
*/
public $arguments;

/**
* OperationStarted constructor.
* @param string $name
* @param array $arguments
*/
public function __construct($name, array $arguments = [])
{
$this->name = $name;
$this->arguments = $arguments;
}
}
9 changes: 9 additions & 0 deletions src/JobDispatcherTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Lucid\Foundation;

use Lucid\Foundation\Events\JobStarted;
use Lucid\Foundation\Events\OperationStarted;
use ReflectionClass;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -31,6 +33,13 @@ public function run($job, $arguments = [], $extra = [])
$job = $this->marshal($job, new Collection(), $arguments);
}

if ($job instanceof Operation) {
event(new OperationStarted(get_class($job), $arguments));
}
if ($job instanceof Job) {
event(new JobStarted(get_class($job), $arguments));
}

$result = $this->dispatch($job, $arguments);
}

Expand Down
3 changes: 3 additions & 0 deletions src/ServesFeaturesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Collection;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Lucid\Foundation\Events\FeatureStarted;

trait ServesFeaturesTrait
{
Expand All @@ -20,6 +21,8 @@ trait ServesFeaturesTrait
*/
public function serve($feature, $arguments = [])
{
event(new FeatureStarted($feature, $arguments));

return $this->dispatch($this->marshal($feature, new Collection(), $arguments));
}
}

0 comments on commit 6bc61ef

Please sign in to comment.