This repository was archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExecutor.php
More file actions
54 lines (46 loc) · 1.39 KB
/
Executor.php
File metadata and controls
54 lines (46 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace FDevs\Fixture;
use FDevs\Executor\ExecutorInterface;
use FDevs\Fixture\Event\ExecuteEvent;
use FDevs\Fixture\Event\ExecuteExceptionEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Executor implements ExecutorInterface
{
/**
* @var ExecutorInterface
*/
private $executor;
/**
* @var EventDispatcherInterface
*/
private $dispatcher;
/**
* Executor constructor.
*
* @param ExecutorInterface $executor
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(ExecutorInterface $executor, EventDispatcherInterface $dispatcher)
{
$this->executor = $executor;
$this->dispatcher = $dispatcher;
}
/**
* @inheritDoc
*/
public function execute(array $context, array $fixtures = []): \Iterator
{
$event = new ExecuteEvent($context, $fixtures);
$this->dispatcher->dispatch(FDevsFixtureEvents::PRE_EXECUTE, $event);
try {
yield from $this->executor->execute($context, $fixtures);
} catch (\Throwable $e) {
$this->dispatcher->dispatch(
FDevsFixtureEvents::EXCEPTION_EXECUTE,
new ExecuteExceptionEvent($context, $fixtures, $e)
);
throw $e;
}
$this->dispatcher->dispatch(FDevsFixtureEvents::POST_EXECUTE, $event);
}
}