-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathWorkerMiddlewareStack.php
More file actions
49 lines (41 loc) · 1.41 KB
/
WorkerMiddlewareStack.php
File metadata and controls
49 lines (41 loc) · 1.41 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
<?php
declare(strict_types=1);
namespace SchedulerBundle\Middleware;
use SchedulerBundle\Task\TaskInterface;
use SchedulerBundle\Worker\WorkerInterface;
use function array_unique;
use const SORT_REGULAR;
/**
* @author Guillaume Loulier <[email protected]>
*/
final class WorkerMiddlewareStack extends AbstractMiddlewareStack implements WorkerMiddlewareStackInterface
{
/**
* {@inheritdoc}
*/
public function runPreExecutionMiddleware(TaskInterface $task): void
{
$this->runMiddleware(middlewareList: $this->getPreExecutionMiddleware(), func: static function (PreExecutionMiddlewareInterface $middleware) use ($task): void {
$middleware->preExecute(task: $task);
});
}
/**
* {@inheritdoc}
*/
public function runPostExecutionMiddleware(TaskInterface $task, WorkerInterface $worker): void
{
$this->runMiddleware(middlewareList: $this->getPostExecutionMiddleware(), func: static function (PostExecutionMiddlewareInterface $middleware) use ($task, $worker): void {
$middleware->postExecute(task: $task, worker: $worker);
});
}
/**
* {@inheritdoc}
*/
public function getMiddlewareList(): array
{
return array_unique(array: [
...$this->getPreExecutionMiddleware()->toArray(),
...$this->getPostExecutionMiddleware()->toArray(),
], flags: SORT_REGULAR);
}
}