-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transactional behavior to custom closures
- Loading branch information
Showing
6 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
|
||
namespace Neves\Events; | ||
|
||
|
||
use Closure; | ||
use Neves\Events\Contracts\TransactionalEvent; | ||
|
||
class TransactionalClosureEvent implements TransactionalEvent | ||
{ | ||
private $closure; | ||
|
||
public function __construct(Closure $closure) | ||
{ | ||
$this->closure = $closure; | ||
} | ||
|
||
public function getClosure(): Closure { | ||
return $this->closure; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract; | ||
use Neves\Events\TransactionalClosureEvent; | ||
|
||
if (! function_exists('transactional')) { | ||
/** | ||
* Add an element to an array using "dot" notation if it doesn't exist. | ||
* | ||
* @param \Closure $callable | ||
* @return void | ||
*/ | ||
function transactional(Closure $callable) | ||
{ | ||
$dispatcher = app(DispatcherContract::class); | ||
|
||
$dispatcher->dispatch(new TransactionalClosureEvent($callable)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters