Lines 0.00% 0 / 2
Functions and Methods 0.00% 0 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
DispatchSource 0.00% 0 / 2 0.00% 0 / 2 6 0.00% 0 / 1
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 attach 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Dispatch;
6
7use Closure;
8use Stewart\Contracts\Registry\EntityFilter;
9use Stewart\Contracts\Selector\Selector;
10use Stewart\Contracts\Subscription;
11use Stewart\Runtime\Model\ResourceScope;
12use Stewart\Runtime\Model\SubscriptionKind;
13use Stewart\Support\Stream\StreamSource;
14use Stewart\Support\Stream\SubscriptionScope;
15use Stewart\Support\Wire\TriggerSpec;
16
17/**
18 * @template T
19 * @implements StreamSource<T>
20 */
21final readonly class DispatchSource implements StreamSource
22{
23    public function __construct(
24        private LocalDispatcher $dispatcher,
25        private ResourceScope $scope,
26        private SubscriptionKind $kind,
27        private Selector $selector,
28        private ?TriggerSpec $trigger = null,
29        private ?EntityFilter $entityFilter = null,
30    ) {}
31
32    public function attach(SubscriptionScope $scope, Closure $downstream): Subscription
33    {
34        return $this->dispatcher->register($this->scope, $this->kind, $this->selector, $scope, $downstream, $this->trigger, $this->entityFilter);
35    }
36}