| Total Complexity | 5 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | final class Dispatcher implements Contract\Dispatcher |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var Processor |
||
| 19 | */ |
||
| 20 | private $processor; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var callable[] |
||
| 24 | */ |
||
| 25 | private $handlers = []; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param Processor $processor |
||
| 29 | */ |
||
| 30 | 6 | public function __construct(Processor $processor = null) |
|
| 33 | 6 | } |
|
| 34 | |||
| 35 | /** |
||
| 36 | * {@inheritdoc} |
||
| 37 | */ |
||
| 38 | 5 | public function register(string $signal, callable $handler): void |
|
| 39 | { |
||
| 40 | 5 | $this->handlers[$signal] = $handler; |
|
| 41 | |||
| 42 | 5 | $this->processor->interrupt($signal, function (...$arguments) use ($signal) { |
|
| 43 | 1 | return $this->dispatch($signal, ...$arguments); |
|
| 44 | 5 | }); |
|
| 45 | 5 | } |
|
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | */ |
||
| 50 | 6 | public function dispatch($signal, ...$arguments): Task |
|
| 63 | } |
||
| 64 | } |
||
| 65 |