Lines 0.00% 0 / 13
Functions and Methods 0.00% 0 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ControlPlaneFactory 0.00% 0 / 13 0.00% 0 / 2 12 0.00% 0 / 1
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 createControlPlane 0.00% 0 / 12 0.00% 0 / 1 6
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Control;
6
7use Psr\Log\LoggerInterface;
8use Stewart\Runtime\Broker\ControlPlane;
9use Stewart\Runtime\Broker\DisabledControlPlane;
10use Stewart\Runtime\Config\ControlConfig;
11use Stewart\Runtime\Config\ProjectRoot;
12use Stewart\Runtime\Control\Protocol\Codec\FrameCodec;
13use Stewart\Runtime\Control\Request\ControlRequestDispatcher;
14use Stewart\Runtime\Control\Server\ControlServer;
15use Stewart\Runtime\Control\Server\UnixSocketFile;
16use Stewart\Runtime\Exception\ConfigurationError;
17use Stewart\Runtime\Exception\ConfigurationException;
18use Stewart\Support\Time\Deadlines;
19
20final readonly class ControlPlaneFactory
21{
22    public function __construct(
23        private ControlConfig $control,
24        private ControlRequestDispatcher $requests,
25        private Deadlines $deadlines,
26        private FrameCodec $codec,
27        private LoggerInterface $logger,
28        private UnixSocketFile $socketFile,
29        private ProjectRoot $projectRoot,
30    ) {}
31
32    /** @throws ConfigurationException */
33    public function createControlPlane(): ControlPlane
34    {
35        if ($this->control->listen === null) {
36            return new DisabledControlPlane();
37        }
38
39        return new ControlServer(
40            address: $this->control->listen,
41            token: $this->control->token ?? throw ConfigurationException::createForReason(ConfigurationError::ControlTokenMissing),
42            requests: $this->requests,
43            deadlines: $this->deadlines,
44            codec: $this->codec,
45            logger: $this->logger,
46            socketFile: $this->socketFile,
47            projectRoot: $this->projectRoot,
48        );
49    }
50}